Altering user-defined table types in SQL Server

前端 未结 7 1520
心在旅途
心在旅途 2020-12-13 12:06

How can I alter a user-defined table type in SQL Server ?

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 12:21

    Here are simple steps that minimize tedium and don't require error-prone semi-automated scripts or pricey tools.

    Keep in mind that you can generate DROP/CREATE statements for multiple objects from the Object Explorer Details window (when generated this way, DROP and CREATE scripts are grouped, which makes it easy to insert logic between Drop and Create actions):

    1. Back up you database in case anything goes wrong!
    2. Automatically generate the DROP/CREATE statements for all dependencies (or generate for all "Programmability" objects to eliminate the tedium of finding dependencies).
    3. Between the DROP and CREATE [dependencies] statements (after all DROP, before all CREATE), insert generated DROP/CREATE [table type] statements, making the changes you need with CREATE TYPE.
    4. Run the script, which drops all dependencies/UDTTs and then recreates [UDTTs with alterations]/dependencies.

    If you have smaller projects where it might make sense to change the infrastructure architecture, consider eliminating user-defined table types. Entity Framework and similar tools allow you to move most, if not all, of your data logic to your code base where it's easier to maintain.

提交回复
热议问题