Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a best practice to database column ordering?

Are there any best practices to column ordering when designing a database? Will order effect performance, space, or the ORM layer?

I am aware of SQL Server - Does column order matter?. I am looking for more general advice.

like image 253
James McMahon Avatar asked Apr 21 '09 15:04

James McMahon


People also ask

Does database column order matter?

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 column order matter in SQL select?

Column Order Does Make A Difference Clearly and immediately, performance degrades as we SELECT a column other than the first column. But to satisfy any naysayers, below you can find the statistical significance test between column one and column two.

Does the order of table creation matter in SQL?

create all table, only structure (fields), without any Primary Keys nor Foreign Key, without any Index, the order doesn't matter.


1 Answers

I don't believe that the column order will necessarily affect performance nor space. To improve performance, you can create indexes on the table, and the order of the columns defined in the index will effect performance.

I've seen tables have their fields ordered alphabetically, as well as "logically" (in a way that makes sense for the data that is being represented). All in all, I can see benefits in both, but I would tend to go for the "logically" method.

like image 141
CodeMonkey1313 Avatar answered Oct 10 '22 07:10

CodeMonkey1313