I have two tables, t1:
id,field
t2:
id,field,t1_id
t1 and t2 are connected via t1_id
Can I make the db remove the t2 entry automatically when I remove the t1 entry?
I have two tables, t1:
id,field
t2:
id,field,t1_id
t1 and t2 are connected via t1_id
Can I make the db remove the t2 entry automatically when I remove the t1 entry?
If you're running at least MySQL 5, how about:
DELIMITER $$
CREATE TRIGGER t1_AD AFTER DELETE ON t1 FOR EACH ROW
BEGIN
DELETE FROM t2 WHERE t1_id=OLD.id;
END $$
DELIMITER ;
(Caveat emptor: not at my workstation, have not tested!)