How do you add a NOT NULL Column to a large table in SQL Server?

前端 未结 12 1854
情话喂你
情话喂你 2020-12-02 15:42

To add a NOT NULL Column to a table with many records, a DEFAULT constraint needs to be applied. This constraint causes the entire ALTER TABLE command to take a long time to

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 16:09

    Admitted that this is an old question. My colleague recently told me that he was able to do it in one single alter table statement on a table with 13.6M rows. It finished within a second in SQL Server 2012. I was able to confirm the same on a table with 8M rows. Something changed in later version of SQL Server?

    Alter table mytable add mycolumn char(1) not null default('N');
    

提交回复
热议问题