无法使用外键创建表。错误:ORA-00904 ::标识符无效

时间:2018-03-24 19:45:25

标签: sql oracle identifier ora-00904

我正在尝试创建一个在名为“country”的表中具有外键的表,如下所示:

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”创建表中引用“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),
);

1 个答案:

答案 0 :(得分:1)

,表DDL的最后一行删除尾随逗号Country

CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name),

应该成为:

CONSTRAINT CityCountry_fk FOREIGN KEY (CityCountry) REFERENCES country (name)