SQL Server Management Studio - Adding/Moving Columns require drop and re-create?

前端 未结 5 1624
轻奢々
轻奢々 2021-02-04 03:47

Why do I get message that the table needs to dropped and re-created when I add/move columns? I believe this happens after adding foreign key constraints.

What can I do t

5条回答
  •  失恋的感觉
    2021-02-04 04:39

    SQL Server (and any other RDBMS, really) doesn't have any notion of "column order" - e.g. if you move columns around, the only way to achieve that new table structure is be issuing a new CREATE TABLE statement. You cannot order your columns any other way - nor should you, really, since in the relational theory, the order of the columns in a tuple is irrelevant.

    So the only thing SQL Server Management Studio can do (and has done all along) is:

    • rename the old table
    • create the new table in your new layout you wish to have
    • copy the data over from the old table
    • drop the old table

    The only way to get around this is:

    • not reordering any columns - only add new columns at the end of your table
    • use ALTER TABLE SQL statements instead of the interactive table designer for your work

提交回复
热议问题