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

后端 未结 9 981
北海茫月
北海茫月 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:27

    You have to create a temp table that mirrors the original table's schema but with the column order that you want, then copy the contents of the original to temp. Delete the original and rename the temp.

    This is what SQL Management Studio does behind the scenes.

    With a schema sync tool, you can generate these scripts automatically.

提交回复
热议问题