SQL Server数据库操作中,我们常常会因为工作的需要来修改字段的数据类型,当字段比较多的时候就需要批量来进行修改了,本文我们给出了一个SQL Server数据库批量修改字段的数据类型的代码实例,它是通过存储过程来实现的,希望能够对您有所帮助 。
代码实例如下:
- create procedure p_set
- as
- declare tb cursor for
- SELECT sql=alter table [+d.name
- +] alter column [+a.name+]
- +b.name+(8,3)
- FROM syscolumns 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(decimal)
- order by d.name,a.name
- declare @sql varchar(1000)
- open tb
- fetch next from tb into @sql
- while @@fetch_status = 0
- begin
- print @sql
- exec(@SQL)
- fetch next from tb into @sql
- end
- close tb
- deallocate tb
- go
上面的代码就是SQL Server批量修改字段的数据类型的过程,它是通过一个存储过程来实现的,本文我们就介绍到这里了,希望本次的介绍能够对您有所收获!