How to implement a conditional Upsert stored procedure?

后端 未结 5 1401
闹比i
闹比i 2021-02-06 10:49

I\'m trying to implement your basic UPSERT functionality, but with a twist: sometimes I don\'t want to actually update an existing row.

Essentially I\'m trying to synchr

5条回答
  •  故里飘歌
    2021-02-06 11:13

    I'd drop the transaction.

    Plus the @@rowcount probably would work, but using global variables as a conditional check will lead to bugs.

    Just do an Exists() check. You have to make a pass through the table anyhow, so speed is not the issue.

    No need for the transaction as far as I can see.

提交回复
热议问题