bonjour à vous !

Voici 3 tables, j'aimerai faire plusieurs choses.

Si je supprime 1 occurrence dans la table test que ça supprime son occurrence qui suit dans test3 et test2.

exemple bidon lol:

test = membre
test2 = chat
test3 = appartient

si je supprime un membre, ça supprime son appartenance avec le chat mais supprime également le chat qui lui ai propre.

mais un membre peut perdre un chat donc si je supprime le chat dans la table chat il faut que ça supprime aussi l'occurrence dans appartient.

vous me suivez ?

je travail sous MySQL
je me suis aidé de cette page pour essayer de comprendre mais je n'ai pas réussi:
http://dev.mysql.com/doc/refman/5.0/...nstraints.html

est-ce que vous pouvez m'aider s'il vous plait ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
CREATE TABLE IF NOT EXISTS test3 (
  test2_id int(11) NOT NULL,
  test_id int(11) NOT NULL,
  PRIMARY KEY (test2_id,test_id),
  KEY FK_test (test_id),
  KEY FK_test2 (test2_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
 
CREATE TABLE IF NOT EXISTS test2 (
  test2_id int(11) NOT NULL AUTO_INCREMENT,
  test2_txt varchar(50) DEFAULT NULL,
  PRIMARY KEY (test2_id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
 
CREATE TABLE IF NOT EXISTS test (
  test_id int(11) NOT NULL AUTO_INCREMENT,
  test_txt varchar(50) NOT NULL,
  PRIMARY KEY (test_id)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
 
ALTER TABLE test3
  ADD CONSTRAINT FK_test FOREIGN KEY (test_id) REFERENCES test (me_id),
  ADD CONSTRAINT FK_test2 FOREIGN KEY (test2_id) REFERENCES test2 (test2_id);