You are here

Estimating the Size of an Index

If you’re creating a new index in SQL Server, it is good practice to make sure you have enough space on your drive to do so. You’ll not only need the space to hold it, but double the space as SQL Server builds it on temporary disk space. ( So if your index is going to be 1 GB, then you will need up to 2 GB to make it. By the way, when rebuilding, you’ll need triple the space, as SQL Server also retains the old index while it creates a new one.

While figuring out the size of an existing index is easy, estimating the space of an index that you haven’t created yet is not so obvious.

This script will make it easy.

-- Each column must be listed in the parens.
-- SUM(LEN(columnName))
-- FROM must refer to the table where the columns are
 SUM(LEN('Col1')) +
 SUM(LEN('Col2')) +
 / 1073741824.0 AS [SizeInGB] -- This converts bytes to GB
FROM TableName

The output will be the size of the index, in GB. Creating the index will need that much space in tempdb and that much space in your MDF or NDF file.

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer