Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a column after another column within SQL

Tags:

sql

How do I add a column after another column within MS SQL by using SQL query?

TempTable ID int, Type nvarchar(20), Active bit

NewTable ID int, Type nvarchar(20), Description text, Active bit

That is what I want, how do I do that

like image 970
mattgcon Avatar asked Nov 03 '10 03:11

mattgcon


People also ask

How add column after another column in SQL?

Syntax. The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ];

How do I add a column to the second position in SQL?

To add a column at a specific position within a table row, use FIRST or AFTER col_name . The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.

How do I add a column between two existing columns?

To insert a single column: Right-click the whole column to the right of where you want to add the new column, and then select Insert Columns. To insert multiple columns: Select the same number of columns to the right of where you want to add new ones. Right-click the selection, and then select Insert Columns.


1 Answers

Assuming MySQL (EDIT: posted before the SQL variant was supplied):

ALTER TABLE myTable ADD myNewColumn VARCHAR(255) AFTER myOtherColumn 

The AFTER keyword tells MySQL where to place the new column. You can also use FIRST to flag the new column as the first column in the table.

like image 134
Hamish Avatar answered Oct 03 '22 06:10

Hamish