在修改mysql表中的列的位置的时候报错:
mysql> alter table users modify id smallint unsigned primary key auto_increment first;
ERROR 1068 (42000): Multiple primary key defined
错误原因:定义了两次主键;
解决办法:去掉主键:primary key;
mysql> alter table users modify id smallint unsigned first;
mysql> show columns from users;
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| username | varchar(20) | NO | | NULL | |
| id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| age | smallint(5) unsigned | NO | | NULL | |
| sex | tinyint(1) | YES | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> alter table users modify id smallint unsigned primary key auto_increment first;
ERROR 1068 (42000): Multiple primary key defined
mysql> alter table users modify id first;
mysql> alter table users modify id smallint unsigned first;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show columns from users;
+----------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| id | smallint(5) unsigned | NO | PRI | NULL | |
| username | varchar(20) | NO | | NULL | |
| age | smallint(5) unsigned | NO | | NULL | |
| sex | tinyint(1) | YES | | NULL | |
+----------+----------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)