Duplicating MySQL entries.

Discussion in 'PHP' started by Kyrus, Nov 27, 2008.

  1. #1
    Hello everyone.

    Anyone knows the best way to duplicate entries in a database? New ID but same data. Thanks.
     
    Kyrus, Nov 27, 2008 IP
  2. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You can use PHP to make your job faster.
    first of all, you must have MySQL connections opened,
    then read the datas that you want to copy and store them to some variables.
    and then do a sql query that will insert the new datas (use the variables you stored before) in a loop depends on the total of the IDs that you wanted to create. also use the iteration as the new ID to avoid ID duplication.
     
    djzmo, Nov 27, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    If you know all fields are unique, add uniques to the table and use INSERT INTO ... ON DUPLICATE KEY so you never have duplicate data!

    check out mysql for more info about ON DUPLICATE KEY and UNIQUE indexes!
     
    EricBruggema, Nov 28, 2008 IP