1、实际使用例子: /*--将所需表的某特定数值类型批量转换为其他类型--*/ /*--调用示例:E1T04_1996char(10)-转换为nvarchar(100)--*/ setANSI_NULLSONsetQUOTED_IDENTIFIERONgo CREATE procedure[dbo].[p_set] as declare tb cursor for SELECT sql='alter table ['+d.name+'] altercolumn ['+a.name+']nvarchar' +'(100)' FRO
2、M syscolumns a left join systypes b on a.xtype=b.xusertype inner join sysobjectsd on a.id=d.id and d.xtype='U' andd.name='E1T04_1996' whereb.name ='char' ANDa.length='10' declare @sql varchar(1000) open tb fetch next from tb into @sql while @@fetch_status = 0 begi
3、n exec(@sql) fetch next from tb INTO @sql end close tb deallocate tb ----DECLARE@sqlVARCHAR(1000)--select@sql='alter table ['+d.name+'] altercolumn ['+a.name+']nvarchar' -- +'(100)' FROM syscolumns a -- left join systypes b on a.xtype=b.xusertype -- inner join
5、ect * from dbo.sysobjects where id = object_id(N'[dbo].[p_set]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[p_set] GO /*--将所有的表中,数值类型由char,varchar改为nchar,nvarchar --*/ /*--调用示例: ex
6、ec p_set --*/ --修改的存储过程 create procedure p_set as declare tb cursor for SELECT sql='alter table ['+d.name +'] alter column ['+a.name+'] n' +b.name+'('+cast(a.length*2 as varchar)+')' FROM syscolumns
7、 a left join systypes b on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' where b.name in('char','varchar') and not