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

Cedric Aube
  • 345
  • 4
  • 6
  • 13

4 Answers4

8
ALTER TABLE table_name ADD COLUMN column_name FIRST;
Bernie
  • 97
  • 1
  • 1
4

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.

Note: Be aware that by doing this, SQL Server drops the table and creates it again. You won't lose your data though.

FLICKER
  • 6,439
  • 4
  • 45
  • 75
BarrettJ
  • 3,431
  • 2
  • 29
  • 26
  • 2
    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 Apr 25 '09 at 00:06
  • Old thread, but in case this bites anyone else: Go to Tools/Options/Designers/"Table and Database Designers" and increase your "Transaction time-out after:" value before you try this on a large table. – amonroejj Jun 19 '17 at 18:37
0

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
  • 39,306
  • 13
  • 73
  • 89
-1

Answers to your question is in the link below!

http://www.tech-recipes.com/rx/378/add-a-column-to-an-existing-mysql-table/

  • 1
    Welcome to Stack Overflow! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Shawn Chin May 16 '12 at 14:16