When I try to create these two tables I get:
"SQL Error: ORA-00904: "COLLECTIBLENUM": invalid identifier"
I'm sure it's a noob error but I'm just not seeing it. Can someone please point out what I'm doing wrong? Thanks in advance.
CREATE TABLE Collectibles(
CollectibleNum Number(10) NOT NULL,
CONSTRAINT collectibles_pk PRIMARY KEY(CollectibleNum));
Create table DiecastItems(
DiecastName VARCHAR2(45) NOT NULL,
DiecastCopy NUMBER(2) NOT NULL,
DiecastScale VARCHAR2(25),
ColorScheme VARCHAR2(25),
DiecastYear NUMBER(4),
CONSTRAINT diecastItem_pk PRIMARY KEY(DiecastName, DiecastCopy),
CONSTRAINT diecastItem_Collectible_fk FOREIGN KEY(CollectibleNum) REFERENCES Collectibles(CollectibleNum));
When you add FK, you are linking a column as a child from the table you are creating, to its parent from the parent table. Hence, you need to provide the child column name, as well as the parent column name.
The general syntax is
Notice that the columns between
FOREIGN KEY
brackets, are from the table you are creating, while the columns betweeNREFERENCES PARENT_TABLE
are from the parent table.You do not have a column called
CollectibleNum
in yourDiecastItems
. Hence, the following works fine by adding such a column:FIDDLE