您的位置:首页 > 数据库

mssql批量修改列类型

2016-05-13 19:02 465 查看
declare c_sql cursor for
SELECT sql = 'alter table [' + d.name + '] alter column [' + a.name +
'] datetime' --** 修改为什么属性
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 = 'date' --**  这里是要修改的属性
and not exists
(SELECT 1
FROM sysobjects
where xtype = 'PK'
and name in (SELECT name
FROM sysindexes
WHERE indid in (SELECT indid
FROM sysindexkeys
WHERE id = a.id
AND colid = a.colid))) --** 排除主键修改
order by d.name, a.name

declare @sql varchar(1000)
open c_sql
fetch next from c_sql into @sql
while @@fetch_status = 0
begin
--select @sql
exec(@sql)
fetch next from c_sql into @sql
end
close c_sql
deallocate c_sql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: