blue piranha
blue piranha

Reputation: 3874

Storing zips in SQL Server

I would like to store a zip file as a column in a SQL Server table. When I open this zip in notepad++, it has null characters in some places.

What datatype can I use for the SQL Server column to store this zip?

I have tried using varchar, nvarchar, text but they only store till they encounter the first nul character.

Upvotes: 2

Views: 1585

Answers (2)

marc_s
marc_s

Reputation: 754468

The datatype to use would be varbinary(max) which holds up to 2 GB of binary data.

The datatypes you've tried are only good for text data - not for binary data. And also: text, ntext and image datatypes have been deprecated with SQL Server 2005 - you definitely shouldn't be using those anymore

PS: also see Hossam's answer - if you're on SQL Server 2008 or newer, you could also investigate using the FILESTREAM feature of SQL Server to store the actual data contents of your blobs in the server's file system (instead of inside the database). This can improve performance quite significantly (if you use the file I/O streaming interface), but it does require a bit more work to get this to fly.

Upvotes: 2

Hossam Barakat
Hossam Barakat

Reputation: 1397

I totally agree with @marc_s however I recommend using FILESTREAM as it will leverage the rich streaming APIs and performance.

you can check the following links for more details

https://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/

http://msdn.microsoft.com/en-us/library/gg471497.aspx

Upvotes: 1

Related Questions