_SQL SERVER数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

批量修改Ms SqlServer 的default(默认值)

作者:黑客防线网安SQL维护基地 来源:黑客防线网安SQL维护基地 浏览次数:0

本篇关键词:默认修改批量

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 ;


    希望这篇批量修改Ms SqlServer 的default(默认值)的文章能够对您有所帮助,如果您觉得这篇网站维护教程有用的话,别忘了推荐给您的朋友哦!如果您有好的经验方法,不妨拿出来和大家一起分享:假如每个人都拿出一个经验,那么我们都将额外的获取一堆他人的经验。
请记住本站永久域名:(黑客防线网安服务器维护方案维护基地)Www.Rongsen.Com.Cn
    黑客防线网安服务器维护方案本篇连接:http://kj.rongsen.com.cn/show-10293-1.html
网站维护教程更新时间:2012-03-21 02:32:21  【打印此页】  【关闭
0
顶一下
0
踩一下
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer