MySQL transaction and trigger

前端 未结 2 398
感动是毒
感动是毒 2020-12-20 14:35

I quickly browsed MySQL manual but didn\'t find the exact information about my question. Here is my question: if I have a InnoDB table A with two triggers triggered by \'AFT

相关标签:
2条回答
  • 2020-12-20 14:56

    They should be atomic, if done in a transaction. The MySQL page on triggers has the appropriate information.

    http://dev.mysql.com/doc/refman/5.0/en/triggers.html

    0 讨论(0)
  • 2020-12-20 14:58

    And by atomic, you mean if one statement in the trigger fails, the whole statement fails. Yes -- the trigger is done in the context of statement's transaction. And no, of course, if there is no transaction, then there is no transaction context.

    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.

    And you aren't allowed to start a transaction in the trigger.

    0 讨论(0)
提交回复
热议问题