MySQL AUTO_INCREMENT does not ROLLBACK(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 不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL AUTO_INCREMENT 不回滚
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
