Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

MySQL Constraints/Cascades: Will This Work?

I have a table - threads - and another - posts.

Each thread is like a subject with the posts being replies. If a thread is deleted, all related posts need to be deleted.

All posts have an id and a thread_id field. Here's what I have, just wondering if this is correct.

ALTER TABLE `posts`

ADD CONSTRAINT `FK_threads`

ADD FOREIGN KEY(`thread_id`)

REFERENCES `threads`(`id`)

ON DELETE CASCADE

ON UPDATE CASCADE;

Does this need to be the other way around, or is it just completely wrong all together?

1 Answer

Relevance
Still have questions? Get your answers by asking now.