#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Error 1062 Duplicate PK for every record


    Hey all,
    I am using MySQL Browser to run a creation script. Bellow is an excerpt. When I run the script I get an error for every entry stating that there was a Duplicate entry 1 for Key 1 followed by Duplicate entry 2 for Key 1 and so on. It does this for every record. I have stopped the script and looked at what is in the table at that point and nothing other than what was recently created is in there. I have manually dropped the tables too but that doesn't seem to help. Any help would be greatly appreciated.




    Code:
    DROP TABLE IF EXISTS `tblAnswers`;
    
    CREATE TABLE `tblAnswers` (
      `answID` INTEGER NOT NULL AUTO_INCREMENT, 
      `Cat` VARCHAR(255), 
      `answText` VARCHAR(255), 
      `answValue` INTEGER, 
      PRIMARY KEY (`answID`)
    ) ENGINE=myisam DEFAULT CHARSET=utf8;
    
    SET autocommit=1;
    
    #
    # Dumping data for table 'tblAnswers'
    #
    
    INSERT INTO `tblAnswers` (`answID`, `Cat`, `answText`, `answValue`) VALUES (1, 'Connectivity', 'Existing DSL provisioned hardline', NULL);
    INSERT INTO `tblAnswers` (`answID`, `Cat`, `answText`, `answValue`) VALUES (2, 'Connectivity', 'Strong 3G connectivity', NULL);
    INSERT INTO `tblAnswers` (`answID`, `Cat`, `answText`, `answValue`) VALUES (3, 'Connectivity', 'Close to hardline distribution', NULL);
    INSERT INTO `tblAnswers` (`answID`, `Cat`, `answText`, `answValue`) VALUES (4, 'Connectivity', 'Hardline possible, but not economical', NULL);
    INSERT INTO `tblAnswers` (`answID`, `Cat`, `answText`, `answValue`) VALUES (5, 'Connectivity', 'Weak 3g connectivity', NULL);
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,146
    Rep Power
    4274
    is that the actual script there? that's all?

    because that script works just fine
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by r937
    is that the actual script there? that's all?

    because that script works just fine
    Yes that is from the actual script and I am getting an error for each line it enters. It does indeed make the entry, but it gives an error. Strange.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Is it a conflict between specifying the answID values and the column being defined as AUTO_INCREMENT?
    What does the following do when run against an empty table?:
    Code:
    INSERT INTO `tblAnswers` (`Cat`, `answText`, `answValue`) VALUES ('Connectivity', 'Existing DSL provisioned hardline', NULL);
    INSERT INTO `tblAnswers` (`Cat`, `answText`, `answValue`) VALUES ('Connectivity', 'Strong 3G connectivity', NULL);
    INSERT INTO `tblAnswers` (`Cat`, `answText`, `answValue`) VALUES ('Connectivity', 'Close to hardline distribution', NULL);
    INSERT INTO `tblAnswers` (`Cat`, `answText`, `answValue`) VALUES ('Connectivity', 'Hardline possible, but not economical', NULL);
    INSERT INTO `tblAnswers` (`Cat`, `answText`, `answValue`) VALUES ('Connectivity', 'Weak 3g connectivity', NULL);
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo