?
Solved

NULL values in sql-server

Posted on 2000-03-20
10
Medium Priority
?
221 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 143

Expert Comment

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

Author Comment

by:pietjepuk
ID: 2636274
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
ID: 2636536
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2636618
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
ID: 2641065
Also depends on the datatype.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2643408
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
ID: 2643655
Adjusted points from 50 to 100
0
 
LVL 1

Author Comment

by:pietjepuk
ID: 2643656
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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 2644167
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
ID: 2644388
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

862 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