add column between two column

  • I have a table having column1,column2,column3,column4

    Now I have to modify the table and add two new column column A, ColumnB in between Column1 & Column2.

    So new columns list will be column1,column A, ColumnB, column2,column3,column4

    How to achieve this using T-SQL?

  • bang.prashant (10/9/2008)


    I have a table having column1,column2,column3,column4

    Now I have to modify the table and add two new column column A, ColumnB in between Column1 & Column2.

    So new columns list will be column1,column A, ColumnB, column2,column3,column4

    How to achieve this using T-SQL?

    You can’t do it. If it is really important for you, you can drop the table and recreate it, but it shouldn’t be important at all. The logical order of the columns is not necessarily the same as the physical order of columns and since you should specify the columns that you want to select clause and not use *, the logical order of columns has no importance at all.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Not sure if this will help you here is a link to some information.

    http://blog.sqlauthority.com/2008/04/08/sql-server-change-order-of-column-in-database-tables/

    Respectfully,Kate SchwidSoftware Developer/Data AnalystOzaukee, WI

  • Sure you can do it. And, you don't have to write a lick of T-SQL to do it... Enterprise Manager will write all of the code for you.

    Open Enterprise Manager and go into design the table. Make the changes that you want including the inserted columns and then click on the 3rd menu icon from the left (Save Change Script). Follow your nose after that.

    Now, SHOULD you do it? That's a whole 'nuther story... 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply