The general syntax of CREATE TRIGGER is :
CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_statement
in the following example we are updating the Salary column of Employee table before inserting any record in Emp table. Example :
mysql> SELECT * FROM Employee;
+-----+---------+----------+-------------------+--------+-------+
| Eid | Ename | City | Designation | Salary | Perks |
+-----+---------+----------+-------------------+--------+-------+
| 1 | Rahul | Delhi | Manager | 10300 | 853 |
| 2 | Gaurav | Mumbai | Assistant Manager | 10300 | 853 |
| 3 | Chandan | Banglore | Team Leader | 15450 | 999 |
| 5 | Tapan | Pune | Developer | 20600 | 1111 |
| 6 | Amar | Chennai | Developer | 16000 | 1124 |
| 7 | Santosh | Delhi | Designer | 10000 | 865 |
| 8 | Suman | Pune | Web Designer | 20000 | 658 |
+-----+---------+----------+-------------------+--------+-------+
7 rows in set (0.00 sec)
mysql> delimiter //
mysql> CREATE TRIGGER ins_trig BEFORE INSERT ON Emp
-> FOR EACH ROW
-> BEGIN
-> UPDATE Employee SET Salary=Salary-300 WHERE Perks>500;
-> END;
-> //
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter ;
mysql> INSERT INTO Emp VALUES(9,'Rajesh','Delhi','Developer',15000,658);
Query OK, 1 row affected (0.05 sec)
mysql> SELECT * FROM Employee;
+-----+---------+----------+-------------------+--------+-------+
| Eid | Ename | City | Designation | Salary | Perks |
+-----+---------+----------+-------------------+--------+-------+
| 1 | Rahul | Delhi | Manager | 10000 | 853 |
| 2 | Gaurav | Mumbai | Assistant Manager | 10000 | 853 |
| 3 | Chandan | Banglore | Team Leader | 15150 | 999 |
| 5 | Tapan | Pune | Developer | 20300 | 1111 |
| 6 | Amar | Chennai | Developer | 15700 | 1124 |
| 7 | Santosh | Delhi | Designer | 9700 | 865 |
| 8 | Suman | Pune | Web Designer | 19700 | 658 |
+-----+---------+----------+-------------------+--------+-------+
7 rows in set (0.00 sec)