欢迎光临
我们一直在努力

修改自定义数据类型精度-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

/*–修改自定义数据类型精度的示例

     自定义数据类型一旦被引用,就不能再修改和删除,如果要修改数据的精度,就非常麻烦,下面的示例演示了如何修改

     假设要修改的自定义变量名为aa

–*/

–1.修改自定义变量类型的名称
exec sp_rename aa,aa_bak,userdatatype
go

–2.新增自定义变量(按新的精度)
exec sp_addtype naa, nnumeric(20,2), nnot 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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 修改自定义数据类型精度-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章