BEFORE or AFTER start for audit logging

I read the MySql 5.0 comment stream on creating a trigger page  and I would like to ask the community if the recommendations are good and whether they will apply to 5.1. What I noticed today with triggers is that it is not possible to update a field in an old table using AFTER UPDATE.

  • Be careful with BEFORE triggers. Limitations are possible, especially if you use the InnoDB engine where the insertion failed, but the actions from your BEFORE trigger will succeed.
  • Use BEFORE triggers primarily for restrictions or rules, not transactions, to configure new ones. * columns should be good.
  • Stick to AFTER triggers for most other operations, such as pasting into a history table or updating denormalization.
+3
source share
1 answer

Yes. AFAIK, MySQL 5.1 did not make any changes to the semantics of triggers. MySQL is trying to support the ANSI / ISO SQL specification for trigger semantics.

You can imagine that a sequence of operations that runs as a string is written to the database:

  • Launch BEFORE Triggers
  • Rate constraints, apply NOT NULL, apply DEFAULTvalues
  • Enter a string in the database
  • Update Indexes
  • Trigger AFTER Triggers

AFTER, . NEW.somecolumn = 1234, AFTER. , , .

, INSERT/UPDATE , , , . -, MySQL , , BEFORE -, . .

, , , , , . . BEFORE, - NOT NULL.

DELETE, , BEFORE.

+13