November 18, 2017 at 9:52 am
Hello
I haven't really had the need for VARBINARY before
Just started filling in some gaps in my SQL knowledge and decided to investigate further
Here, I appear to have 2 options:
VARBINARY(n|MAX) where n is between 1 and 8000
From what I've seen, n is the number of bytes; so a max of 8000
MAX allows up to 2^31 - 1; approx 2GB
Is that correct?
Why the big difference? 8KB vs 2GB
Thanks
Damian.
- Damian
November 19, 2017 at 9:58 am
DamianC - Saturday, November 18, 2017 9:52 AMHelloI haven't really had the need for VARBINARY before
Just started filling in some gaps in my SQL knowledge and decided to investigate furtherHere, I appear to have 2 options:
VARBINARY(n|MAX) where n is between 1 and 8000
From what I've seen, n is the number of bytes; so a max of 8000
MAX allows up to 2^31 - 1; approx 2GBIs that correct?
Why the big difference? 8KB vs 2GBThanks
Damian.
The big difference is because of 8K pages. VARBINARY(n) was designed to live on a normal data page. VARBINARY(MAX) is treated like any other MAX blob. Typically (especially if longer than 8K), it won't live in a normal 8K page. Instead, it works like the old IMAGE datatype, which lives in a special kind of storage and only has a pointer to it on normal 8K pages.
The 2GB limit is likely because of the use of a "double word" behind the scenes, which is 32 bits, which is probably also a leftover from the old FAT32 files which had a limit of 4GB (the total number of values possible in 32 bits) and only the positive side of that range of values was considered for SQL Server.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2017 at 10:27 am
Jeff Moden - Sunday, November 19, 2017 9:58 AMDamianC - Saturday, November 18, 2017 9:52 AMHelloI haven't really had the need for VARBINARY before
Just started filling in some gaps in my SQL knowledge and decided to investigate furtherHere, I appear to have 2 options:
VARBINARY(n|MAX) where n is between 1 and 8000
From what I've seen, n is the number of bytes; so a max of 8000
MAX allows up to 2^31 - 1; approx 2GBIs that correct?
Why the big difference? 8KB vs 2GBThanks
Damian.
The big difference is because of 8K pages. VARBINARY(n) was designed to live on a normal data page. VARBINARY(MAX) is treated like any other MAX blob. Typically (especially if longer than 8K), it won't live in a normal 8K page. Instead, it works like the old IMAGE datatype, which lives in a special kind of storage and only has a pointer to it on normal 8K pages.
The 2GB limit is likely because of the use of a "double word" behind the scenes, which is 32 bits, which is probably also a leftover from the old FAT32 files which had a limit of 4GB (the total number of values possible in 32 bits) and only the positive side of that range of values was considered for SQL Server.
It's one of those relics, of course a LOB should be bound by storage space and not 2^32 -1 byte size these days.
😎
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply