本文介绍了插入带有主键副本的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL中做了一些插入语句,其中一些条目具有相同的主键。这个输出在我的MySQL shell中:
$ $ $ p $ ERROR 1062 (23000):键'PRIMARY'的重复条目'1'
错误1062(23000):键'PRIMARY'的重复条目'2'
错误1062(23000):重复条目3键'PRIMARY'
ERROR 1062(23000):键'PRIMARY'重复输入'4'
错误1062(23000):键'PRIMARY'的重复输入'5'
错误1062 (23000):键'PRIMARY'的重复输入'6'
错误1062(23000):键'PRIMARY'重复输入'8'
$ p $那么,MySQL是否做了输入,并且只是给了我这个错误,或者在这个时候停止了输入。我怎么能解决主键错误的问题?我知道这些主键有时是重复的,但是这是有原因的。 解决方案没有创建。这是主键是什么。如果您需要复制一个,那么该字段不应该是主键。
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.
解决方案
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.
这篇关于插入带有主键副本的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!