Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002

    Unanswered: How to change column order of a table


    I need to modify column order of some of my sql server 2k tables
    because i want to keep related columns together. How can i do this?


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    create a view with the columns in the order you want


  3. #3
    Join Date
    Mar 2003
    Indiana, USA

    Thumbs down


    If you really need to do it.

    create an new table as you want the columns to be.

    Copy the data into it.

    rename the old table to a different name.

    rename the new table to the old name.

    Fix all the Foreign keys to point to the correct table.

    and pray it works!!!

    I would suggest getting an book on SQL design because there is normaly no good reason to change the column order of the table.

    Tim S

  4. #4
    Join Date
    Mar 2003
    Bucharest, Romania

    Re: How to change column order of a table

    It's very simple use Enterprise Manager -> Tables _> Design Table -> and use drag and drop to move one column in the position you want (it' necessary to select the row of the column in order for drag and drop to function)

    Beware, this only can be done in SQL Server 2k not in any previous versions of SQL Server.

    Anyway to move a column has a meaning only for a better visualisation of the table design, because the order of columns, or the phisical order of rows in the table has no importance (it's a base rule of relational database).
    But, if you decide to move one column before another, you can do it nothing is going to change within your application.

    In fact, there is one problem in SQL 2k. If you are changing the position of a column and for that table you have a trriger that use the function COLUMNS_UPDATED(n) (where n is the no of a row in the table) and after your switching positions of columns the positin of the column implied in COLUMN_UPDATED function changes you should modify your trriger in order to work corectly.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts