TRIGGERS: ======================= DROP TRIGGER IF EXISTS `update_coaching_master_on_ins_follower`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_coaching_master_on_ins_follower` AFTER INSERT ON `coaching_followers` FOR EACH ROW UPDATE coaching_masters SET total_followers = IF(new.follow_type = 1, total_followers+1, total_followers) WHERE id=new.coaching_id DROP TRIGGER IF EXISTS `update_coaching_master_on_del_follower`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_coaching_master_on_del_follower` AFTER DELETE ON `coaching_followers` FOR EACH ROW UPDATE coaching_masters SET total_followers = IF(old.follow_type = 1, total_followers-1, total_followers) WHERE id=old.coaching_id DROP TRIGGER IF EXISTS `update_coaching_master_on_ins_following`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_coaching_master_on_ins_following` AFTER INSERT ON `coaching_followings` FOR EACH ROW UPDATE coaching_masters SET total_following = IF(new.follow_type = 1, total_following+1, total_following) WHERE id=new.coaching_id DROP TRIGGER IF EXISTS `update_coaching_master_on_del_following`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_coaching_master_on_del_following` AFTER DELETE ON `coaching_followings` FOR EACH ROW UPDATE coaching_masters SET total_following = IF(old.follow_type = 1, total_following-1, total_following) WHERE id=old.coaching_id DROP TRIGGER IF EXISTS `update_coaching_master_on_ins_rating`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_coaching_master_on_ins_rating` AFTER INSERT ON `package_ratings` FOR EACH ROW UPDATE coaching_masters SET rating = (SELECT AVG(rating) FROM `package_ratings` WHERE coaching_id = new.coaching_id GROUP BY coaching_id), total_rating_count = (SELECT COUNT(*) FROM `package_ratings` WHERE coaching_id = new.coaching_id GROUP BY coaching_id) WHERE id = new.coaching_id DROP TRIGGER IF EXISTS `update_test_package_on_ins_total_test`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_test_package_on_ins_total_test` AFTER INSERT ON `tests` FOR EACH ROW UPDATE test_packages SET no_of_test = no_of_test+1 WHERE id=new.test_package_id DROP TRIGGER IF EXISTS `update_product_on_ins_engaged_test_series`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_product_on_ins_engaged_test_series` AFTER INSERT ON `coaching_engagements` FOR EACH ROW UPDATE test_packages SET test_packages.enrolled_students = IF(new.test_package_id > 0, test_packages.enrolled_students+1, test_packages.enrolled_students) WHERE test_packages.id=new.test_package_id DROP TRIGGER IF EXISTS `update_product_on_ins_engaged_practice`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_product_on_ins_engaged_practice` AFTER INSERT ON `coaching_engagements` FOR EACH ROW UPDATE practice_sets SET practice_sets.enrolled_students = IF(new.practice_set_id > 0, practice_sets.enrolled_students+1, practice_sets.enrolled_students) WHERE practice_sets.id=new.practice_set_id DROP TRIGGER IF EXISTS `update_product_on_ins_enaged_quiz`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_product_on_ins_enaged_quiz` AFTER INSERT ON `coaching_engagements` FOR EACH ROW UPDATE quizzes SET quizzes.enrolled_students = IF(new.quiz_id > 0, quizzes.enrolled_students+1, quizzes.enrolled_students) WHERE quizzes.id=new.quiz_id