错误1062(23000):密钥'PRIMARY'的重复条目'2147483647' [英] ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY'

查看:100
本文介绍了错误1062(23000):密钥'PRIMARY'的重复条目'2147483647'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我已经看到许多其他类似的帖子,但是答案不适用于我的特殊情况. 以防万一我几个月才学习SQL,对此我没有太多的了解.

First off all, i've seen many others post like this, however the answer wasn't working on my particular case. Just in case i am only few months studding SQL, i have no much knowledge on that.

有一张桌子:

CREATE TABLE passenger_details
   (
    bank_card INT(20) NOT NULL AUTO_INCREMENT,
    email VARCHAR(20), 
    mobile INT(15) NOT NULL,
    p_id INT NOT NULL,    
    PRIMARY KEY (bank_card),
    FOREIGN KEY (p_id) REFERENCES passenger(p_id) 
    );

INSERT INTO passenger_details 
VALUES (0123012301230123,'blah_@hotmail.com',0872863492,1234);

select*from passenger_details;
+------------+--------------------+-----------+------+
| bank_card  | email              | mobile    | p_id |
+------------+--------------------+-----------+------+
| 2147483647 | blah_@hotmail.com  | 872863492 | 1234 |
+------------+--------------------+-----------+------+
1 row in set (0.00 sec)  

我们可以看到,先前的值在表中出错了.应该是16个数字,而不仅仅是10个,实际上是不同的数字.
当我尝试插入新值时:

As we can see, the previous value, just went wrong into table. Should be 16 numbers and not only 10, actually different numbers.
When i try to insert a new value:

INSERT INTO passenger_details 
VALUES (1234258431681842,'blah@icloud.com',0895764829,123548);
ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY'

如果bank_card是AUTO_INCREMENT,为什么会有错误? 我可以将PK更改到另一个地方吗?

If bank_card is AUTO_INCREMENT why there is error? Shall i change the PK to another place?

真的很感谢您的帮助

推荐答案

INT具有

INT has a maximum signed value of 2147483647. Any number greater than that will be truncated to that value. What you need to do is change that column to be a varchar(20) which will hold strings of up to 20 characters since bank card numbers are strings and not actually numbers (you don't do math with the). You also should remove AUTO_INCREMENT as that is not a value you will be incrementing.

这篇关于错误1062(23000):密钥'PRIMARY'的重复条目'2147483647'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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