Solved

NULL values in sql-server

Posted on 2000-03-20
10
208 Views
Last Modified: 2008-03-17
Do recordfields containing NULL-values take up storage space? (SQL-server 7)
0
Comment
Question by:pietjepuk
10 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
Yes, but only a few bytes (indicating that there is a NULL value)
0
 
LVL 1

Author Comment

by:pietjepuk
Comment Utility
In this specific situation a few bytes might very well add up to Gigabytes. Do you (or anyone) know exactly how many bytes?
0
 
LVL 2

Expert Comment

by:evertd
Comment Utility
I think that is not documented but you can try to load 1000000 rows with NULL values and a table without the null values. Than look the size differences of the two tables.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
M$ reference:
For each variable-sized column (including nullable columns), byte usage is:
1 (or more) shared bytes per table  indicating columns are null or not (2 if more than 8 columns
0 byte per column that is null
0
 
LVL 3

Expert Comment

by:ahoor
Comment Utility
Also depends on the datatype.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
ahoor: if value is null, datatype is not important: size is 0 bytes, the nullbit mask will be defined whatsoever and take 1 or more bytes (depending on the number of nullable columns in the table)
0
 
LVL 1

Author Comment

by:pietjepuk
Comment Utility
Adjusted points from 50 to 100
0
 
LVL 1

Author Comment

by:pietjepuk
Comment Utility
evertd, thanks for the suggestion but it doesn't answer my question(s).

angelIII,
So this nullbit mask uses bits (eight columns make up one byte). But does it refer to the nullability of columns, or to actual storage of null values?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
The nullability of columns is referred to in the syscolumns table, with the exact definition of every column (type, size...)
Then for every row, the values are stored one after the other (fixed sized columns first), with some bytes of informations (number of columns, size of row...) This bytes include the nullbit-mask (taking 0 to n bytes).
So the answer is, this nullbit mask refers to the actual value of NULLS
0
 
LVL 1

Author Comment

by:pietjepuk
Comment Utility
OK, (I think) I get it. Through this nullbit masking up to 8 columns that are NULL can be stored into 1 byte (per row), right?

Thanks again.

Pietjepuk.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now