开发者

Is there a big technical difference between VARBINARY(MAX) and IMAGE data types?

开发者 https://www.devze.com 2023-01-24 06:52 出处:网络
I was reading on internet these开发者_开发知识库 statements about SQL Server data types: VARBINARY(MAX) - Binary strings

I was reading on internet these开发者_开发知识库 statements about SQL Server data types:

  1. VARBINARY(MAX) - Binary strings with a variable length can store up to 2^31-1 bytes.

  2. IMAGE - Binary strings with a variable length up to 2^31-1 (2,147,483,647) bytes.

Is there a really big technical difference between VARBINARY(MAX) and IMAGE data types?

If there is a difference: do we have to customize how ADO.NET inserts and updates image data field in SQL Server?


They store the same data: this is as far as it goes.

"image" is deprecated and has a limited set of features and operations that work with it. varbinary(max) can be operated on like shorter varbinary (ditto for text and varchar(max)).

Do not use image for any new project: just search here for the issues folk have with image and text datatypes because of the limited functionality.

Examples from SO: One, Two


I think that technically they are similar, but it is important to notice the following from the documentation:

ntext, text, and image data types will be removed in a future version of MicrosoftSQL 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.


They store the same data: this is as far as it goes.

"image" is deprecated and has a limited set of features and operations that work with it. varbinary(max) can be operated on like shorter varbinary (ditto for text and varchar(max)).

Do not use image for any new project: just search here for the issues folk have with image and text datatypes because of the limited functionality.

In fact, VARBINARY can store any data that can be converted into a byte array, such as files, and this is the same process that IMAGE data type uses, so, by this point of view, both data types can store the same data. But VARBINARY have a size property, while IMAGE accepts any size up to the data type limits, so when using IMAGE data type, you will spend more resources to store the same data. In a Microsoft® SQL Server®, the IMAGE data type is really deprecated, then you must bet in VARBINARY data type.

But be carefull: The Microsoft® SQL Server® CE® (including the latest 4.0 version) still using IMAGE data type and probably this data type will not "disappears" so soon, because in Compact Edition versions, this data type is better than any other to fast files storage.


I inadvertently found one difference between them. You can insert a string into an image type but not into a varbinary. Maybe that's why MS is deprecating the image type as it really doesn't make sense to set an image with a string.

0

精彩评论

暂无评论...
验证码 换一张
取 消