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