Solved

NULL values in sql-server

Posted on 2000-03-20
10
211 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 100 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL 10 35
How to prevent deleting SQL tables thru FE Application? 20 86
SQL Insert to Begin if data exists 2 33
MSSQL - Lock Row from reading by other programs 9 38
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

828 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