Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A sparse column doesn't use <strong>4x the amount of space</strong> to store a value, it uses a (fixed) <strong>4 extra bytes</strong> per non-null value. (As you've already stated, a NULL takes 0 space.)</p> <ul> <li><p>So a non-null value stored in a <em>bit</em> column would be 1 bit + 4 bytes = 4.125 bytes. But if 99% of these are NULL, it is still a net savings.</p></li> <li><p>A non-null value stored in a <em>GUID (UniqueIdentifier)</em> column is 16 bytes + 4 bytes = 20 bytes. So if only 50% of these are NULL, that's still a net savings.</p></li> </ul> <p>So the "expected savings" depends strongly on what <em>kind</em> of column we're talking about, and your estimate of what ratio will be null vs non-null. Variable width columns (varchars) are probably a little more difficult to predict accurately.</p> <p>This <a href="http://msdn.microsoft.com/en-us/library/cc280604.aspx" rel="noreferrer">Books Online Page</a> has a table showing <em>what percentage</em> of different data types would need to be null for you to end up with a benefit.</p> <p>So <em>when</em> should you use a Sparse Column? When you expect a significant percentage of the rows to have a NULL value. Some examples that come to mind:</p> <ul> <li>A "<strong>Order Return Date</strong>" column in an order table. You would hope that a very small percent of sales would result in returned products.</li> <li>A "<strong>4th Address</strong>" line in an Address table. Most mailing addresses, even if you need a Department name and a "Care Of" probably don't need 4 separate lines.</li> <li>A "<strong>Suffix</strong>" column in a customer table. A fairly low percent of people have a "Jr." or "III" or "Esquire" after their name.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload