【问题标题】:How can I add a new column and check constraint to an existing table in SQL Server? [closed]如何向 SQL Server 中的现有表添加新列和检查约束? [关闭]
【发布时间】:2015-11-08 18:42:58
【问题描述】:

如何向现有表添加新列以及对该列的检查约束?

我使用的是 SQL Server 2008

【问题讨论】:

    标签: sql sql-server sql-server-2008 alter-table


    【解决方案1】:

    你可以用一个Alter 语句来做这一切,使用下面的模板:

    Alter table table_name
    add column_name column_datatype
    constraint constraint_name check (column_name>some_value)
    

    示例:

    create table tbl(a int)
    go
    alter table tbl
    add clmn int
    constraint constraint_name check (clmn >10);
    

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 2018-03-26
      • 1970-01-01
      相关资源
      最近更新 更多