我在设计数据库时使用了自定义数据类型,由于现在修改了编码规则,需要重新定义此数据类型的长度,但自定义数据类型使用后就不能修改了,也不能删除,请问如何才能重新定义自定义数据类型?
---------------------------------------------------------------
drop proc proc_type
go
create proc proc_type (
@selftype varchar(256),
@systype varchar(256),
@isnull varchar(8)=''
)as
begin
set nocount on
declare @tablename varchar(256)
declare @columnname varchar(256)
declare @sqlstr1 varchar(8000)
declare @sqlstr2 varchar(8000)
declare @sqlstr3 varchar(8000)
declare @sqlstr4 varchar(8000)
select @sqlstr1=''
select @sqlstr2=''
declare my_cursor cursor for
select c.name ,a.name from syscolumns a ,systypes b ,sysobjects c where b.name =@selftype and a.xusertype=b.xusertype and a.id=c.id
open my_cursor
fetch next from my_cursor
into @tablename,@columnname
if @@fetch_status =0
begin
while @@fetch_status = 0
begin
select @sqlstr1 = @sqlstr1 + ' alter table ' + @tablename + ' alter column ' + @columnname + ' '+ @systype + ' ' + @isnull
select @sqlstr2 = @sqlstr2 + ' alter table ' +@tablename + ' alter column ' + @columnname + ' '+ @selftype + ' '
fetch next from my_cursor
into @tablename,@columnname
end
select @sqlstr3='sp_droptype ' + '''' + @selftype + ''''
select @sqlstr4='sp_addtype ' + '''' + @selftype + '''' + ',' + '''' + @systype + '''' + ',' + '''' + @isnull + ''''
print @sqlstr1
print @sqlstr2
print @sqlstr3
print @sqlstr4
exec(@sqlstr1)
exec(@sqlstr3)
exec(@sqlstr4)
exec(@sqlstr2)
end
close my_cursor
deallocate my_cursor
set nocount off
end
go
proc_type 'tel','varchar(80)','null'