Question

I did some insert statements in MySQL where some entries had the same primary Keys. I got

this output in my MySQL shell:

ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '3' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '4' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '5' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '6' for key 'PRIMARY' 
ERROR 1062 (23000): Duplicate entry '8' for key 'PRIMARY'

So, did MySQL make the entries and just gave me this error or did it stop at this point and didn't make the entries. And how could I solve the problem with primary key errors ? I am aware that these primary keys have duplicates sometimes, but this is for a reason.

Was it helpful?

Solution

The entries with duplicate primary keys were not created. That is what primary keys are for. If you need to duplicate one, then that field should not be a primary key in the first place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top