Add a column with a default value to an existing table in SQL Server

后端 未结 30 2145
轮回少年
轮回少年 2020-11-22 12:00

How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?

30条回答
  •  隐瞒了意图╮
    2020-11-22 12:13

    Beware when the column you are adding has a NOT NULL constraint, yet does not have a DEFAULT constraint (value). The ALTER TABLE statement will fail in that case if the table has any rows in it. The solution is to either remove the NOT NULL constraint from the new column, or provide a DEFAULT constraint for it.

提交回复
热议问题