SQL Query to add a new column after an existing column in SQL Server 2005

Aayushi picture Aayushi · Jan 19, 2011 · Viewed 211.5k times · Source

I need a SQL query which add a new column after an existing column, so the column will be added in a specific order.

Please suggest me if any ALTER query which do that.

Answer

Brad Christie picture Brad Christie · Jan 19, 2011

Microsoft SQL (AFAIK) does not allow you to alter the table and add a column after a specific column. Your best bet is using Sql Server Management Studio, or play around with either dropping and re-adding the table, or creating a new table and moving the data over manually. neither are very graceful.

MySQL does however:

ALTER TABLE mytable
ADD COLUMN  new_column <type>
AFTER       existing_column