为什么这是一个重复的密钥?
mysql> describe tagged_chemicals;
+-------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| bar_code | text | NO | | NULL | |
| rfid_tag | text | NO | UNI | NULL | |
| checked_out | char(1) | NO | | N | |
+-------------+---------+------+-----+---------+-------+
3 rows in set (0.04 sec)
mysql> select * from tagged_chemicals;
+-------------+----------------------+-------------+
| bar_code | rfid_tag | checked_out |
+-------------+----------------------+-------------+
| 416444.0001 | 34443030304142453141 | N |
+-------------+----------------------+-------------+
1 row in set (0.00 sec)
mysql> INSERT INTO tagged_chemicals (rfid_tag, bar_code) VALUES("34443030304144393935", "412577.0001B");
ERROR 1062 (23000): Duplicate entry '34443030304144393935' for key 'rfid_tag'发布于 2012-04-24 15:17:46
这是由于索引前缀造成的。
前缀是实际放置到索引中的字符量。
如果prefix为1,那么您将无法插入行ab和aa,因为这两个行的前缀值都为a,因此会导致重复条目错误。
前缀用于减少索引中存储的数据量,因为在大多数情况下,一个长字符串中的几个字符就足以加快查询速度。
更多详情请访问:http://dev.mysql.com/doc/refman/5.5/en/create-index.html
https://stackoverflow.com/questions/10293273
复制相似问题