To know about Existing Trigger's | Query To Find Out Existing Triggers MYSQL
Show Triggers;
Structure of Existing Trigger MYSQL
show create trigger TriggerName;
Create Trigger statement 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 Create trigger statement 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.
No comments:
Post a Comment