Update if different/changed

后端 未结 8 2040
野性不改
野性不改 2020-12-15 02:54

Is it possible to perform an update statement in sql, but only update if the updates are different?

for example

if in the database, col1 = \"hello\"

8条回答
  •  不知归路
    2020-12-15 03:40

    This is possible with a before-update trigger. In this trigger you can compare the old with the new values and cancel the update if they don't differ. But this will then lead to an error on the caller's site.
    I don't know, why you want to do this, but here are several possibilities:

    1. Performance: There is no performance gain here, because the update would not only need to find the correct row but additionally compare the data.
    2. Trigger: If you want the trigger only to be fired if there was a real change, you need to implement your trigger like so, that it compares all old values to the new values before doing anything.

提交回复
热议问题