Results 1 to 5 of 5

Thread: MySQL ALTER TABLE Query

  1. #1
    Join Date
    Mar 2003
    Location
    manchester
    Posts
    2

    MySQL ALTER TABLE Query

    Hiya!

    Hopefully this is a nice easy one. I'm trying to add a new column to a table. Not difficult. But I want to insert it in a specific position in the table. I can't find a simple way to do this - but there MUST be one, right?

    Cheers

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    New column added with ALTER statement always gets added at the end. Only way to put it in the middle is recreate the table.

  3. #3
    Join Date
    Mar 2003
    Location
    manchester
    Posts
    2
    thanks. so I can make a temporary table containing all my original columns PLUS the new columns inserted in the correct positions. is there an easy way to copy the contents of the old table into the correct columns in the new table? some form of JOIN statement perhaps...? obviously I can do this with a simple script but I have quite a lot of columns and if there's an automated method that'd be much easier...
    Last edited by el_numptio; 03-24-2003 at 09:41 AM.

  4. #4
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    No, you can add a column wherever you want. Use something like:
    ALTER TABLE t ADD f2 TINYINT NOT NULL AFTER f1;

  5. #5
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145

    Lightbulb GUI Alternative

    Or use phpMyAdmin

    Cheers

Posting Permissions

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