先建立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 | n