Unable to create a table with foreign key. Error: ORA-00904: : invalid identifier
Unable to create a table with foreign key. Error: ORA-00904: : invalid identifier
我正在尝试创建一个 table,它在名为 'country' 的 table 中有一个外键,如下所示:
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)
);
每次我尝试在我的 'City' 创建 table 中引用 'country' 时,我都会收到此错误 ORA-00904:: 无效标识符。有人可以告诉我我做错了什么吗?谢谢。
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),
);
从 Country
table DDL
的最后一行中删除结尾的逗号 ,
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name),
应该变成:
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name)
我正在尝试创建一个 table,它在名为 'country' 的 table 中有一个外键,如下所示:
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)
);
每次我尝试在我的 'City' 创建 table 中引用 'country' 时,我都会收到此错误 ORA-00904:: 无效标识符。有人可以告诉我我做错了什么吗?谢谢。
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),
);
从 Country
table DDL
,
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name),
应该变成:
CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name)