判断多个表是否加了默认值脚本
来源:互联网 发布:linux echo用法 编辑:程序博客网 时间:2024/05/01 22:11
set nocount on
create table #tb(id int identity(1,1), tbname varchar(100))
insert into #tb(tbname)
select 'tbCustUse_gold'
union all select 'tbCustUse_PJ'
union all select 'tbCustUse_PJ'
union all select 'tbOrderBalance_report_dtl'
union all select 'tbOrderBalance_report_gold'
union all select 'tbOrderBalance_report_pj'
union all select 'tbOrderBalance_report_stone'
union all select 'tbOrderBalance_report_sum'
union all select 'tbOrderBalance_StonePrint'
union all select 'tbOrderBalance_StonePrint_cust'
declare @maxid int,@i int
select @maxid=max(id) from #tb
set @i=1
while @i<=@maxid
begin
declare @cur cursor,@name varchar(100),@type varchar(50)
declare @table varchar(100),@s varchar(2000)
select @table=tbname from #tb where id=@i
set @cur=cursor for select a.name,b.name from syscolumns a inner join systypes b on a.xtype=b.xtype where a.id=object_id(@table)
open @cur
fetch next from @cur into @name,@type
while @@fetch_status=0
begin
set @s=''
set @s='if not exists(select d.name from syscolumns a join sysobjects b on a.id=b.id
join syscomments c on a.cdefault=c.id join sysobjects d on c.id=d.id
where b.name= '''+@table+''' and a.name='''+@name+''')
alter table '+@table+' add constraint DF_'+@table+'_'+@name+' default ('+
case when charindex('int',@type)>0 or @type='numeric' then '0'
when @type='datetime' then 'getdate()' else '''''' end +') for '+ @name+ char(10)+
'GO'
print @s
fetch next from @cur into @name,@type
end
close @cur
deallocate @cur
set @i=@i+1
end
drop table #tb
- 判断多个表是否加了默认值脚本
- document.compatMode介绍(判断文档是否加了标准声明)
- 用jQuery 判断一个标签是否加了click事件
- 判断是否root了
- js判断页面图片是否存在,并设置默认值
- SQLServer判断指定列的默认值是否存在,并修改默认值
- Android判断网路是否畅通加权限
- 判断是否使用了spfile
- 判断生日是否过了
- 加默认值 对表外键
- 用shell脚本循环加判断生成sql脚本
- [修改]脚本判断网站是否能打开
- JS判断脚本是否加载完成
- 判断脚本是否加载完成的方法
- 判断是否支持脚本显示不同操作
- shell脚本循环判断进程是否存在
- javascript 判断 脚本加载请求是否健康
- shell脚本判断/dev/ttyUSB0是否存在
- 学生成绩, 学号, 姓名。小程序
- 交叉编译指导网站http://cross-lfs.org
- 一个wxWidgets判断注册表键值的函数
- HDU1247字典树
- 大飞哥
- 判断多个表是否加了默认值脚本
- 너무 반갑습니다.ㅋㅋㅋㅋ
- Javascript鼠标滚轮监测
- 求助 : win7 32位下安装vc++的一个问题?
- 确认信息需品(济南报考点)
- 超级实用且不花哨的js代码大全(转载)
- Linux设备驱动12
- 运用RUP 4+1视图方法进行软件架构设计(转载)
- Swing JTable 表格排序jdk1.5于1.6