Thursday, July 2, 2015

Did you know that you may add a NOT NULL column to an existing table that has rows in it with T-SQL?

You have to give a default value and the constraint for it has to be given at the moment the column is added like so:

ALTER Table My_Corny_Table
ADD The_Date DateTime NOT NULL
CONSTRAINT DF_My_Corny_Table_The_Date DEFAULT GETDATE()

No comments:

Post a Comment