批量修改系统中int,varchar字段的默认值
来源:互联网 发布:打印标签软件 编辑:程序博客网 时间:2024/05/18 01:02
declare @t table(id int identity(1,1),tbname varchar(256), colname varchar(256),xtype varchar(20))
insert into @t
select a.name,b.name ,c.name
from sysobjects a
inner join syscolumns b on a.id=b.id
inner join systypes c on b.xusertype = c.xusertype
where a.xtype='u'
and c.name in ('varchar','int')
and b.status<>0x80 --去掉自增列
and not exists --过滤掉原来已存在默认值的列
(select 1
from
(select
(select name from sysobjects where id=c.id) 表名,
(select name from syscolumns where cdefault=a.id) 字段名
from sysobjects b,syscolumns c,syscomments a
where b.xtype='d'
and a.id=b.id
and b.parent_obj=c.id
and a.colid=c.colid
) t
where a.name=t.表名
and b.name=t.字段名)
--select * from @t
declare @i int
set @i=1
declare @tbname varchar(256),@colname varchar(256),@xtype varchar(20),@sql nvarchar(4000)
while @i <= (select MAX(id) from @t)
begin
select @tbname=tbname,@colname=colname,@xtype = xtype from @t where id=@i
set @sql = 'alter table ['+@tbname+'] add constraint ' + 'df_' + replace(@tbname,'-','') +'_'+ replace(@colname,'-','') + ' default '
if @xtype = 'int'
begin
set @sql = @sql + ' 0 '
end
else if @xtype = 'varchar'
begin
set @sql = @sql + ''''''
end
set @sql = @sql + ' for [' + @colname +']'
exec(@sql)
set @i = @i + 1
end
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/htl258/archive/2009/04/16/4083008.aspx
- 批量修改系统中int,varchar字段的默认值
- 批量修改系统中int,varchar字段的默认值
- 批量修改系统中int,varchar字段的默认值
- 批量修改sqlserver 字段默认值
- MySQL中字段varchar和int排序的区别
- SQL 修改字段的默认值
- 修改字段的数据类型、字段的默认值
- 批量修改数据库中字段的数据类型
- 批量修改Ms SqlServer 的default(默认值)
- mysql数据库中存储数字字段时,选择int和varchar的区别
- SQL SERVER 2005 修改字段的默认值
- sql server 修改字段的默认值
- mysql 批量修改默认值
- MySQL修改字段默认值
- MYSQL修改字段默认值
- SQL修改字段默认值
- SQL修改字段默认值
- SQL修改字段默认值
- Android的Camera系统结构
- pku1905 pku3122(二分2,几何,面积)
- linux 下计算程序运行时间 一句话说明
- SQL批量删除用户表(先删除所有外键约束,再删除所有表)
- SQL2005 批量修改架构名
- 批量修改系统中int,varchar字段的默认值
- 平台崩溃之operator new异常(二十二)-2010-8-12
- poj1426解题报告
- 动态批量修改字段属性
- c:forEach status.index 行索引的使用[转载!]
- WinCE的LCD驱动程序编写指南
- ZOJ2059The Twin Towers题解动态规划DP
- 全文索引创建实例
- MySql 基本操作