MySQL InnoDB databases support the FOREIGN KEY constraint with ON DELETE CASCADE clause. With this specifications, related dependent table rows will be deleted when doing a DELETE on the referred table.
This is an example:
CREATE TABLE categories (
id_category int unsigned not null primary key,
...
);
CREATE TABLE posts (
id_post int unsigned not null primary key,
category_id int unsigned not null,
...
FOREIGN KEY (category_id) REFERENCES categories (id_category)
ON DELETE CASCADE
);
CREATE TABLE comments (
post_id int unsigned not null,
...
FOREIGN KEY (post_id) REFERENCES posts (id_post)
ON DELETE CASCADE
);
Here you can find documentation about the use of foreign keys in MySQL:
http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
foreign keysand usereferencesin tables -> calledreferential integrity. Take a look at dev.mysql.com/tech-resources/articles/… Maybe this is the right thing for youforeign keyand want to do other way use trigger to handle it.