tags:

views:

661

answers:

3

Good day,

When we add a column to a table, it gets added to the end of the table. However, I really need to add a column to the beginning of the table. The reason is that we have scripts that import data from a flat file source to a table, and that it would be really easier for us to have the columns at the beginning to the table.

Thank you!

sql server 2005

A: 

Drop and re-create the table with the new structure. (Or rename existing, create new, and insert data)

There is no ALTER statement you can run that will insert it at the beginning.

Even if you use the SQL 2005 Management Studio, and you insert a column at the beginning, that's what it is doing behind the scenes when you click Save. (rename the original table, create the new table, insert the data)

BradC
+4  A: 

I already answered this question: add-a-new-table-column-to-specific-ordinal-position

Jose Basilio
+3  A: 

GUI method: in SQL Server Management Studio if you right click the table and choose "Design" you can then drag the column up to the top and hit save.

BarrettJ
Superb, thank you!
Cedric Aube
Be aware that doing this effectively drops the old table and creates/populates a new table in its place. I really wouldn't recommend this for large tables, although it's your only option if the new column absolutely has to be at the beginning.
LukeH