Last_Insert_Id()MySQL函数用于查找AUTO_INCREMENT最近分配的序列号。
mysql> Create table Employee(Id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, Name Varchar(5)); mysql> Insert into Employee(Name) Values('Harvinder'); mysql> Insert into Employee(Name) Values('Suresh'); 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)