Please pay attention to update your answer.
Update Your Answer care fully. After saving you can not recover your old 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:
- Create a new table with the desired column order.
- Copy data into it.
- 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 SELECTwith 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
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
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;