how to create database trigger on insert, update and delete operation in mysql with coldfusion?

1.7k Views Asked by At

how to create trigger in mysql in coldfusion at the time of insert, update and delete operation.

Thanks
Yugal

1

There are 1 best solutions below

0
On BEST ANSWER

I don't really get the point of this because the whole idea of using triggers is to automatically have the database do something without the need to do it from your server-side language on every insert/update or delete.

So basically it's code you only execute once to create the trigger.

I suppose it's just creating a trigger between your <CFQUERY> tags similar to how you do an insert, update or delete operation

Before the insert

CREATE TRIGGER triggerName BEFORE INSERT ON tableName FOR EACH ROW what_ever_you_want_your_trigger_todo;

After the insert

CREATE TRIGGER triggerName AFTER INSERT ON tableName FOR EACH ROW what_ever_you_want_your_trigger_todo;

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

But really I would do this using a mysql-client, set and forget it. Depending on the use of BEFORE or AFTER it will be executed either before or after your insert/update/delete statement on that table.