How to trigger on after delete with update query mysql

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog i will show you how to trigger on after delete with update query mysql. Sometimes we need to fire trigger as like as after delete or update some fields of an another tables. For better understand an example if we have comments tables and when we remove a row on on this table then we need to update “remove_counter(remove_counter + 1)” on the users table. Here i will give you a example on bellow . Here you can see that how to write trigger code:

Example:

delimiter //
CREATE TRIGGER add_ban_counter_in_users 
	AFTER DELETE ON `chat_messages` 
	FOR EACH ROW
BEGIN
   UPDATE `users` 
   	SET remove_counter = users.remove_counter + 1 
   	WHERE users.id = old.user_id;
END

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →