Bug #40 Last_insert_id incremented even if last insert failed.
Submitted: 25 Jan 2003 16:35 Modified: 28 Jan 2003 16:54
Reporter: Alexander Keremidarski Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version: OS:
Assigned to: CPU Architecture:Any

[25 Jan 2003 16:35] Alexander Keremidarski
Description:
Happens with both MyISAM and InnoDB 

How to repeat:
mysql> create table t (i tinyint unsigned not null auto_increment primary key) auto_increment = 255;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values (null);
Query OK, 1 row affected (0.02 sec)

mysql> insert into t values (null);
ERROR 1062: Duplicate entry '255' for key 1
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|              256 |
+------------------+
[28 Jan 2003 16:54] MySQL Developer
Not relevant as last_insert_id() is not guranteed to return a correct value if previous query failed.