⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 自定义数据类型精度.sql

📁 很好的sql 文档,可能邦你成为sql 高手
💻 SQL
字号:
/*--修改自定义数据类型精度的示例

	假设要修改的自定义变量名为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' and objectproperty(a.id,N'IsUserTable')=1
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
go

--刷新视图
declare hCForEach cursor global for 
select '[' + REPLACE(user_name(uid), N']', N']]')+'].['
	+ REPLACE(object_name(id), N']', N']]')+ ']' 
from dbo.sysobjects
where xtype='V' and status>=0

exec sp_MSforeach_worker 'sp_refreshview ''?'''

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -