That depends on your database engine, but basically what you need sounds like you want one table referencing the other using a FOREIGN KEY with ON DELETE CASCADE option and then removal from the parent table will automatically remove corresponding rows from dependent tables.