Thursday 20 November 2008

MySQL Triggers

My recent 'baptism of fire' with MySQL triggers has revealed a couple of differences with their cousins in the SQL Server and Oracle domain.

1) You need seperate triggers for UPDATE, INSERT and DELETE. Oracle and SQL Server will let you combine these into one trigger.

2) You cannot create triggers dynamically using a Procedure. The Execute command in the stored procedures works fine when creating a table, but try creating a Trigger. The parser throws an error stating that you can not run these types of commands.

The real problem for me has been 2). I often rely on writing procedures to apply auditing to a table (composed of audit table and trigger to insert the data from the main table into the audit table).

No comments: