Home  >  Article  >  Backend Development  >  如何获取一条新纪录的自增项的值?

如何获取一条新纪录的自增项的值?

WBOY
WBOYOriginal
2016-06-06 20:17:061283browse

定义表时是这样定义的:

<code>CREATE TABLE Room
(
    R_Id char(128) AUTO_INCREMENT PRIMARY KEY,
    R_Info char(128) NOT NULL
)</code>

如果我向表中插入一条记录:

<code>INSERT INTO Room (R_Info) VALUES ("123456")</code>

请问有什么好的方法获取刚才插入记录自增项R_Id的值?

回复内容:

定义表时是这样定义的:

<code>CREATE TABLE Room
(
    R_Id char(128) AUTO_INCREMENT PRIMARY KEY,
    R_Info char(128) NOT NULL
)</code>

如果我向表中插入一条记录:

<code>INSERT INTO Room (R_Info) VALUES ("123456")</code>

请问有什么好的方法获取刚才插入记录自增项R_Id的值?

<code>INSERT INTO Room (R_Info) VALUES ("123456");
SELECT last_insert_id();</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn