NateHunt
NateHunt

Reputation: 153

#1062 - Duplicate entry '111' for key 'PRIMARY'

I am trying to import a DB in through phpMyAdmin and I'm having trouble with this particular error repeating itself even though I cannot find where the duplicate entry is.

I changed some of the values of the PKs to see what would happen ie I changed 13 to 111, 12 to 112. So even though I have changed the vlaue it's still seeing it as duplicate.

 SQL query:

--
-- Dumping data for table `gno_affiliates`
--
INSERT INTO  `gno_affiliates` (  `id` ,  `affiliate_name` ,  `affiliate_url` ) 
VALUES ( 111,  'Blackberry',  'http://www.blackberry.com' ) , ( 112,  'Android',      'http://www.android.com' ) , ( 12,  'I-Pod',  'http://www.I-Pod.com' ) , ( 14,  'Windows     Mobile',  'http://www.windowsmobile.com' ) , ( 15, 'Meego',  'http://www.meego.com' ) , (     16,  'Zombie Farm',  'http://itunes.apple.com/au/app/zombie-farm-2/id494655448?mt=8' ) ;


MySQL said: 

#1062 - Duplicate entry '111' for key 'PRIMARY' 

Here is the table code:

CREATE TABLE IF NOT EXISTS `gno_affiliates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `affiliate_name` varchar(255) NOT NULL,
  `affiliate_url` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;

Thanks.

EDIT:

Here is the result of the query cowls suggested: phpMyAdmin screenshot

As you can see there is only one entry for that id.

Upvotes: 3

Views: 3681

Answers (1)

cowls
cowls

Reputation: 24334

There must already be an entry for that key in the table.

Run this query before running the insert to check:

SELECT * FROM gno_affiliates WHERE id = 111

It is possible to run this on the command line, however I reccommend downloading a SQL client as this will make your life easier going forward. I reccommend SQLYog:

http://code.google.com/p/sqlyog/downloads/list

Download the community edition (.exe) file.

Once downloaded, install the program and connect to your database using the connection details. Then you will have a query editor where you can execute this query.

Upvotes: 4

Related Questions