Friday, March 9, 2012

Nullable Bit Field Storage

How does SQL store a collection of bit fields when they are nullable? I
know that it stores the first 8 bits of a table in the same byte to save
storage, but a nullable bit field is essentially a tri-state and can't
possibly be stored in a single bit.Each row contains a separate null bitmap with a bit representing the null
state of each column.
Hope this helps.
Dan Guzman
SQL Server MVP
"Brad" <me@.privacy.net> wrote in message
news:MPG.1a70ba8015d9aeee98bb01@.news...
quote:

> How does SQL store a collection of bit fields when they are nullable? I
> know that it stores the first 8 bits of a table in the same byte to save
> storage, but a nullable bit field is essentially a tri-state and can't
> possibly be stored in a single bit.
|||In article <Oc027982DHA.556@.TK2MSFTNGP11.phx.gbl>, danguzman@.nospam-
earthlink.net said...
quote:

> Each row contains a separate null bitmap with a bit representing the null
> state of each column.

How is that sized? Is it one byte for every eight nullable columns?|||From the Books Online <createdb.chm::/cm_8_des_02_92k3.htm>:
Null Bitmap (Null_Bitmap) = 2 + (( Num_Cols + 7) / 8 )
Hope this helps.
Dan Guzman
SQL Server MVP
"Brad" <me@.privacy.net> wrote in message
news:MPG.1a7133c92572518f98bb05@.news...
quote:

> In article <Oc027982DHA.556@.TK2MSFTNGP11.phx.gbl>, danguzman@.nospam-
> earthlink.net said...
null[QUOTE]
> How is that sized? Is it one byte for every eight nullable columns?

No comments:

Post a Comment