Add a new table column to specific ordinal position in Microsoft SQL Server

后端 未结 9 971
北海茫月
北海茫月 2020-11-27 20:16

Is it possible to add a column to a table at a specific ordinal position in Microsoft SQL Server?

For instance, our tables always have CreatedOn, CreatedBy, LastModi

9条回答
  •  隐瞒了意图╮
    2020-11-27 20:45

    go into SQL Server management Studio, and "design" an existing table. Insert a column in the middle, right click in an empty area and select Generate Change Script...

    Now look at the script it creates. it will basically create a temp table with the proper column order, insert the data from the original table, drop the original table, and rename the temp table. This is probably what you'll need to do.

    You may also need to uncheck this option to allow creation of change scripts

提交回复
热议问题