Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of columns in the table matter?

Tags:

sql-server

We have a number of projects big and small - most (if not all) of them use at least one SQL Server DB. All of them have different environments set up. Typically: dev (1+), QA, UAT, Live. It is also common for us to release various code updates to different environments independently of each other. Naturally some of those updates come with schema update scripts such as

alter table foo add column bar
go
update foo set bar=... where ...

Sometimes made by hand, other times using Red Gate SQL/Data Compare.

Anyway where I'm going with this is that often different environments for the same project end up with different order of columns. Is this a problem? I don't really know... Does column order have any performance implications? Anything I could be missing?

like image 537
Ilia G Avatar asked Dec 15 '10 18:12

Ilia G


People also ask

Does the order of columns matter in a relation?

In a relation, the order of the columns does not matter.

Does the order of table matter?

Generally, no, the order of the tables in the JOIN will not affect the overall results of the query. As long as you specify what columns to select, the results should appear essentially the same, just that the rows will be ordered according to the appearance in the first table.

Does SQL order matter?

No, the order of the WHERE clauses does not matter. The optimizer reviews the query & determines the best means of getting the data based on indexes and such.


1 Answers

No, column order is not significant. In actuality, the order that column data is stored on disk may itself be different than the order you see in client tools, as the engine reorders the data to optimize storage space and read/write performance (putting multiple bit fields into a single memory location, aligning columns on memory boundaries, etc.. )

like image 62
Charles Bretana Avatar answered Sep 27 '22 17:09

Charles Bretana