11

I would like alter my table and add SPARSE option to all fields that contain a lot of NULL values. What is the right syntax for this ALTER TABLE command?

4

3 回答 3

11
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
于 2011-09-30T11:24:25.090 回答
11

The other answers work, but you can also get away with:

ALTER TABLE #foo ALTER COLUMN bar ADD SPARSE;

This way you don't have to look up the column's type or nullability.

于 2016-04-15T01:22:54.423 回答
1
ALTER TABLE Xtable
ADD myCol int sparse null 
于 2011-09-30T11:22:42.507 回答