Jump to content

Recommended Posts

Guest orb123
Posted

Hi, I was wondering how I would add a trigger to a delete a row from forum_replies when a topic is deleted from forum_posts?

 

 

Thanks for your assistance.

Guest orb123
Posted

Hi, I am failing to understand.

 

I ran the following SQL query

 

 

DELETE [LOW_PRIORITY] [QUICK] [iGNORE]

posts_forums[.*]

FROM replies_forums

[WHERE id=postid]

 

 

But it returns

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[LOW_PRIORITY] [QUICK] [iGNORE] posts_forums[.*] FROM replies_forums ' at line 1

 

Any help would be greatly apperiated thanks.

Posted

Try this

DELIMITER $$
USE `db_name`$$
CREATE
TRIGGER `db_name`.`delete_forum_replies`
AFTER DELETE ON `forum_posts`
FOR EACH ROW
BEGIN   
DELETE FROM `forum_replies`
WHERE (id = old.id);
END$$

Be sure to change db_name to your database name and check table names (forum_posts and forum_replies.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...