插入带有主键副本的语句 [英] Insert statements with primary key duplicates

查看:209
本文介绍了插入带有主键副本的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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'
解决方案

没有创建。这是主键是什么。如果您需要复制一个,那么该字段不应该是主键。


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.

这篇关于插入带有主键副本的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆