Duplicate unique key error after rollback in mysql
I have a table like this
mysql> describe seudonimos;
+--------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+----------------+
| id_seudonimo | int(11) unsigned | NO | PRI | NULL | auto_increment |
| seudonimo | varchar(45) | NO | UNI | NULL | |
+--------------+------------------+------+-----+开发者_Python百科---------+----------------+
2 rows in set (0.02 sec)
Let's assume that it is empty so autoincrement is 0. For example:
SET AUTOCOMMIT=0;
START TRANSACTION;
INSERT INTO seudonimos (seudonimo) VALUES ('Agatha Christie');
ROLLBACK;
SET AUTOCOMMIT=1;
As far as I konw, the rollback does not affect the autoincrement. So if I insert a new value the autoincrement will be 2 instead of 1. But if I try to insert 'Agatha Christie' again, I have the following problem:
INSERT INTO seudonimos (seudonimo) VALUES ('Agatha Christie');
#1062 - Duplicate entry 'Agatha Christie' for key 'seudonimo'
That is not what I expected. I expected this:
+--------------+--------------------+
| id_seudonimo | seudonimo |
+--------------+--------------------+
| 2 | Agatha Christie |
+--------------+--------------------+
What's wrong?
You probably use MyISAM engine... Run show create seudonimos;
and see.
精彩评论