MySQL AUTO_INCREMENT 不回滚

MySQL AUTO_INCREMENT does not ROLLBACK(MySQL AUTO_INCREMENT 不回滚)
本文介绍了MySQL AUTO_INCREMENT 不回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MySQL 的 AUTO_INCREMENT 字段和 InnoDB 来支持事务.我注意到当我回滚事务时,AUTO_INCREMENT 字段没有回滚?我发现它是这样设计的,但是有什么解决方法吗?

I'm using MySQL's AUTO_INCREMENT field and InnoDB to support transactions. I noticed when I rollback the transaction, the AUTO_INCREMENT field is not rollbacked? I found out that it was designed this way but are there any workarounds to this?

推荐答案

让我指出一些非常重要的事情:

Let me point out something very important:

也就是说,除了比较它们是否相等(=)或不相等(<>)之外,您不应该做任何其他事情.没有关系运算符(<、>),没有按索引排序等.如果你需要按添加日期"排序,有一个添加日期"列.

That is, other than comparing them for equality (=) or unequality (<>), you should not do anything else. No relational operators (<, >), no sorting by indexes, etc. If you need to sort by "date added", have a "date added" column.

把它们当作苹果和橙子:问苹果和橙子是否一样有意义吗?是的.问苹果是否比橙子大有意义吗?不.(实际上,确实如此,但你明白我的意思.)

Treat them as apples and oranges: Does it make sense to ask if an apple is the same as an orange? Yes. Does it make sense to ask if an apple is larger than an orange? No. (Actually, it does, but you get my point.)

如果你坚持这个规则,自动生成索引的连续性差距不会导致问题.

If you stick to this rule, gaps in the continuity of autogenerated indexes will not cause problems.

这篇关于MySQL AUTO_INCREMENT 不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)