Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Does column order matter?

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 my primary key is the first column?
  • When constructing a multi-field index, does it matter if the columns are adjacent?
  • Using ALTER TABLE syntax, is it possible to specify in what position I want to add a column?
    • If not, how can I move a column to a difference position?
like image 516
Seibar Avatar asked Aug 29 '08 17:08

Seibar


People also ask

Does column order matter in table?

OK, for years I've been saying that SQL Server doesn't care about the order in which you define the columns of your table because internally SQL Server will re-arrange your columns to store all of the fixed width columns first and the variable columns last.

Does the order of columns in update statements matter?

Answer is NO. There is no difference between them in SQL Server.

Does order in table matter in SQL?

Basically, no matter how we try to redefine the order of our tables in the FROM statement, SQL Server will still do what it thinks it's best.

Are SQL columns ordered?

as per SQL standard, the columns in a table are not "ordered"


1 Answers

In SQL Server 2005, placement of nullable variable length columns has a space impact - placing nullable variable size columns at the end of the definition can result in less space consumption.

SQL Server 2008 adds the "SPARSE" column feature which negates this difference.

See here.

like image 71
Aidan Ryan Avatar answered Sep 20 '22 09:09

Aidan Ryan