use declarative referential integrity.
create table foo ( id int not null primary key , foo varchar(32) not null , ) create table bar ( id int not null primary key , foo_id int null foreign key references foo ( id ) on delete cascade , )
Removing a line from foo will delete all related lines in the line.
Be careful with cascading deletions, though - fat-fingering of the deletion instruction can cause very large damage very quickly, unlike rm (1) in * nix. Cascading deletions can also chew on a transaction log very quickly if you delete a lot of data in one fell swoop.
source share