MySQL trigger

Mysql Triggers:

The MySQL trigger is a database object that is associated with a table. It will be activated when a defined action is executed for the table. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE and DELETE. It can be invoked before or after the event.

Create trigger `nasiv2`.`test_mailing_trig` AFTER UPDATE on `nasiv2`.`civicrm_mailing_job`
for each row UPDATE civicrm_mailing SET body_html = REPLACE(body_html,’/sites’,’http://nasi-v2.webhop.org/sites’ );

Description:

this is database mysql command to make triggers in mysql. For example to update one table when an other table is being inserted.
Here,

Nasiv2 = database name
Test_mailing_trig = trigger name ( any you can choose )
AFTER = time when to run this trigger
UPDATE = event when to run this trigger
ON = keyword
Civicrm_mailing_job = database table name
For each row = keywords…. To make operation for every row of the civicrm_mailing table.
Civicrm_mailing = database table name which is to be update for each row.
Set = keyword
Body_html = column name of the civicrm_mailing table
Replace = mysql built in function like array or string built in functions.
1. first argument is string to operate
2. second argument is string to find
3. third argument is string to be replaced with second argument string.

Was this article helpful?

Related Articles