I have a merge query similar to the one below:
MERGE [Unshipped] u
USING [Order] or ON or.ID = u.ID
WHEN MATCHED AND u.Date <> or.Date
THEN
UPDATE
SET u.Date = or.Date
WHEN NOT MATCHED
THEN
INSERT (ID, FK, Date)
VALUES (or.ID, or.FK, or.Date)
If i am to add TABLOCK where is the best place for it? I would have assumed i would put it like below - wrap the whole merge statement:
MERGE [Unshipped] u WITH (TABLOCK)
USING [Order] order or ON or.ID = u.ID
or is it more suitable for it to go with the insert statement?
You only need:
MERGE [Unshipped] WITH (TABLOCK) AS u
USING [Order] or ON or.ID = u.ID
Rest of the MERGE statement is unchanged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With