0

I am aware that INSERT ... SELECT .. WHERE NOT EXISTS (SELECT...) is not atomic.

There is a race condition where two sessions running concurrently can run the select; both see the row does not exist and then both would attempt the insert.

How would you make this statement atomic in SQL Server? I am not sure which locking hint to use or where to put it.

wrschneider
  • 17,913
  • 16
  • 96
  • 176

0 Answers0