Rohan Singh Dhaka
Rohan Singh Dhaka

Reputation: 193

Is MERGE statement is a good option to use when we are just updating a table?

I know MERGE is used if we have to combine multiple operations(INSERT/UPDATE/DELETE). But in my case, I have a procedure which is using MERGE statement to update few columns in a table. But sometimes it takes a lot of time to run which is not expected because data is not that big. So is it because of MERGE and is it okay to use merge or should I change it to UPDATE statement?

Upvotes: 1

Views: 684

Answers (1)

Martin Smith
Martin Smith

Reputation: 453658

I would recommend using UPDATE. It is more tried and tested and has fewer bugs and can have better execution plans. It is also clearer to see the intent when reading the source code.

The semantics are not always the same however.

If the table source has multiple rows that could map to a target row then MERGE will raise an error and UPDATE will non deterministically select one of the possible options.

If this semantic is important to you (you want to assert that there is only one match and error if this is violated) then you might want to stick with MERGE.

Upvotes: 2

Related Questions