GPH Theory: Your Ultimate Guide to General Topics, News, SEO, and Technology

Welcome to GPH Theory, your go-to source for the latest news, insights, and analysis on general topics, SEO, technology, and more. Our mission is to provide you with the most relevant and up-to-date information to help you stay ahead of the curve. From beginners to experts, we have something for everyone. Join us and start your journey towards digital excellence today.

How to Create Trigger in MYSQL | Everything about Triggers MYSQL

  Bittu      

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.
logoblog

Thanks for reading How to Create Trigger in MYSQL | Everything about Triggers MYSQL

Previous
« Prev Post

No comments:

Post a Comment