95

I need to store binary files to the SQL Server Database. Which is the better Data Type out of Varbinary and Image?

4 Answers 4

146

Since image is deprecated, you should use varbinary.

per Microsoft (thanks for the link @Christopher)

ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

Fixed and variable-length data types for storing large non-Unicode and Unicode character and binary data. Unicode data uses the UNICODE UCS-2 character set.

Sign up to request clarification or add additional context in comments.

7 Comments

@ cmsjr: maybe because as Microsoft says: "image data type will be removed in a future version of Microsoft SQL Server."
@Ehsan I can only assume that you are not familiar with the term deprecated. In general when you say something is deprecated, you are saying it should not be used because it is going to be removed in the future. So my post and the quote you posted in your comment mean essentially the same thing.
No worries, you bring up a good point. I'll update the phrasing.
I wouldn't call this a "link-only" answer. I would call this a "succinct and correct answer to a question that includes some helpful links for those who are inclined to learn more" answer.
I will be frank and let you know that I was disinclined from making the edit because you approached it with an offensive and threatening tone. Perhaps it was not your intent to be rude, but it seemed you were being so to me. Rudeness can often lead people to dismiss otherwise good ideas. I improved the content as you suggested, but I would also ask that you give some thought to how you present your suggestions.
|
14

varbinary(max) is the way to go (introduced in SQL Server 2005)

Comments

9

There is also the rather spiffy FileStream, introduced in SQL Server 2008.

3 Comments

spiffy : smart in appearance?
'rather spiffy' has a somewhat more general meaning (than just 'spiffy') in common vernacular... Most apt I think.
This question is about column formats and FileStream is just a storage behavior. Filestream is implemented by using varbinary(max) and making changes to your sql server instance.
7

https://learn.microsoft.com/en-us/sql/t-sql/data-types/ntext-text-and-image-transact-sql

image

Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes. Still it IS supported to use image datatype, but be aware of:

https://learn.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sql

varbinary [ ( n | max) ]

Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.

So both are equally in size (2GB). But be aware of:

https://learn.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2016#features-not-supported-in-a-future-version-of-sql-server

Though the end of "image" datatype is still not determined, you should use the "future" proof equivalent.

But you have to ask yourself: why storing BLOBS in a Column?

https://learn.microsoft.com/en-us/sql/relational-databases/blob/compare-options-for-storing-blobs-sql-server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.