Please stop using this UPSERT anti-pattern - SQLPerformance.com
Locating the row to confirm it exists, only to have to locate it again in order to update it, is doing twice the work for nothing.
BEGIN TRANSACTION;
UPDATE dbo.t WITH (UPDLOCK, SERIALIZABLE) SET val = @val WHERE [key] = @key;
IF @@ROWCOUNT = 0
BEGIN
INSERT dbo.t([key], val) VALUES(@key, @val);
END
COMMIT TRANSACTION;
September 8, 2020 at 2:57:38 PM EDT
*
FILLER