I get this error for this schema: What am I doing wrong? Edit: Now I can add a column Krankenhaus to the table mitarbeiter and change the table order but I get the same error ... Schema:
Error: A unique obstacle match Is the key given for the reference table "abteilung"
< Code> CREATE TABLE person (SNN N VARAR (40) Primary, NSHRAHARAARA (40) Naul, Varchare name (20) Noel); Start; CREATE TABLE Mitarbeiter (svnr VARCHAR (40) Primary key reference person (svnr), beschaeftigt_seit date not NULL, numerator (5,2), probe (gehalt & gt gehalt; 0), abteilung integer no NULL, Krankenhaus integer no. Make the tablet crankhouse (primary key debut next child ('sachkkrankhaus'), subsequent VARARA (40) faucet, name VARCHAR (20) faucet, GelitatVon VARCHAR (40) Reference Methibieter (STNR) Random Interior Defrade); Make table Abteilung (abid INTEGER DEFAULT next equals ('seq_abteilung'), name VARCHAR (40) No, zero, answer is VARCHAR (40), Cordinier VARCHAR (40) references Mitarbeiter (svnr) Extraordinary defined randomly, crankhaus INTEGER reference Krankenhaus (child), primary key (abid, krankenhaus)); Change table Mitarbeiter foreign key (abteilung, Krankenhaus) Reference Abteilung (Abid, Krankenhaus) DEFERRABLE Early avoiding fk_abteilung add fixed point; COMMIT;
After
the primary key of the table Abteilung
is ( Abid, Crankhahos)
As a foreign reference reference exactly one line, you also need to use both foreign key barrier definition columns.
But if you do not need a column as Krankenhaus
in your table Mitarbeiter
you do not reference Abteilung
Can give
You need to reduce the primary key of either Abteilung
to (abid)
(which is possible because it is a generated, artificial key ) Or Krankenhaus
to your Mitarbeiter
table
Comments
Post a Comment