MySQL AUTO_INCREMENT 不回滚 [英] MySQL AUTO_INCREMENT does not ROLLBACK

查看:47
本文介绍了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 不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆