Given the following SQL statement:
INSERT INTO my_table VALUES ((SELECT MAX(id) + 1 my_table), {omitted})
And assuming id is the only primary key for my_table.
What is the lowest possible isolation level that would guarantee no duplicate key exception could occur when executing the above statement?
DB2 Isolation levels (ANSI SQL equivalent)
- Repeatable read (Serializable)
- Read Stability (Repeatable read)
- Cursor Stability (Read committed)
- Uncommitted Read (Read uncommitted)
Feel free to use either the DB2 or ANSI SQL equivalent in your answer, but please specify which one you're using. We're using DB2, but I'll accept a more generic answer if one is possible.