HELP: SQL Data File Help needed

Discussion in 'Programming' started by jl255, Aug 13, 2009.

  1. #1
    I have a data file .sql with a whole long list of commands like INSERT INTO XXX ("id","field1","field2")...

    But my database has field1 and field2 switched in positions. How can I change my SQL file so that ALL field1 and field2 are swapped?

    Is that possible?

    If not, how best can i import my sql file into my DB??

    Tks alot!
     
    jl255, Aug 13, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It might be better to insert the field definitions instead. For example The typical insert string goes as such

    INSERT INTO TABE ('id', 'field1', 'field2', 'field3') VALUES (1, 'value for field 1', 'value for field 2' ... )

    By inserting the bolded part you can define the order in which your values will be assigned. For reasons such as this is why its always best to export out to a complete insert instead of assuming the order will be the same as the data.
     
    kblessinggr, Aug 13, 2009 IP
    jl255 likes this.
  3. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    There is no need to swap the fieldnames since the INSERT will work fine regardless to actual field order used in table definition..
     
    stOK, Aug 13, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Incorrect.

    If he's using an Insert statement such as

    INSERT INTO TABLE ('field values'...);

    and not

    INSERT INTO TABLE ('field names', ...) VALUES ('field values', ...);

    And for some reason in his new database structure the fields are not in the same order, that WILL be a problem.
     
    kblessinggr, Aug 13, 2009 IP
  5. jl255

    jl255 Well-Known Member

    Messages:
    2,762
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    185
    #5
    tks alot kblessinggr... think u r right and it works :)
     
    jl255, Aug 14, 2009 IP