批量修改Ms SqlServer 的default(默认值)
2009-07-22 19:44
155 查看
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 ;
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 ;
相关文章推荐
- 经验:XP下安装MS SQL SERVER 2000 (只要做一个修改)
- [转+自己修改]将 MS SQL Server 2005 SP2 整合到安装文件
- MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏
- MS SQL SERVER 2008修改服务器排序规则
- MS SQL Server 中的"默认值"
- 【技巧】SQL中如何修改表格(table)中列(column)的默认值(default);
- sql server 批量修改表和存储过程的所有者
- MS SQLSERVER端口修改
- 在SQL SERVER中批量修改字段名的办法!又是在CSDN查到的,哈哈
- MS SQLServer 批量附加数据库
- CodeSmith 5.0工具实例篇系列4——根据表生成修改的存储过程,针对MS Sqlserver
- MS SQLServer 批量附加数据库
- 《MS SQL Server 2000管理员手册》系列——16. 建立与使用默认值、条件约束及规则
- MS SQL Server存储过程批量修改用户表所有者
- MS SQL Server存储过程批量修改用户表所有者
- 关于ms sql server的所有者及修改数据库对象的所有者
- 在SQL SERVER中批量修改字段名的办法!
- 获取MS SQL Server用户存储过程最近修改日期
- myRoad--MS SQL Server身份验证的修改
- MS SQl Server 为用户批量授与存储过程执行权限