MySQL 如何查找AUTO_INCREMENT最近分配的序列号

MySQL 如何查找AUTO_INCREMENT最近分配的序列号

使用Last_Insert_Id() MySQL函数来查找由AUTO_INCREMENT最近分配的序列号。

阅读更多:MySQL 教程

例子

mysql> Create table Employee(Id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, Name Varchar(5));
Query OK, 0 rows affected (0.13 sec)

mysql> Insert into Employee(Name) Values('Harvinder');
Query OK, 1 row affected (0.06 sec)

mysql> Insert into Employee(Name) Values('Suresh');
Query OK, 1 row affected (0.07 sec)

mysql> Select* from Employee;
+----+---------+
| Id | Name    |
+----+---------+
| 1  |Harvinder|
| 2  | Suresh  |
+----+---------+
2 rows in set (0.00 sec)

mysql> Select Last_insert_id();
+------------------+
| Last_insert_id() |
+------------------+
|                2 |
+------------------+
1 row in set (0.00 sec)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程