Sql-Server

將 DEFAULT 添加到現有列

  • May 18, 2017

在 Microsoft SQL Server 中,如何使用 T-SQL 添加/更改現有表列的預設值?

ALTER TABLE yourTable ADD  CONSTRAINT constraintName  
  DEFAULT ('XYZ') FOR [YourColumn]

要更改預設值,請刪除約束並使用新值重新添加它:

ALTER TABLE yourTable
DROP CONSTRAINT constraintName

ALTER TABLE yourTable ADD  CONSTRAINT constraintName  
  DEFAULT ('ABC') FOR [YourColumn]

引用自:https://dba.stackexchange.com/questions/3843