Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 938
Aayushi Avatar asked Jan 19 '11 06:01

Aayushi


People also ask

How do you add a new column to an existing column in SQL?

In Microsoft SQL Server, we can change the order of the columns and can add a new column by using ALTER command. ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.


1 Answers

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 
like image 175
Brad Christie Avatar answered Sep 24 '22 12:09

Brad Christie