Last week I solved an issue with the deadlock with a table and thought it is worth sharing the information as we are using multi-threading batches a lot.
Background about the issue:
In the batch, we are updating a log table to keep track of the messages sent outside using update_recordset. We are using where clause on two fields. In multi-threaded batch, deadlock was happening for all the records even though the multiple threads were working on different records.
Solution:
This took me a while but at the end what I found was if there is no index at the table for the where clause you are using in your query then sql locks the table at the time of update and not just a record. It uses table scan operator in the execution plan, hence causing the deadlock.
The reason why the developer did not put index at the table was there was no unique index in the table. So key lesson here is, create index even though it is not unique for the where clauses.
Below link provides really good information on how SQL deals with indexes
https://www.sqlpassion.at/archive/2014/11/24/deadlocks-caused-by-missing-indexes-in-sql-server/