Is possible to do a ROLLBACK in a MySQL trigger?

前端 未结 3 1949
逝去的感伤
逝去的感伤 2021-01-13 14:22

Just that is the question: is possible to do a ROLLBACK in a MySQL trigger?

If answer is yes, then, please, explain how.

3条回答
  •  有刺的猬
    2021-01-13 15:15

    From: http://dev.mysql.com/doc/refman/5.1/en/trigger-syntax.html

    The trigger cannot use statements that explicitly or implicitly begin or end a transaction such as START TRANSACTION, COMMIT, or ROLLBACK.

    and

    For transactional tables, failure of a statement should cause rollback of all changes performed by the statement. Failure of a trigger causes the statement to fail, so trigger failure also causes rollback. For nontransactional tables, such rollback cannot be done, so although the statement fails, any changes performed prior to the point of the error remain in effect.

提交回复
热议问题