Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VarBinary vs Image SQL Server Data Type to Store Binary Data?

Tags:

sql-server

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

like image 459
Yoann. B Avatar asked Jan 14 '09 18:01

Yoann. B


People also ask

Which data type is used to store binary data in SQL?

Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.

What 2 formats does SQL Server store binary data in?

Binary, Varbinary & Varbinary(max) are the binary string data types in SQL Server. These data types are used to store raw binary data up to a length of (32K – 1) bytes.

What is the difference between binary and VARBINARY in SQL Server?

binary [ ( n ) ] Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes. varbinary [ ( n | max) ] Variable-length binary data. n can be a value from 1 through 8,000.


2 Answers

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.

like image 115
cmsjr Avatar answered Oct 10 '22 09:10

cmsjr


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

like image 30
SQLMenace Avatar answered Oct 10 '22 10:10

SQLMenace