密钥mysql的重复条目

时间:2014-06-01 12:00:16

标签: mysql sql

这是我在执行有问题的SQL查询时显示的错误

#1062 - Duplicate entry '67302165' for key 'Player_Resource'

我理解这意味着该记录已经存在,但它实际上并不存在,这是我在运行SELECT查询时返回的内容,以检查该特定的{ {1}}

Player_Resource

至于我尝试执行的SELECT * FROM `players` WHERE `Player_Resource` = '67302165' MySQL returned an empty result set (i.e. zero rows). (Query took 0.0003 sec) 查询,请按照以下步骤进行;

INSERT

表格描述就像这样

INSERT INTO 
    `players` 
    (
        `Player_ID`, 
        `Player_Resource`, 
        `Player_Name`, 
        `Player_Common`, 
        `Player_Club`,
    ) 
SELECT 
    `Player_ID`, 
    '67302165', 
    Player_Name, 
    Player_Common, 
    Player_Club,
FROM 
    `players` 
WHERE 
    `Player_ID` = '193301'

为什么会出现此错误的任何可解释的原因?请记住,我已在| Field | Type | Null | Key | Default | Extra | +----------------+----------------+----------+---------+---------+------------------+ Players_id int(11) NO PRI NULL auto_increment Player_ID int(6) NO 0 Player_Resource varchar(255) NO UNI 0 Player_Name varchar(255) NO NULL Player_Common varchar(255) NO NULL Player_Club int(10) NO NULL

上放置UNIQUE索引

1 个答案:

答案 0 :(得分:1)

您似乎在该表中有多行Player_ID=193301。他们有不同的Player_Resource这一事实并不重要,因为您从未在插入查询中使用实际值。您在所有插入中使用67302165的固定值:

...
SELECT 
    `Player_ID`, 
    '67302165', 
    Player_Name, 
    Player_Common, 
    Player_Club,
FROM 
    `players` 
...