HOLDLOCK required in MERGE with UPDATE
4
votes
1
answer
4264
views
Within a .NET 6 application the EntityFramework is used to keep track of entities and to update related fields. To improve bulk updates, the EfCore.BulkExtensions package has been added.
During a .BulkUpdate a SQL statement is generated and executed (by the described package).
I noticed the
WITH (HOLDLOCK)
part. I've read some documentation about the hint and possible race conditions, but do they occur in a MERGE with only the UPDATE command?
In short, is this WITH (HOLDLOCK) hint necessary in case the MERGE statement only includes an UPDATE command or can it safely be removed?
Sample query:
MERGE TargetProducts WITH (HOLDLOCK) AS Target
USING SourceProducts AS Source
ON Source.ProductID = Target.ProductID
WHEN MATCHED THEN UPDATE SET
Target.ProductName = Source.ProductName,
Target.Price = Source.Price;
Asked by Odrai
(153 rep)
Sep 27, 2022, 06:45 PM
Last activity: Sep 28, 2022, 10:33 AM
Last activity: Sep 28, 2022, 10:33 AM