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

--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 ;

最新文章

  1. Xshell显示中文乱码问题
  2. C# 如何给sql数据库的日期字段插入空值
  3. php测试程序运行时间和占用内存情况
  4. 距离矢量路由协议举例——RIP
  5. iOS AvPlayer AvAudioPlayer音频的后台播放问题
  6. 路径问题以及cookie详解
  7. 分享几种Linux软件的安装方法
  8. asp.net mvc框架的一些切入点
  9. OpenCV成长之路:图像直方图
  10. ch4-注册 登陆 实现 cookie使用
  11. Redis~Linux环境下的部署
  12. python基础篇实战
  13. 主机配置nginx后如何获取访问者IP
  14. ABP框架系列之八:(Introduction-介绍)
  15. 【Mybatis】XML配置实现增删改查
  16. #pragma的一些用法
  17. 爱奇艺视频显示列表CSS实现
  18. loadrunner中controller 中scenario-> rendezvous灰色不可用的解决方法:
  19. web自动化测试:watir+minitest(四)
  20. 使用 Python 开始你的机器学习之旅【转】

热门文章

  1. 0x04 Python logger 支持多进程日志按大小分割
  2. linux系统盘扩容操作
  3. [转]【会话技术】Session技术
  4. 浅析 fstab 与移动硬盘挂载方法
  5. springboot 整合 freemarker
  6. 用JSON.parse(JSON.stringify(itemData))序列化反序列化实现‘深度复制’
  7. 爬虫-selenium的使用
  8. JDOJ 1133 分段公司利润
  9. 【java异常】Expected one result (or null) to be returned by selectOne(), but found: 63
  10. 洛谷 P1801 黑匣子_NOI导刊2010提高(06) 题解