How to change column order in a table using sql query in sql server 2005?

Himadri picture Himadri · Oct 22, 2009 · Viewed 282.3k times · Source

How to change column order in a table using SQL query in SQL Server 2005?

I want to rearrange column order in a table using SQL query.

Answer

marc_s picture marc_s · Oct 22, 2009

You cannot. The column order is just a "cosmetic" thing we humans care about - to SQL Server, it's almost always absolutely irrelevant.

What SQL Server Management Studio does in the background when you change column order there is recreating the table from scratch with a new CREATE TABLE command, copying over the data from the old table, and then dropping it.

There is no SQL command to define the column ordering.