I am trying to create a table that has a foreign key in a table called 'country' which looks as follows:
CREATE TABLE country (
name varchar2(50),
region varchar2(60),
area number(10,0),
population number(11,0),
gdp number,
CONSTRAINT country_PK primary key (name)
);
Every time I try to reference the 'country' in my 'City' create table I get this error ORA-00904: : invalid identifier. Can someone please tell me what I am doing wrong? Thank you.
CREATE TABLE City(
CityName varchar2(50) not null,
CityCountry varchar2(60),
CityPopulation number(11,0),
IsCapital char(1),
CONSTRAINT CityName_pk PRIMARY KEY (CityName),
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name),
);
Remove the trailing comma ,
from your last line of Country
table DDL
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name),
should become:
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name)