修改欄位預設值-查找欄位的約束名稱 刪除約束 修改預設值約束 獲取表列的預設值 ...
1、查出該欄位的約束名稱
SELECT c.name FROM sysconstraints a INNER JOIN syscolumns b on a.colid=b.colid INNER JOIN sysobjects c on a.constid=c.id WHERE a.id=object_id('TClass') AND b.name='PhoneIsOpen'
2、刪除該約束
ALTER TABLE TClass DROP CONSTRAINT DF__TClass__PhoneIsO__51BA1E3A
3、修改預設值約束
ALTER TABLE TClass ADD CONSTRAINT DF__TClass__PhoneIsO__51BA1E3A DEFAULT(1) FOR PhoneIsOpen
4、獲取表列的預設值
SELECT SO.NAME AS "Table Name", SC.NAME AS "Column Name", SM.TEXT AS "Default Value" FROM dbo.sysobjects SO INNER JOIN dbo.syscolumns SC ON SO.id = SC.id LEFT JOIN dbo.syscomments SM ON SC.cdefault = SM.id WHERE SO.xtype = 'U' and so.name='TClass' ORDER BY SO.[name], SC.colid