I have a table, TBL1, with only GUIDs.
I have another table, TBL2, in which the primary key is GUID and it also has some other columns. I want to update one of the columns in TBL2 table based on whether the GUID is in TBL1.
Which of the following queries is faster and/or more reliable to use for that?
MERGE INTO [db].[dbo].[TBL1] AS target
USING [db].[dbo].[TBL2] as source
ON target.GUID = source.GUID
WHEN MATCHED THEN
UPDATE SET
StatusColumn = 0;
or
UPDATE [db].[dbo].[TBL1]
SET StatusColumn=0
WHERE GUID IN (SELECT GUID FROM [db].[dbo].[TBL2])
or maybe something else?
The answer to this question can only come from the execution plan. From the plan you posted (http://i.imgur.com/6vB2t.png) we can see the following:
Diagnosing this without a plan is just guessing. Look at the plan and/or measure. The measuring provides the answer, but the plan provides the understanding of the answer.