日期:2014-05-18  浏览次数:20480 次

批量修改数据表字段类型
sql2005

把所有表的字段为bit类型的改为varchar(50)

请大家提供下方法,感谢!

------解决方案--------------------
declare @sql varchar(8000)
SQL code
select 
  @sql=isnull(@sql,'')
  +' alter table '+c.name
  +' alter column '+a.name
  +' varchar(50);'
from sys.columns a
join sys.types b on a.system_type_id=b.system_type_id
join sys.objects c on a.object_id=c.object_id
where b.name='bit' and c.type='U'

exec (@sql)

------解决方案--------------------
SQL code
declare @sql varchar(8000)
select 
  @sql=isnull(@sql,'')
  +' alter table '+c.name
  +' alter column '+a.name
  +' varchar(50);'
from sys.columns a
join sys.types b on a.system_type_id=b.system_type_id
join sys.objects c on a.object_id=c.object_id
where b.name='int' and c.type='U'

exec (@sql)