mssql中修改字段默认值_mssql中修改字段默认值default value

更新时间:2018-12-12    来源:Mssql    手机版     字体:

【www.bbyears.com--Mssql】

1、取得数据库所有表的默认值:

 代码如下

select

t3.name as 表名,t1.name as 字段名,t2.text as 默认值 ,t4.name

from syscolumns t1,syscomments t2,sysobjects t3 ,sysobjects t4

where t1.cdefault=t2.id and t3.xtype=’u’ and t3.id=t1.id

and t4.xtype=’d’ and t4.id=t2.id;

2、生成删除所有默认值的语句:

 代码如下

select “ALTER  TABLE ” +  t3.name   + ” DROP  CONSTRAINT  ” +t4.name  +”;” 

  from   syscolumns   t1,syscomments   t2,sysobjects   t3   ,sysobjects   t4   

    where     t1.cdefault=t2.id   and   t3.xtype=’u"   and   t3.id=t1.id   

  and   t4.xtype=’d"   and   t4.id=t2.id  ;

3、生成批量添加所有默认值的语句:

 代码如下

select “alter table ” +  t3.name   + “  add default  (1)  for ” +t1.name  +”;” 

from   syscolumns   t1,syscomments   t2,sysobjects   t3   ,sysobjects   t4   

   where     t1.cdefault=t2.id   and   t3.xtype=’u"   and   t3.id=t1.id   

and   t4.xtype=’d"   and   t4.id=t2.id ;

本文来源:http://www.bbyears.com/shujuku/46468.html

热门标签

更多>>

本类排行