修改约束字段属性.sql 418 B

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