1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Reordering of fields in phpMyAdmin

Discussion in 'MySQL' started by Araneum, May 3, 2008.

  1. #1
    Hi

    I have a large table of information that I want to import into another table with a different field order.

    I can´t see anywhere in PHPMyAdmin to change the field order.

    Does anyone know how I could do this, or maybe of a free database app for my pc which will allow me to import the records, change and insert the fields before exporting a mysql dump.

    Any ideas very much appreciated.
     
    Araneum, May 3, 2008 IP
  2. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You could try the following (not tested):

    1) Export structure only.
    2) Edit structure file and re-order fields.
    3) Export the data with "Complete inserts" Option.
    4) Import edited table structure.
    5) Import data.
     
    Kuldeep1952, May 3, 2008 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    As long as the fields are the same name and type the order does not matter so long as you export and then import it. The proper information will be inserted into the correct table.

    There is one additional important step. After you export the file open it in a text editor like notepad2 and use the replace all function to replace the old database name with the new database name.

    If there is a way to re-order the fields using phpmyadmin I never found it.

    First time doing this, I would suggest you work with copies of the DB on both ends to cover your tushey.
     
    Colbyt, May 3, 2008 IP
  4. Araneum

    Araneum Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #4
    I´ll give it a try

    Thanks :)
     
    Araneum, May 3, 2008 IP
  5. Araneum

    Araneum Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #5
    Hi

    Surely when you are using the import its not the names but the order of the fields that matters as its using the INSERT command e.g

    INSERT INTO `table_name` VALUES (1,'Bob wilson','etc.');
     
    Araneum, May 3, 2008 IP
  6. Araneum

    Araneum Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #6
    Hi

    Think I´ve found a solution

    I´ve downloaded Navicat 8 for MySQL and that allows you to connect remotely with your host and change field order. :)
     
    Araneum, May 4, 2008 IP
  7. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #7
    Why you need to re-order the fields? You can SELECT them in any order you want...
     
    mwasif, May 4, 2008 IP
  8. Araneum

    Araneum Active Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #8
    Hi

    Depends if you are doing the import/ export route, or using sql queries.

    For the Import/Export you need to have the records in the right order. e.g.

    INSERT INTO `table_name` VALUES (1,'Bob wilson','etc.');

    If you are doing a SQL query you can do as you say. The reason I wanted to use a app which allowed me to change the order of the fields is that my SQL is very rusty and with Navicat it allowed me to make all the changes to the table and then just do a simple

    INSERT INTO `newtable` SELECT * FROM `original table`; and it was all there. ;-)
     
    Araneum, May 4, 2008 IP
  9. MattC1983

    MattC1983 Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I think you should be able to do the following:

    CREATE TABLE *TABLE NAME* AS (

    SELECT column 1, column 5, column 2, column4, column3 from table

    )

    ?
     
    MattC1983, May 4, 2008 IP
  10. belabacsi

    belabacsi Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    reordering fields using sql:

    ALTER TABLE table_name MODIFY col_name original_column_definition [FIRST|AFTER col_name]
     
    belabacsi, Aug 12, 2010 IP
  11. siliconrockstar

    siliconrockstar Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I like PHPMyAdmin for quick changes but for reordering fields use MySQL Workbench. It's free and is substantially more capable. MySQL Workbench is to PHPMyAdmin what Eclipse IDE is to Notepad (ok, that's an exaggeration, but you get my drift) :) The best benefit I've found is that you can completely diagram your database and then export the SQL to actually create it.
     
    siliconrockstar, Jul 18, 2012 IP