LogIn
I don't have account.

How can I add new column between two existing columns in sql table?

I have a table student with columns
Id | Name | Collage
I want to add a new column name age in between Name and Collage .
how can I do this?

Please pay attention to update your answer.

Update Your Answer care fully. After saving you can not recover your old answer

Carefully Update Your Answer!!

Adding a Column Between Two Existing Columns in SQL (All Databases)

 If you want to add a new column Age between Name and Collage.
Below is how it works across different SQL databases

MySQL

Supports adding a column in a specific position using AFTER:

ALTER TABLE student
ADD COLUMN Age INT AFTER Name;

 

 PostgreSQL

Does not support changing the physical column order.
You can only add a column at the end:

ALTER TABLE student
ADD COLUMN Age INT;

If you want to see it between Name and Collage, specify the order in your SELECT:

SELECT Id, Name, Age, Collage FROM student;

 

SQL Server

Same as PostgreSQL :- column order cannot be changed directly.

ALTER TABLE student
ADD Age INT;

To reorder columns, you’d need to:

  1. Create a new table with the desired column order.
  2. Copy data into it.
  3. Rename the new table.

Or just reorder in queries:

SELECT Id, Name, Age, Collage FROM student;

 

Oracle

It also does not allow adding a column at a specific position.

ALTER TABLE student
ADD (Age NUMBER);

To reorder columns:

  • Use CREATE TABLE AS SELECT with desired column order:
CREATE TABLE student_new AS SELECT Id, Name, NULL AS Age, Collage FROM student;

Please pay attention to update your answer.

Update Your Answer care fully. After saving you can not recover your old answer

Carefully Update Your Answer!!

You can add a new column between two existing columns in SQL using the AFTER clause (supported in MySQL).
Here’s the correct SQL command for your case:

ALTER TABLE student
ADD COLUMN Age INT AFTER Name;

Please pay attention to update your answer.

Update Your Answer care fully. After saving you can not recover your old answer

Carefully Update Your Answer!!

MySQL

Supports column positioning

ALTER TABLE student ADD COLUMN Age INT AFTER Name;

 

PostgreSQL

 Cannot reorder columns

ALTER TABLE student ADD COLUMN Age INT;
-- Use SELECT to control order 
SELECT Id, Name, Age, Collage FROM student;

 

SQL Server

 Cannot reorder directly

ALTER TABLE student ADD Age INT;
-- Reorder in query or recreate table 
SELECT Id, Name, Age, Collage FROM student;

 

 Oracle

Cannot reorder directly

ALTER TABLE student ADD (Age NUMBER);
-- Or recreate table for new order 
CREATE TABLE student_new AS SELECT Id, Name, NULL AS Age, Collage FROM student;