How to add a column in TSQL after a specific column?

Justin808 picture Justin808 · Oct 28, 2011 · Viewed 102.6k times · Source

I have a table:

MyTable
    ID
    FieldA
    FieldB

I want to alter the table and add a column so it looks like:

MyTable
    ID
    NewField
    FieldA
    FieldB

In MySQL I would so a:

ALTER TABLE MyTable ADD COLUMN NewField int NULL AFTER ID;

One line, nice, simple, works great. How do I do this in Microsoft's world?

Answer

Mike M. picture Mike M. · Oct 28, 2011

Unfortunately you can't.

If you really want them in that order you'll have to create a new table with the columns in that order and copy data. Or rename columns etc. There is no easy way.