Insert statements with primary key duplicates

痴心易碎 提交于 2019-12-25 02:21:16

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22832701/insert-statements-with-primary-key-duplicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!