Solved

NULL values in sql-server

Posted on 2000-03-20
10
216 Views
Last Modified: 2008-03-17
Do recordfields containing NULL-values take up storage space? (SQL-server 7)
0
Comment
Question by:pietjepuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

696 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