假设您已将列值设置为唯一键,并尝试在表中插入重复的值。这将导致错误1062(23000):重复输入。
让我们首先创建一个表-mysql> create table DemoTable776 (
FirstValue int,
SecondValue int,
unique key(FirstValue,SecondValue)
);
使用insert命令在表中插入一些记录。插入重复值时,会出现相同的错误,如下所示-mysql> insert into DemoTable776 values(10,20);
mysql> insert into DemoTable776 values(10,40);
mysql> insert into DemoTable776 values(40,20);
mysql> insert into DemoTable776 values(10,20);
ERROR 1062 (23000): Duplicate entry '10-20' for key 'FirstValue'
使用select语句显示表中的所有记录-mysql> select *from DemoTable776;
这将产生以下输出-+------------+-------------+
| FirstValue | SecondValue |
+------------+-------------+
| 10 | 20 |
| 10 | 40 |
| 40 | 20 |
+------------+-------------+
3 rows in set (0.00 sec)