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

查看:109
本文介绍了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天全站免登陆