Alter user defined type in SQL Server

后端 未结 10 1134
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 19:47

I created few user defined types in my database as below

CREATE TYPE [dbo].[StringID] FROM [nvarchar](20) NOT NULL

and assigned them to vario

10条回答
  •  时光说笑
    2020-12-02 20:31

    This is what I normally use, albeit a bit manual:

    /* Add a 'temporary' UDDT with the new definition */ 
    exec sp_addtype t_myudt_tmp, 'numeric(18,5)', NULL 
    
    
    /* Build a command to alter all the existing columns - cut and 
    ** paste the output, then run it */ 
    select 'alter table dbo.' + TABLE_NAME + 
           ' alter column ' + COLUMN_NAME + ' t_myudt_tmp' 
    from INFORMATION_SCHEMA.COLUMNS 
    where DOMAIN_NAME = 't_myudt' 
    
    /* Remove the old UDDT */ 
    exec sp_droptype t_mydut
    
    
    /* Rename the 'temporary' UDDT to the correct name */ 
    exec sp_rename 't_myudt_tmp', 't_myudt', 'USERDATATYPE' 
    

提交回复
热议问题