I have merge query like below
MERGE [dbo].[tablename] AS tpr
USING @Tabletype AS spr
ON tpr.[ee_typeid] = spr.[ee_typeid]
WHEN MATCHED THEN
UPDATE SET tpr.[name]=spr.[name],
tpr.[modifiedon]=spr.[modifiedon],
tpr.[statecode]=spr.[statecode],
tpr.[statecodename]=spr.[statecodename]
WHEN NOT MATCHED THEN
INSERT ([ee_engagementtypeid],[ee_name],[modifiedon],[statecode],[statecodename])
values (spr.[ee_typeid],spr.[ee_name],spr.[modifiedon],spr.[statecode],spr.[statecodename]);
So when this procedure is executed it checks whether the record exist if yes then update or insert, since I don't know which column is modified so I 'm not putting any conditions instead I use update statement directly.
Could you please let me know what is the good practice? 1. To put condition before update statement to check each column which one is updated and update only that column. 2. Or To update directly all columns without checking which one is modified.
Performance wise which one is better 1st or 2nd ? I feel 2nd will be slower, let me know please if you have best query to handle such conditions.