您好,欢迎访问一九零五行业门户网

MySQL LAST_INSERT_ID() 函数有什么用?

mysql last_insert_id() 函数用于通过 auto_incrment 获取最近生成的序列号。
示例在这个示例中,我们是创建一个名为“student”的表,该表具有 auto_incrment 列。我们在“name”列中插入两个值,当我们使用 insert_last_id() 函数时,它会返回最近生成的序列号,即 2。
mysql> create table student(id int primary key not null auto_increment, name varchar(5));query ok, 0 rows affected (0.13 sec)mysql> insert into student(name) values('raman');query ok, 1 row affected (0.06 sec)mysql> insert into student(name) values('rahul');query ok, 1 row affected (0.07 sec)mysql> select* from student;+----+-------+| id | name |+----+-------+| 1 | raman || 2 | rahul |+---+-------+2 rows in set (0.00 sec)mysql> select last_insert_id();+------------------+| last_insert_id() |+------------------+| 2 |+------------------+1 row in set (0.00 sec)
以上就是mysql last_insert_id() 函数有什么用?的详细内容。
其它类似信息

推荐信息