rjps12
rjps12

Reputation: 605

How to reduce deadlocks on select statement

Can someone know how to fix this problem? When I trace the error. I saw a piece of code calling this query.

SqlException : Transaction (Process ID 57) was deadlocked on lock

SELECT A.[CallID]
FROM dbo.[Calls] A WITH(NOLOCK)
INNER JOIN [dbo].[Issues] B WITH(NOLOCK) ON A.[CallID] = B.[CallID]
WHERE A.[AddedByUserID] = @UserID
  AND A.[EndTime] IS NULL
  AND DATEDIFF(d,A.AddedOn,GETDATE()) <= 1

My understanding with (NOLOCK) is to prevent deadlock. But why am I encountering this error?

Upvotes: 1

Views: 92

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172448

You can try to turn on read committed snapshot so that select should not take any locks and get consistent reads.

Upvotes: 1

Related Questions