Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

LAST_INSERT_ID Function

Description

The LAST_INSERT_ID function returns the value created at the end of the AUTO_INCREMENT column of all tables.

If no values are INSERTed successfully, the last successful value will be maintained, and the SQL statement on execution does not affect the LAST_INSERT_ID() value. If you enter multiple rows with one INSERT statement, the LAST_INSERT_ID() will return the input row value entered at the end. If the execution result of the previous SQL statement returns an error, the LAST_INSERT_ID() value is not defined, and the rollback can not recover the LAST_INSERT_ID() value as the previous transaction value.

You can not check the LAST_INSERT_ID() value used in the trigger, outside trigger.

The created ID is maintained independently for the connection of each client.

Syntax

LAST_INSERT_ID()

Example

CREATE TABLE ss (id INT AUTO_INCREMENT NOT NULL PRIMARY KEY, text VARCHAR(32));

INSERT into ss VALUES(NULL,’cubrid’);

SELECT LAST_INSERT_ID();

 

     last_insert_id()

=======================

                     1

 

INSERT INTO ss VALUES(NULL,’database’),(NULL,’manager’);

SELECT LAST_INSERT_ID();

 

     last_insert_id()

=======================

                     3