SQL Server: modify table, how to add SPARSE definition

I would like to modify my table and add the SPARSE parameter to all fields that contain many NULL values. What is the correct syntax for this ALTER TABLE command?

+7
source share
3 answers
 CREATE TABLE #Foo ( X INT NULL, Y INT NULL ) ALTER TABLE #Foo ALTER COLUMN Y INT SPARSE NULL ALTER TABLE #Foo ALTER COLUMN X INT SPARSE NULL 
+10
source

Other answers work, but you can also get away with:

 ALTER TABLE #foo ALTER COLUMN bar ADD SPARSE; 

This way you do not need to look for the column type or nullability value.

+5
source
 ALTER TABLE Xtable ADD myCol int sparse null 
+1
source

All Articles