Meena
Meena

Reputation: 1

Sql query for alter Table

I'm trying to alter a table and add a column at position which is after an existing column, but I can't make it since getting the following

error:

Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'AFTER'.

and the query I used is:

ALTER TABLE DealerGroup
ADD Status varchar(50)
AFTER Description;

Upvotes: 0

Views: 61

Answers (3)

Shubhit304
Shubhit304

Reputation: 301

You cannot add the column after specified column because in database structure column order doesn't matter when you need to fetch the data, and also AFTER is not any keyword defined in it in case of alter table query. OR if you still want to, then you have to drop the table and re-create it with required column ordering.

Upvotes: 0

Radu Gheorghiu
Radu Gheorghiu

Reputation: 20489

You can't add a column to a specific position in a table. Actually the RDBMS (SQL Server in this case) doesn't care where a column resides in the order of a table.

When you add another column to a table, it always goes "last".

Upvotes: 0

jpw
jpw

Reputation: 44871

Microsoft SQL Server does not support the after part, which I believe is specific to MySQL.

In any case the internal ordering of columns should not matter to you, unless you rely on getting an ordered result when doing select * which you shouldn't do anyway.

Upvotes: 1

Related Questions