MYSQL插入处理重复键值的几种方法
Leave a Comment2010年05月12日 作者: 大头刚
当unique列在一个UNIQUE键上插入包含重复值的记录时,默认insert的时候会报1062错误,MYSQL有三种不同的处理方法,下面我们分别介绍。
先建立2个测试表,在id列上创建unique约束。
mysql> create table test1(id int,name varchar(5),type int,primary key(id));
Query OK, 0 rows affected (0.01 sec)
mysql> create table test2(id int,name varchar(5),type int,primary key(id));
Query OK, 0 rows affected (0.01 sec)
mysql> select * from test1;
+—–+——+——+
| id | name | type |
+—–+——+——+
| 101 | aaa | 1 |
| 102 | bbb | [...]
No Comments so far | 阅读全文 »



