MySQL with InnoDB engine has the "feature" of keeping indexes of autoincrement columns on RAM and it is updated each time the service starts. This leads to possible duplicate ids when you delete rows at the bottom of the table, restart the MySQL service and then you insert a new row, its id will be duplicated. For example:
1.- We have this:
ID | Name
-------------
1 |'John'
2 |'Paul'
3 |'Ringo'
4 |'George'
2.- We delete row with id=4
ID | Name
-------------
1 |'John'
2 |'Paul'
3 |'Ringo'
We restart MySQL and insert a new row
ID | Name
-------------
1 |'John'
2 |'Paul'
3 |'Ringo'
4 |'Pete'
So, my question is: SQL Server and Oracle DB have a similar behavior or the final result on them is like the following table:
ID | Name
-------------
1 |'John'
2 |'Paul'
3 |'Ringo'
5 |'Pete'
In other words, is the behavior of SQL Server and Oracle DB the same as MySQL with InnoDB or it keeps the las index of the auto_increment columns even after reset so there is no posible duplicate entries?
InnoDB guarantees uniqueness at any moment. It does not guarantee against delete + restart + insert reusing a number. If your app expects that, you are expecting more than it delivers.
There are other cases where InnoDB may act differently. Consider a multi-row INSERT IGNORE
, REPLACE
, INSERT .. ON DUPLICATE KEY UPDATE
, etc. InnoDB, by default (there is a setting to change this) will pre-assign the desired number of rows. But a ROLLBACK
, dup key, etc will not return the unused numbers to the pool (except in the restart situation you mentioned).
If the auditors are looking in the log, the either need to notice the delete, or demand that you change your code to avoid ever reusing an id. A "sequence" can be simulated if you really need it.