Ich versuche, eine Datenbank in Oracle SQL-Entwickler einzurichten, ich habe diese 3 Tabellen. Ich brauche die Tabelle "GuyAddress", um 3 Primärschlüssel zu haben, die auch alle Fremdschlüssel sind. Hier kommt es zu einem Fehler, den ich nicht verstehen kann.Oracle SQL-Datenbankfehler: "kein übereinstimmender eindeutiger oder Primärschlüssel für diese Spaltenliste"
CREATE TABLE Guy
(
id NUMBER(10) PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Address
(
zipcode VARCHAR(6),
"number" NUMBER(10),
CONSTRAINT PK_Address PRIMARY KEY(zipcode, "number")
);
CREATE TABLE GuyAddress
(
Guy_id NUMBER(10),
Address_zipcode VARCHAR(6),
Address_number NUMBER(10),
CONSTRAINT FK_GuyAddress_Guy_id FOREIGN KEY(Guy_id) REFERENCES Guy(id),
CONSTRAINT FK_GuyAddress_Address_zipcode FOREIGN KEY(Address_zipcode) REFERENCES Address(zipcode),
CONSTRAINT FK_GuyAddress_Address_number FOREIGN KEY(Address_number) REFERENCES Address("number"),
CONSTRAINT PK_GuyAddress PRIMARY KEY(Guy_id, Address_zipcode, Address_number)
);
Dies ist der Fehler, hoffentlich jemand den Fehler vor Ort kann ich gemacht, weil ich kann nicht ...
Error starting at line : 18 in command -
CREATE TABLE "GuyAddress"
(
Guy_id NUMBER(10),
Address_zipcode VARCHAR(6),
Address_number NUMBER(10),
CONSTRAINT FK_GuyAddress_Guy_id FOREIGN KEY(Guy_id) REFERENCES Guy(id),
CONSTRAINT FK_GuyAddress_Address_zipcode FOREIGN KEY(Address_zipcode) REFERENCES Address(zipcode),
CONSTRAINT FK_GuyAddress_Address_number FOREIGN KEY(Address_number) REFERENCES Address("number"),
CONSTRAINT PK_GuyAddress PRIMARY KEY(Guy_id, Address_zipcode, Address_number)
)
Error report -
SQL Error: ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
Dank!
'CONSTRAINT PK_Address PRIMÄRSCHLÜSSEL (Postleitzahl," Nummer ")' Dies ist kombinierter Primärschlüssel und Sie verwenden 'CONSTRAINT FK_GuyAddress_Address_zipcode FOREIGN KEY (Address_zipcode) REFERENZEN Adresse (Postleitzahl),', die die Ursache sein kann. – ELITE
Ist dies für Oracle (wie der Titel Ihres Beitrags und die Fehlermeldung in der Frage) oder MySQL? Du hast beide markiert. – Boneist
Entschuldigung, das Tag sollte "sql" sein. – SJ19