0

I have a Spring application which uses an SQL database. In the application I use rollback for Transactions. When an exception occurs, the transaction gets rolled back as it should and all the created rows get rolled back. However, the IDs keep incrementing.

For example, if it inserts IDs 5,6,7, and then rolls back everything, despite the rollback next time the ID starts from 8. I would like it to start from 5.

Is there a way to handle this so that the ID counter gets rolled back too? Is this possible in NoSQL databases?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Auto increments like SEQUENCE or IDENTITY are never regenerated because some other sessions can have been take new values in the continuity

This is the SQL standard and every RDBMS have the same behaviour.

SQLpro
  • 3,994
  • 1
  • 6
  • 14