批量修改数据库中字段的数据类型
来源:互联网 发布:淘宝同学官网 编辑:程序博客网 时间:2024/05/16 05:36
在有些时候,需要将某种数据类型的字段,修改为另一种数据类型,可使用下列脚本实现;例如:原来定义为decimal(18,2)类型的所有统一修改为decimal(19,4)。
– 关闭 约束
declare tb cursor for
SELECT sql=’alter table [‘+d.name+’] NOCHECK CONSTRAINT all’
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’) GROUP BY d.name
declare @sql1 varchar(1000)
open tb
fetch next from tb into @sql1
while @@fetch_status = 0
begin
print @sql1
exec(@SQL1)
fetch next from tb into @sql1
end
close tb
deallocate tb
-- 修改字段数据类型
declare tb cursor for
SELECT sql=’alter table [‘+d.name+’] alter column [‘+a.name+’] decimal(19,4)’
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 @sql2 varchar(1000)
open tb
fetch next from tb into @sql2
while @@fetch_status = 0
begin
print @sql2
exec(@SQL2)
fetch next from tb into @sql2
end
close tb
deallocate tb
-- 恢复 约束
declare tb cursor for
SELECT sql=’alter table [‘+d.name+’] CHECK CONSTRAINT ALL’
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’) GROUP BY d.name
declare @sql3 varchar(1000)
open tb
fetch next from tb into @sql3
while @@fetch_status = 0
begin
print @sql3
exec(@SQL3)
fetch next from tb into @sql3
end
close tb
deallocate tb
- 批量修改数据库中字段的数据类型
- SQL SERVER 批量修改字段的数据类型
- 批量修改同一个字段的数据类型
- 批量修改oracle数据库中sdo_geometry字段的SRID
- 数据库迁移之pdm-数据库数据类型的批量修改
- sql server数据库的表中修改一个表的字段的数据类型后,不能保存
- SQL SERVER 2008数据库的表中修改字段的数据类型后,不能保存
- SQL SERVER 2008数据库的表中修改字段的数据类型后,不能保存
- SQL Server 2008数据库表中修改字段的数据类型后,不能保存
- 批量替换数据库中所有用户数据表中字段数据类型为char和varchar到nvarchar的脚本
- 批量修改数据库某个字段的某些字符
- 批量修改系统中int,varchar字段的默认值
- 批量修改系统中int,varchar字段的默认值
- 批量修改系统中int,varchar字段的默认值
- 批量修改数据库某字段内容
- 批量修改SQL数据库字段值
- 批量修改数据库字段类型(ORACLE)
- 修改字段数据类型的方法
- 自动重命名Terminal的Title
- expect一些资料
- java中MD5和SHA加密
- Android 微信主页面
- JavaScript数组过滤相同元素
- 批量修改数据库中字段的数据类型
- spring-data-jpa 中文文档(2)
- I2C总线学习之二
- nyoj_41 三个数从小到大排序
- pthread_detach解析
- 111111111111111111
- solr5安装实践
- ios 图片拉伸
- SQL Server 批量插入数据的两种方法