Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013

    Question Unanswered: ADD multiple columns AFTER a specific column using one query

    Hello everyone, i am new in this website and MySQL and i'm loving it

    I need to add a set of columns to a table, but i need to add them after a specific column, can this be done in one query without having to specify AFTER for each column like this?

    ALTER TABLE details
    ADD address VARCHAR(255) AFTER name,
    ADD city VARCHAR(255) AFTER address,
    ADD state VARCHAR(255) AFTER city,

    Thanks in advance!

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    the order of columns in a table has no intrinsicilly importance.
    logically it its 'nice' to have the PK the first column(s), but its not required.

    the order of columns in a query is determined by the order the columns appear in the column specification (unless you are using SELECT *
    SELECT my2ndColumn, My4thColumn, My3rdColumn, My1stColumn FROM MyTable

    again the column order is irrelevant (unless say you are using an order by clause in whcih case I guess it makes sense to place the sorted columns in order at the front of the column list, but thats only if you are viewing query results in a query browser as opposed to consuming the data in an application, where the application front end handles the actual display of the query results.

    I guess the smart alexk response would be to design your tables fully AND properly first time around
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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