URL: https://linuxfr.org/users/elrik/journaux/attention-sql-foreign-key Title: Attention : SQL Foreign key Authors: Elrik de Melnibone Date: 2003年05月21日T18:09:24+02:00 Tags: Score: 0 Voici mes tables (Postgres) : **Une table Langue qui decrit differentes langues :** _ CREATE TABLE Langue ( id SERIAL PRIMARY KEY, intitule VARCHAR(30) NOT NULL );_ **Une table qui fait reference à Langue, la "clée primaire" est la combinaison de 'id' et 'lang_id' :** _ CREATE TABLE Domaine ( id CHAR(3) NOT NULL, intitule VARCHAR(60) NOT NULL , lang_id INTEGER NOT NULL REFERENCES Langue(id) ON DELETE RESTRICT, CONSTRAINT domaine_langue PRIMARY KEY (id, lang_id) ); _ **Et attention une table "Groupe" qui veut faire reference à la "Langue" et à "domaine" :** _ CREATE TABLE Groupe ( id CHAR(4) NOT NULL, intitule VARCHAR(60) NOT NULL, domaine CHAR(3) NOT NULL :evil: :twisted: , lang_id INTEGER NOT NULL REFERENCES Langue(id) ON DELETE RESTRICT, ); _ Le probleme est au niveau des petits demons, impossible de faire une REFERENCES (Foreign key) sur id de domaine puisqu'il n'est pas unique ce qui est normal... Comment pourrait-on faire ? J'espere que mes explicatoins sont claires... Merci

AltStyle によって変換されたページ (->オリジナル) /