So I read this question: Add a column with a default value to an existing table in SQL Server
And it got me to wondering something:
Most of the answers to that question indicated that you should create a DEFAULT, and bind the new column to the default so that it would be seeded with values.
Seems fair.
BUT: What if I'm ok with supplying a default value for existing rows, but for new rows, I want to force code to set a value for the column -- so I don't want to keep a default on the column?
I could:
- Add the column with the default and then drop the default
- Add the column as nullable, UPDATE the table to set my default value, and then alter table to make the column nullable.
I think that both methods would work, but now suppose that I have a lot of rows in that table. Which method is going to be the most efficient?