244.NULL设置

/*--NULL设置

	设置当前数据库中,所有不允许NULL的列为允许NULL

*/
	

DECLARE hCForEach CURSOR GLOBAL
FOR
select --o.name,c.name,t.name,
	N'alter table '+quotename(o.name)
	+N' alter column '+quotename(c.name)
	+N' '+quotename(t.name)
	+CASE 
		WHEN t.name IN (N'decimal',N'numeric')
		THEN N'('+CAST(c.prec as varchar)+N','+CAST(c.scale as varchar)+N')'
		WHEN t.name IN (N'float')
			OR t.name like N'%char'
			OR t.name like N'%binary'
		THEN N'('+CAST(c.prec as varchar)+N')'
		ELSE N'' END
	+N' NULL'
from sysobjects o,syscolumns c,systypes t
where o.xtype='U' and o.status>=0
	and o.id=c.id
	and c.xusertype=t.xusertype
	and t.name not in(N'text',N'image',N'ntext',N'timestamp')
	and columnproperty(c.id,c.name,N'AllowsNull')=0
	and columnproperty(c.id,c.name,N'IsComputed')=0
	and columnproperty(c.id,c.name,N'IsIdentity')=0
	and columnproperty(c.id,c.name,N'IsRowGuidCol')=0
	and not exists(
		select * from sysobjects 
		where parent_obj=o.id 
			and xtype='pk' 
			and name in (
				select name from sysindexes idx,sysindexkeys idxk
				where idx.indid not in(0,255)
					and idx.id=idxk.id and idx.indid=idxk.indid
					and idxk.id=c.id and idxk.colid=c.colid))
EXEC sp_msforeach_worker '?'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值