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

后端 未结 30 2172
轮回少年
轮回少年 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:21

    Alternatively, you can add a default without having to explicitly name the constraint:

    ALTER TABLE [schema].[tablename] ADD  DEFAULT ((0)) FOR [columnname]
    

    If you have an issue with existing default constraints when creating this constraint then they can be removed by:

    alter table [schema].[tablename] drop constraint [constraintname]
    

提交回复
热议问题