sql 修改字段默认值
Posted zhyue93
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 修改字段默认值相关的知识,希望对你有一定的参考价值。
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
以上是关于sql 修改字段默认值的主要内容,如果未能解决你的问题,请参考以下文章