- use db
- --1.查找出表中该字段的约束名称(或根据已有的提示及对象'DF__******')
- declare @dropconstraint varchar(150)
- declare @conName varchar(50)
- select @conName =b.name from sysobjects b join syscolumns a on b.id = a.cdefault
- where a.id = object_id('dbo.Table_1') and a.name ='aid'
- print @conName
- --2. 删除存在的约束
- set @dropconstraint = ('alter table dbo.Table_1 drop constraint ' + @conName)
- exec (@dropconstraint)
|