SQL Server - Does column order matter?

后端 未结 6 842
陌清茗
陌清茗 2020-12-03 21:00

In terms of performance and optimizations:

  • When constructing a table in SQL Server, does it matter what order I put the columns in?
  • Does it matter if
6条回答
  •  温柔的废话
    2020-12-03 21:15

    For the fourth bullet: No you can't specify where you want to add the column. Here is the syntax for ALTER TABLE: https://msdn.microsoft.com/en-us/library/ms190273.aspx

    In MySQL they offer an ALTER TABLE ADD ... AFTER ... but this doesn't appear in T-SQL.

    If you want to reorder the columns you'll have to rebuild the table.

    Edit: For your last last bullet point, you'll have to DROP the table and recreate it to reorder the columns. Some graphical tools that manipulate SQL databases will do this for you and make it look like you're reordering columns, so you might want to look into that.

提交回复
热议问题