Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Location
    Los Angeles, CA
    Posts
    2

    Unanswered: Changing Field positions in an existing table

    I was wondering if there was a way to easily order the fields of a table that display from a "SHOW COLUMNS FROM table_name".

    I assumed this might be possible with an "ALTER TABLE table_name MODIFY ..." command but I haven't been able to get anything to work. I noticed there is syntax for "ALTER TABLE MODIFY" that could prove useful (FIRST | BEFORE | AFTER) but on all my attempts I couldn't get anything to work.

    I know I could go around all this by just dumping my table and re-creating it with the field orders I intended but I figured MySQL had an easier way I could do this with a few simple commands.

    Thanks in advance...

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Use something as simple as
    Code:
    ALTER table tablename MODIFY foo int AFTER bar;
    you need the int (or char or char(15) or whatever) for the columntype after the first column so the database knows what type of data is stored in the column.

  3. #3
    Join Date
    May 2004
    Location
    Los Angeles, CA
    Posts
    2
    I don't know what is up but MySQL sends me an error 1064 message for 'AFTER bar' using the example above. Does anyone else experience this?

  4. #4
    Join Date
    Mar 2004
    Posts
    480
    What version of mysql are you using? I can't think that it should matter but I think 1064 errors crop up when you are using a version of mysql that isn't compatible with the code you are attempting (such as using a subquery before 4.1 or whatever version it starts with). Rudy or Pat can you clarify if I am right with this line of thinking?

  5. #5
    Join Date
    Aug 2003
    Posts
    328
    Download the GUI from here and it does it for you.
    http://www.mysqlfront.de/

Posting Permissions

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