Most ofa table’s space is occupied by its data. There are also other factors like Index and Table Schema information that occupies the space. There are many system defined stored procedures, using that we can calculate the space occupied. Likethe below system, stored procedure displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database. In this article you will learn how to calculate Data Row Space usage In SQL Server.
Example:

In the above query we find out the row number and space reserved for Employee table.
If you find out more details about space used by a table like size of minimum and maximum record and numbers of page record then you can use below query.

As I explained earlier there are many methods to find out the space occupied by a table but “I think we should have basic idea how to calculate the space occupied by each row and a whole table.” In this article I will explain how to calculate the approximate space occupied by a row or whole table.
There are three key factors that decide the space consumption of a field.
- Data Type
- Nature of Data Type(Fixed or Variable)
- Nullable property of field.
Data Type:
The space occupied by each field mainly depends upon the data type of that particular field. Each data type occupies a different amount of space. The following list provides commonly used data types and space occupied by that data type.
Data Type | Size(In Bytes) |
Tinyint | 1 |
Smallint | 2 |
Int | 4 |
Bigint | 8 |
Smallmoney | 4 |
Money | 8 |
Decimal | 5-17 bytes, depending on the number of digits |
Numeric | 5-17 bytes, depending on the number of digits |
Bit | Minmum 1 if there are 8 or less bit columns in a table, If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on. |
Nature of Data Type(Fixed or Variable):
Fixed data type always occupies the same space that is defined at declaration time even if the field contains less data but variable length data type always occupies space according the amount of data in field.
Example: if we defined the char(100) for address field then field always use 100 bytes even if address is 20 character long. But if we used varchar(100) then address field only contain 20 bytes.
Nullable Property of Field:
Like variable length data fields, each record in a table containing nullable field uses a little extra storage space. We will read about it in detail later in article.
Until now we read about the spaced occupied by each field now w will read how to calculate space for whole row. Space occupied by each row is manly dependant upon five factors. These factors define the space required by the row to store the data. These five field are the following.

- Row Header
- Fixed Data
- Null Block
- Variable Block
- Variable Data
Now we will read about each factor and how this factor affects the space occupied by a row.
Row Header:
Each row in a table contain a 4byte header. This header keeps track of where the row is placed in the table and which fields are contains a row. Row header is divided into 3 parts.

The first 2 bytes of the row, called Status Bits A and Status Bits B, are the bitmaps containing the information about the row, such as row type. Next 2 bytes are for null bitmap, null bitmap offset is always present in data records, regardless of whether the columns are nullable or not.
Fixed Data:
The fixed length data always occupies the same space that is defined at the declaration of field and is easy to predict. For example small int occupy 2 bytes, biging 8 bytes ,int occupy 4 bytes and char(10) always occupied 10 bytes even if field contains 4 bytes long data.
Null Block:
The Null block is not a compulsory data block, it is only present when table contains nullable data. If table doesn’t contain any nullable data then next block after fixed data block will be variable block. In this case only 4 blocks will be present instead of 5 blocks(null block will be absent ). The null block is also known as null bitmap . If a row contains nullable data then minimum size of null block will be 3 bytes, because null block begins with 2 bytes and 1 bytes for each 8th columns.
If numbers of column in table is b/w 1-8 then size of null block will be 3 bytes , if numbers of columns in table is b/w 9-16 then size of null block will be 4 bytes and if numbers of columns in table is b/w 17-24 then size of null block will be 5 bytes and so on.

Now a question arises: “What is work of this extra byte in null block?”.
The main task of this byte is to indicate which column is nullable into table. If any column in nullable then bit will set to 1 otherwise bit will be set 0. Let us take some example to clear up this concept.
Example 1:
Table Employee have 5 columns and 2nd and 4th columns in table are nullable then the following null block will be created.

2 bytes are reserved for null block. Now table contain 5 columns so we required (5+7)/8=1 additional byte according the formula and total of 3 bytes for null block. This 1 byte contains the null status of staring 8 columns. But our table only has 5 columns , so the last three bits will be set to 1 that are unused. Now we focus on staring 5 bits. As we asked that columns number 2nd and 4th are nullable so bit for both columns will set 1 and bit for remaining columns will be set to 0.
Example 2:
Table Employee have total 11 columns and column 1st,3rd and 9th are nullable type columns then for employee table following









Vivek KumarPosted Apr 15, 2016, 5:16 AM
Nice Share
Hari ShankerPosted Apr 15, 2016, 2:06 AM
Nice article..
Debasis SahaPosted Apr 15, 2016, 12:31 AM
Nice article..
Rahul Kumar SaxenaPosted Apr 14, 2016, 2:51 PM
Good work
Gowtham RajamanickamPosted Apr 14, 2016, 9:30 AM
nice sharing
Vignesh ManiPosted Apr 14, 2016, 8:07 AM
Nice