I must / have to create unique ID for invoices. I have a table id and another column for this unique number. I use serialization isolation level. Using
You either lock the table to inserts, and/or need to have retry code. There's no other option available. If you stop to think about what can happen with: