mysql> ALTER TABLE 名单 ADD id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT FIRST;
Query OK, 0 rows affected (0.27 sec)
Records: 0 Duplicates: 0 Warnings: 0mysql> DESC 名单;
+-------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+----------------+
| id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| 姓 | varchar(12) | NO | | NULL | |
| 名 | varchar(24) | NO | | NULL | |
+-------+----------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> SELECT*FROM 名单;
+----+--------+-----+
| id | 姓 | 名 |
+----+--------+-----+
| 1 | 张 | 飞 |
| 2 | 刘 | 备 |
| 3 | 关 | 羽 |
| 4 | 诸葛 | 亮 |
| 5 | 赵% | 云 |
+----+--------+-----+
5 rows in set (0.00 sec)
mysql> INSERT 名单 VALUES(NULL,'马','超');
Query OK, 1 row affected (0.00 sec)mysql> SELECT*FROM 名单;
+----+--------+-----+
| id | 姓 | 名 |
+----+--------+-----+
| 1 | 张 | 飞 |
| 2 | 刘 | 备 |
| 3 | 关 | 羽 |
| 4 | 诸葛 | 亮 |
| 5 | 赵% | 云 |
| 6 | 马 | 超 |
+----+--------+-----+
6 rows in set (0.00 sec)
mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 6 |
+------------------+
1 row in set (0.00 sec)