Home  • Database • MySQL

Automatically delete records in child table when delete related record in parent table using mysql trigger

MySQL
delimiter //
drop trigger if exists ad_question_bank//
create trigger ad_question_bank after delete on mcq_bank_master
for each row
begin

 delete from mcq_bank_details where question_id=old.id;

end;//
delimiter ;
It will be automatically executed when delete command is applied in parent table. here mcq_bank_master is parent table and mcq_bank_details is child table

Comments 1


5259

Share

Copyright © 2024. Powered by Intellect Software Ltd