What is the difference when speaking about 'LOB' and 'binary' data?
Is it the same, in terms of binary data being stored in a separate filegroup, or are there differences?
sql server
What is the difference when speaking about 'LOB' and 'binary' data?
Is it the same, in terms of binary data being stored in a separate filegroup, or are there differences?
Best Answer
According to Technet: Data Types (Transact-SQL)
So these types are defined as LOB data types. When you asked about
binary data
I suppose you are talking about the data ofbinary
data type.Binary
data type can be one of two kinds: fixed-length and variable length. Fixed-length binary data type or variable-length varbinary data type with the maximum number of characters instead of MAX specifier is always stored in row in the first case and (may be) off-row in the second and is NOT LOB data type.On the other hand, according to this classification (from the same Technet article):
varchar(max)
,nvarchar(max)
,text
,ntext
data types are CHARACTER strings and not BINARY strings.So LOB data types include CHARACTER strings that are not binary strings.
Conclusion
BINARY data <> LOB data
And the only case when it's the same is when your data is defined as VARBINARY(MAX)
Back to your question from the comment on how LOB data can be stored.
If the value is one of the old legacy types (
text
,ntex
t,image
) then it is stored off-row by default.Off-row means that there is a pointer from the data record which points to the location of the record storing the actual LOB value or the start of the tree that stores the LOB value:
This image is from Pro SQL Server Internals 1st Edition by Dmitri Korotkevitch book.
But you can force the value to go in-row (obviously with the limit) using
text in row
option.Starting with SQL server 2005 new LOB data types were introduced, these new types:
varchar(max)
,nvarchar(max)
,varbinary(max)
are stored in-row by default (of course with the limit of 8Kb)............................................................
To complete a picture.
There is another kind of data that is stored off-row, that is row-overflow data.
Thanks to this feature, starting with 2005 it's possible not only to DEFINE (as it was in 2000) some variable-length columns with the sum of sizes that exceeds 8060 bytes, but also to INSERT data that will exceed this limit, some of these values will be pushed off-row (i.e. the value will be stored on off-row page and IN ROW there will be only a pointer to the row stored on the row-overflow page):
(From Row-Overflow Data Exceeding 8 KB)
Back to the origin of this your question, how LOB data can be moved.
When we are talking about moving data to another filegroup, and about difficulties we have with LOB data, we refer to LOB data and NOT to
binary data
that is stored in binary columns (in-row
data).From What about moving LOB data? by Kimberly L. Tripp
And to your last question:
Separate filegroup is not a requirement for storing LOB data. But it's possible to store LOB data separately using TEXTIMAGE_ON option:
And the data of fixed-length
binary
data type just cannot be stored in a separate filegroup. It's impossible because all the data is stored in-row, and it's syntactically impossible asMore on TEXTIMAGE_ON here: CREATE TABLE (Transact-SQL)