Sparse columns are designed to have an optimized storage format for null values. Consider using sparse columns when at least 20 percent to 40 percent of the values in a column will be NULL.
This SQL server 2008 feature can be very useful in terms of table storage.
Consider this example when table is created with following structure.
CREATE TABLE Books
(BookID int PRIMARY KEY,
BookTitle varchar(200) NOT NULL,
BookSpecs varchar(20) SPARSE NULL,
BookServey smallint SPARSE NULL) ;
So the code in this example is creating a table with two columns as SPARSE columns.
The SQL Server Database Engine uses the SPARSE keyword in a column definition to optimize the storage of values in that column. Therefore, when the column value is NULL for any row in the table, the values require no storage.
But Sparse columns are restricted to many things like:
A sparse column must be nullable and cannot have a default value
Sparse columns require more storage space for nonnull values than the space required for identical data that is not marked SPARSE.
Overall, making a column as sparse column is beneficial only when more than 40 percent of column values will be NULL.
No comments:
Post a Comment