MySQL 查询给出重复输入错误 1062 [英] MySQL query giving duplicate entry error 1062

查看:62
本文介绍了MySQL 查询给出重复输入错误 1062的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个查询会出错?错误是:SQL 错误 (1062):键 'PRIMARY' 的重复条目 '0'

Why is this query giving an error? The error is: SQL Error (1062): Duplicate entry '0' for key 'PRIMARY'

INSERT INTO `static_number_source` (`IDString`, `source`) VALUES
('RUS-001A', 'Thub'), #one
('RUS-001A', 'Fort'), #two
('RUS-002A', 'Thub'), #three
('RUS-002A', 'Fort'), #four
('RUS-003A', 'Thub'), #five
('RUS-003A', 'Fort'), #six
('RUS-004A', 'Thub'), #seven
('RUS-004A', 'Fort'); #eight

推荐答案

您可以执行 Alter the table 以将 AUTO_INCREMENT 添加到 ID 字段,或者始终在插入时提供 Id

You can do either Alter the table to add AUTO_INCREMENT TO THE ID field, or always provide an Id on Inserts

对于添加AUTO_INCREMENT,只需找到表中id的最大值并将其设置为一个.

For adding AUTO_INCREMENT just find the largest value of id in the table and set id it to one more.

这篇关于MySQL 查询给出重复输入错误 1062的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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