SQL SERVER示例:修改自定义数据类型精度
2016-01-16 14:15
375 查看
/*--修改自定义数据类型精度的示例
自定义数据类型一旦被引用,就不能再修改和删除,如果要修改数据的精度,就非常麻烦,下面的示例演示了如何修改
假设要修改的自定义变量名为aa
--*/
--1.修改自定义变量类型的名称
exec sp_rename 'aa','aa_bak','USERDATATYPE'
go
--2.新增自定义变量(按新的精度)
EXEC sp_addtype N'aa', N'numeric(20,2)', N'not null'
go
--3.修改表,使用新增的自定义变量
declare @s varchar(8000)
declare tb cursor local
for select 'alter table ['+object_name(a.id)+'] alter column ['
+a.name+'] aa'
from syscolumns a join systypes b on a.xusertype=b.xusertype
where b.name='aa_bak'
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
自定义数据类型一旦被引用,就不能再修改和删除,如果要修改数据的精度,就非常麻烦,下面的示例演示了如何修改
假设要修改的自定义变量名为aa
--*/
--1.修改自定义变量类型的名称
exec sp_rename 'aa','aa_bak','USERDATATYPE'
go
--2.新增自定义变量(按新的精度)
EXEC sp_addtype N'aa', N'numeric(20,2)', N'not null'
go
--3.修改表,使用新增的自定义变量
declare @s varchar(8000)
declare tb cursor local
for select 'alter table ['+object_name(a.id)+'] alter column ['
+a.name+'] aa'
from syscolumns a join systypes b on a.xusertype=b.xusertype
where b.name='aa_bak'
open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
相关文章推荐
- SQL SERVER分页存储过程
- 手动编译安装mysql,报错没有libaio模块,
- sqlserver2008 存储过程使用表参数
- SQL SERVER 小技巧
- SQL Server中调用WebService的实例
- SQL SERVER代理作业删除失败问题
- SQL Server中行列转换 Pivot UnPivot
- SQLSERVER数据库管理员的专用连接DAC
- SQL数据库缓存
- SQL Server Management Studio自定义快捷键
- mysql select 语句用法
- Oracle - 数据库的实例、表空间、用户、表之间关系
- 使用plsql导入dmp文件缺少imp*.exe
- java对redis的基本操作
- Navicat 连接oracle解决方案之ORA-28547
- Redis的数据回写机制
- DAG中数据库的复制队列长度和重播队列长度的区别
- Java中使用Jedis操作Redis
- mysql ERROR 1045 (28000): Access denied for user解决
- Redis的Java客户端Jedis的八种调用方式(事务、管道、分布式)介绍