LAST_INSERT_ID

Returns the last value of an AUTO_INCREMENT/IDENTITY column. If multiple sessions concurrently load the same table with an AUTO_INCREMENT/IDENTITY column, the function returns the last value generated for that column.

This function works only with AUTO_INCREMENT/IDENTITY columns. It does not work with named sequences.

Behavior Type

Volatile

Syntax

LAST_INSERT_ID()

Privileges

  • Table owner
  • USAGE privileges on the table schema

Examples

See AUTO_INCREMENT and IDENTITY Sequences in the Administrator's Guide.