如果从主表中删除,MySQL将从其他表中删除行

I have added a custom table in Wordpress DB called wp_likeandfollow, it contains these 4 columns

ID====following_id====follower_id====network_id

Here follower_id and following_id are the actual ID of users and there can be duplicate entries. I want to have a check that if admin deletes a user from admin panel, then all entries of that user in likeandfollow table should also be deleted automatically and I want this to be done through MySQL automatically (not via PHP).

Thank you in advance.

You can use a trigger for this.

CREATE TRIGGER remove_likes_and_follows AFTER DELETE on wp_users
FOR EACH ROW
    BEGIN
    DELETE FROM wp_likeandfollow
        WHERE wp_likeandfollow.following_id = old.id;
END

where old.id will be wp_users.id in this case.