自定义数据类型一旦被引用,就不能再修改和删除,假如要修改数据的精度,就很麻烦,下面的示例演示了如何修改
假设要修改的自定义变量名为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
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




