Syntax Of Create Trigger MYSQL | Query Of Create Trigger MYSQL

To know about Existing Trigger's | Query To Find Out Existing Triggers  MYSQL

Show Triggers;

Structure of Existing Trigger MYSQL 


show create trigger TriggerName;


Syntax to create Trigger MYSQL 

1. Change Delimiter using :

delimiter $

2. Trigger would be based on certain event like Delete,Insert

create trigger TriggerName after/before delete/update on tableName for each row begin YourCondition FollowedByAction end $

Example of Creating trigger MYSQL 


CREATE TRIGGER TriggerName AFTER DELETE ON TableName FOR EACH ROW BEGIN IF((SELECT COUNT(DISTINCT Column) FROM TableName WHERE ColumnName=OLD.ColumnName)=0) THEN DELETE FROM TableName2 WHERE columnValue=OLD.columnValue; END IF; END$

OLD.ColumnName will pick old value of Column indicated.
NEW.ColumnName will pick newly inserted value of Column indicated.
Share on Google Plus

About Bittu choudhary

A Software Engineer and SEO Expert.Self-Employed and Making Money through google.