bonjour,
Dans un cadre très résumé ci-après, on reproduit notre problème. Il s'agit de faire REFERENCE à un même champ de tuples placés dans des tables distinctes. Nous ne pouvons pas, dans notre cas réel, créer une seule table livre qui serait l'UNION de polar et de roman. Existe-t-il une autre solution ?
CREATE TABLE polar (titre VARCHAR(50) NOT NULL PRIMARY KEY);
CREATE TABLE roman (titre VARCHAR(50) NOT NULL PRIMARY KEY);
CREATE TABLE pret (id SERIAL PRIMARY KEY, titre VARCHAR(50) NOT NULL
REFERENCES polar(titre) REFERENCES roman(titre), duree int);
INSERT INTO polar VALUES('premier titre');
INSERT INTO roman VALUES('second titre');
INSERT INTO pret VALUES(1, 'premier titre', 3);
Cet INSERT plante avec un :
Une instruction insert ou update sur la table «pret» viole la contrainte de clé étrangère «pret_titre_fkey1»
DETAIL: La clé (titre)=(premier titre) n'est pas présente dans la table «roman».
on voudrait en fait pouvoir écrire :
REFERENCES polar(titre) OR REFERENCES roman(titre)
dans la table pret.
Grand merci d'avance pour votre aide.
Partager