当前位置: 代码迷 >> Sql Server >> 求sql脚本语句:1:怎么更新字段的默认值2:怎么更新表主键
  详细解决方案

求sql脚本语句:1:怎么更新字段的默认值2:怎么更新表主键

热度:111   发布时间:2016-04-27 19:03:31.0
求sql脚本语句:1:如何更新字段的默认值2:如何更新表主键
如题:
1、原表A的a1字段默认值是0,现在想通过sql语句更新为1
2、原表A的主键字段为a1、b1,现在想改为a1、c1、d1。

------解决方案--------------------

--如果原来有默认值,现在需要更改默认值,执行如下语句:

declare @csname varchar(100)
set @csname= ' '
select @csname=[name]--约束名称
from sysobjects t
where id=(select cdefault from syscolumns where id=object_id(N '表名 ') and name= '字段名 ')
exec( 'alter table 表名 drop constraint '[email protected])

alter table 表名 add default(3000) for 字段名

  相关解决方案