For a relation 0..n between two tables (t1,t2), the mpd generates an intermediate table (t3) with two fk.
Let two constraints on the t3 table, each one with "on delete cascade", if I do:
delete from t1 where id1=$id1;
I want to delete all rows of the t3 which contain the fk id1 and all rows of the t2 which contain the fk id2.
Is it possible in one query ?
Edit: here are my tables:
create T1 (
id1 ...
...
CONSTRAINT pk_id1 PRIMARY KEY (id1) );
create T2 (
id2 ...
...
CONSTRAINT pk_id2 PRIMARY KEY (id2) );
create T3 (
id1 ...,
id2 ...,
CONSTRAINT pk_T3 PRIMARY KEY (id1, id2),
CONSTRAINT fk_T3_1 FOREIGN KEY (id2)
REFERENCES T2 (id2) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fk_T3_2 FOREIGN KEY (id1)
REFERENCES T1(id1) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE )
$id1, $id2and you want toDELETE from t1 where id1=$id1; DELETE from t2 where id2=$id2;and all the related rows deleted fromt3(which should be as you have cascade delete enabled)? – ypercubeᵀᴹ Jun 10 '13 at 15:41t2as well because you may have another row int3with$id37, $id2. What should happen to that row, deleted too? – ypercubeᵀᴹ Jun 10 '13 at 16:11