Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:09:22+00:00 2026-06-18T10:09:22+00:00

When using MySQL START TRANSACTION and the decision is made by MySQL to roll

  • 0

When using MySQL START TRANSACTION and the decision is made by MySQL to roll back –
In the case that a table had an AUTO_INCREMENT column – does the column get… decremented during the roll back?

Or should it?

I am having some issues where the transaction data is being properly rolled back – but it looks like the table was auto incremented and not decremented in the rollback.


# BOTH TABLES START OUT EMPTY // TABLE1 ID is **auto_increment** 

START TRANSACTION;

INSERT INTO `TABLE1` (`ID` ,`NAME`) VALUES (NULL , 'Ted');  # MySQL TABLE1 **ID** is Auto incremented to 1 

INSERT INTO `TABLE2` (`ID` ,`WRONGVALUE`) VALUES (NULL , 'some value');  # error. This TRANSACTION will not succeed 

COMMIT;  # Because of the error - this TRANSACTION is now rolled back and Ted is NOT added

Because MySQL will auto_increment the ID on the first table – regardless of if the transaction succeeds or fails – is the standard practice for this to decrement the table yourself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:09:23+00:00Added an answer on June 18, 2026 at 10:09 am

    No, auto-increment mechanisms must work outside the scope of transactions, because another user may be inserting to the same table before you finish your transaction. The other user’s transaction must be able to allocate the next value, before knowing whether your transaction is using the value you just allocated.

    Re your comment: If I may say it more clearly, any change in the scope of a transaction may be rolled back. The auto-increment counter is not rolled back, so it doesn’t obey atomicity of transactions. Nor does it obey isolation because another transaction gets the next value even though your transaction hasn’t committed yet.

    The way auto-increment works means that sometimes, if you insert some rows and then roll back your transaction, the values you allocated with auto-increment are lost forever!

    But this is okay. Primary key values must be unique, but they don’t need to be consecutive. In other words, they are not row numbers, and you shouldn’t use them like that. So you should never need to decrement values created by auto-increment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL, I have a simple table that logs the IP Address that users
I'm using MySql 5.5. Let's start by looking at a sample of my table:
I am using Hibernate with MySql, when i start my local server and pass
Using mysql 5.5.2 on windows (Wamp) I'm writing a Java application that use several
(Using MySQL and PHP) I have a search form that will allow my users
I'm having some trouble with a SQL transaction using PHP and mySQL. Here is
I have a table that has a START_DATE and an END_DATE column. I want
I'm using MySQL with Memcached, but I'm planning to start using PostgreSQL instead of
To find out the start command for mysqld (using a mac) I can do:
Using MySQL should I store time data as an Int which would be the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.