SQL Server批量修改字段的数据类型的代码实例


  本文标签:SQL Server 批量修改字段 存储过程

  SQL Server数据库操作中,我们常常会因为工作的需要来修改字段的数据类型,当字段比较多的时候就需要批量来进行修改了,本文我们给出了一个SQL Server数据库批量修改字段的数据类型的代码实例,它是通过存储过程来实现的,希望能够对您有所帮助  。

  代码实例如下:

  1. create procedure p_set   
  2. as   
  3. declare tb cursor for   
  4. SELECT sql=alter table [+d.name   
  5. +] alter column [+a.name+]    
  6. +b.name+(8,3)   
  7. FROM syscolumns a left join systypes b on a.xtype=b.xusertype   
  8. inner join sysobjects d on a.id=d.id and d.xtype=U and d.name<>dtproperties   
  9. where   
  10. b.name in(decimal)   
  11. order by d.name,a.name   
  12. declare @sql varchar(1000)   
  13. open tb   
  14. fetch next from tb into @sql   
  15. while @@fetch_status = 0   
  16. begin   
  17. print @sql  
  18. exec(@SQL)  
  19. fetch next from tb into @sql   
  20. end   
  21. close tb   
  22. deallocate tb   
  23. go 

  

  上面的代码就是SQL Server批量修改字段的数据类型的过程,它是通过一个存储过程来实现的,本文我们就介绍到这里了,希望本次的介绍能够对您有所收获!