mysql - auto_increment value increments even if an exception DUPLICATE KEY is thrown or the transaction is Rolled back -
i have table - id auto_increment , email column defined unique.
consider auto_increment set 1.
in stored procedure when insert new row unique email id auto_increment column incremented. correct behavior.
now when try insert same email again unique key violated. check , rollback. auto_increment set 2 now. why?
in third attempt of insert, time unique email row inserted id field has value 3. not good.
is there way can decrement value 2.
check this: mysql auto_increment not rollback
the salient point being: you should never depend on numeric features of autogenerated keys.
Comments
Post a Comment