Oracle 5.0 Reference Manual page 982

Table of Contents

Advertisement

The ID that was generated is maintained in the server on a per-connection basis. This means that
the value returned by the function to a given client is the first
most recent statement affecting an
affected by other clients, even if they generate
ensures that each client can retrieve its own ID without concern for the activity of other clients, and
without the need for locks or transactions.
The value of
LAST_INSERT_ID()
of a row to a non-"magic" value (that is, a value that is not
Important
If you insert multiple rows using a single
LAST_INSERT_ID()
row only. The reason for this is to make it possible to reproduce easily the
same
For example:
mysql>
USE test;
Database changed
mysql>
CREATE TABLE t (
->
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
->
name VARCHAR(10) NOT NULL
->
);
Query OK, 0 rows affected (0.09 sec)
mysql>
INSERT INTO t VALUES (NULL, 'Bob');
Query OK, 1 row affected (0.01 sec)
mysql>
SELECT * FROM t;
+----+------+
| id | name |
+----+------+
|
1 | Bob
|
+----+------+
1 row in set (0.01 sec)
mysql>
SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|
1 |
+------------------+
1 row in set (0.00 sec)
mysql>
INSERT INTO t VALUES
->
(NULL, 'Mary'), (NULL, 'Jane'), (NULL, 'Lisa');
Query OK, 3 rows affected (0.00 sec)
Records: 3
Duplicates: 0
mysql> SELECT * FROM t;
+----+------+
| id | name |
+----+------+
|
1 | Bob
|
|
2 | Mary |
|
3 | Jane |
|
4 | Lisa |
+----+------+
4 rows in set (0.01 sec)
mysql>
SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|
2 |
+------------------+
Information Functions
AUTO_INCREMENT
AUTO_INCREMENT
[961]
is not changed if you set the
[961]
returns the value generated for the first inserted
statement against some other server.
INSERT
Warnings: 0
962
AUTO_INCREMENT
column by that client. This value cannot be
values of their own. This behavior
AUTO_INCREMENT
and not 0).
NULL
statement,
INSERT
value generated for
column

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents