OceanBase AI Database is compatible with triggers in MySQL 5.6. A trigger is a database object associated with a table and is activated when a specific event occurs on the table.
Triggers can be activated when statements insert, update, or delete rows in the associated table. For example, you can insert rows using INSERT or LOAD DATA statements, and the INSERT trigger is activated each time a row is inserted. If two rows of data are inserted in a batch, the trigger is activated twice.
Triggers can be configured to activate before or after the triggering event. For example, you can configure a trigger to activate before each row is inserted into a table, or after each row is updated.
OceanBase AI Database currently supports the following types of triggers:
INSERTtriggers: activated when a row is inserted. These triggers can be fired byINSERT,LOAD DATA, orREPLACEstatements.UPDATEtriggers: activated when a row is updated. These triggers can be fired byUPDATEstatements.DELETEtriggers: activated when a row is deleted. These triggers can be fired byDELETEorREPLACEstatements.
The INSERT INTO ... ON DUPLICATE KEY UPDATE statement is special. Each row inserted by this statement activates a BEFORE INSERT trigger, followed by either an AFTER INSERT trigger or both a BEFORE UPDATE and AFTER UPDATE trigger. Whether an AFTER INSERT trigger or both BEFORE UPDATE and AFTER UPDATE triggers are fired depends on whether the row has a duplicate key.