sql

All things SQL and JDBC...
dharrigan 2020-09-30T06:01:28.014100Z

when you say delete everything do you also mean tags too?

dharrigan 2020-09-30T06:01:43.014500Z

btw your table for the join could be rewritten as this:

dharrigan 2020-09-30T06:02:41.015500Z

create table post_tag (post_id int references post on delete cascade, tag_id int references tag on delete cascade, primary key (post_id, tag_id));

dharrigan 2020-09-30T07:04:48.015600Z

Here's a simple example using a cascade delete, with also a trigger

dharrigan 2020-09-30T07:05:41.016Z

btw, it's a bit dangerous, in the sense that if you delete a post, that references a tag, that then references another post, then that post will be removed too.

dharrigan 2020-09-30T07:05:57.016200Z

you probably either want to put a restrict in, or remove the cascade delete on the tag 🙂

dharrigan 2020-09-30T07:06:23.016400Z

(and let the trigger do the delete for you)

emccue 2020-09-30T21:09:18.017400Z

@dharrigan yes, but its just curiousity - I think the real answer is the trigger