Any easier way for duplicated keys.

Discussion in 'MySQL' started by q8uwait, Oct 18, 2007.

  1. #1
    I have a game sql so i can import games.

    I have more than 3000 inserts in the sql.

    I have splitted the file and started to import then.

    however i sometimes get the error that there is a duplicate key.

    the i have to remove the key from the sql file and import it again. then it stops at another duplicate key.. etc

    what can i add to the sql file to skip the duplicated keys ??

    all insert keys are like that.

    INSERT INTO `games` (`gId` ,`gInCategory` ,`gSwfFile` ,`gName` ,`gOrder` ,`gVisible` ,`gThumb` ,`gWidth` ,`gHeight` ,`gDescription` ,`gplays` ,`description2` ,`sponsor_name` ,`sponsor_link`) VALUES (2376,106,'f-147.swf','Track and Field',0,1,'f-147.png',508,440,'Old school classic nintendo game play different olympic sports hurdles fencing and more.',0,'','',''); 
    Code (markup):
    any help would be appriciated

    thanks
     
    q8uwait, Oct 18, 2007 IP
  2. benajnim

    benajnim Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe there are some records in the table from an earlier attempt that are throwing things off?

    You can remove the constraints (unique constraint) from the gId column.
    Once the import is completed you will want to renumber all your rows, or determine which rows are duplicates and give them a new id number.

    Then you should be able to readd the constraints.
     
    benajnim, Oct 18, 2007 IP
  3. q8uwait

    q8uwait Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Any other way, where I can edit the sql file to add to the insert line to skip values if it is duplicated
     
    q8uwait, Oct 18, 2007 IP
  4. bluegrass special

    bluegrass special Peon

    Messages:
    790
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure this will work in MySQL:

    If not exists select * from games where gID = value
    Insert....
     
    bluegrass special, Oct 18, 2007 IP
  5. moodswing

    moodswing Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    post the errors here and I can help you with it.
    or try this ALTER TABLE `games` DROP PRIMARY KEY
     
    moodswing, Oct 20, 2007 IP
  6. upl8t

    upl8t Peon

    Messages:
    80
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    INSERT IGNORE ....

    By putting the IGNORE after the insert statement it will simply ignore duplicate key conflicts.
     
    upl8t, Oct 22, 2007 IP