Alter user defined type in SQL Server

后端 未结 10 1117
没有蜡笔的小新
没有蜡笔的小新 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:29

    As devio says there is no way to simply edit a UDT if it's in use.

    A work-round through SMS that worked for me was to generate a create script and make the appropriate changes; rename the existing UDT; run the create script; recompile the related sprocs and drop the renamed version.

    0 讨论(0)
  • 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' 
    
    0 讨论(0)
  • 2020-12-02 20:33

    1.Rename the old UDT,
    2.Execute query , 3.Drop the old UDT.

    0 讨论(0)
  • 2020-12-02 20:44

    New answer to an old question:

    Visual Studio Database Projects handle the drop and recreate process when you deploy changes. It will drop stored procs that use UDDTs and then recreate them after dropping and recreating the data type.

    0 讨论(0)
提交回复
热议问题