I have a SQL query as below, running within REPEATABLE READ transaction.
IF NOT EXISTS (SELECT * FROM TableName WHERE Column1Name = @Column1Value)
INSERT INTO TableName VALUES (@Column1Value, @Column2Value);
The above query gets run within multiple processes. I see a possibility when process 1 does a SELECT
and then process 2 also does as SELECT
(as there is shared lock) before either of the processes get chance to do an INSERT
, there would be a deadlock. I would like to avoid this. What is the correct table hint to use for this situation? Note that it is not possible to enable READ_COMMITTED_SNAPSHOT
on the database.