ORA-00904:“ID”:无效的标识符 [英] ORA-00904: "ID": invalid identifier

查看:891
本文介绍了ORA-00904:“ID”:无效的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用外键创建表。我不断收到 ORA-00904 错误。我究竟做错了什么。是否因为外键的表尚未创建?

  CREATE TABLE成分(
成分_id数字(2, 0),
成分VARCHAR2(55)NOT NULL,
quantity_required VARCHAR2(15)NOT NULL,
optional_ingredient VARCHAR2(30)NOT NULL,
CONSTRAINT pk_ingr_id PRIMARY KEY(ingredient_id) ,
CONSTRAINT fk_ingredient_list FOREIGN KEY(id)REFERENCES成分列表(ID)
);


解决方案

请看下面这行:

  CONSTRAINT fk_ingredient_list FOREIGN KEY(id)REFERENCES成分列表(id)

您的表没有名为id的列。我假设你的意思是写

  CONSTRAINT fk_ingredient_list FOREIGN KEY(ingredient_id)参考文献ingredient_list(id)

$ b 编辑:

另外,如你怀疑自己,如果你想引用在创建成分表时,必须创建它。


Trying to create a table with a foreign key. I keep getting ORA-00904 error. What am I doing wrong. Is it because table of the foreign key is not yet created ?

CREATE TABLE ingredients( 
   ingredient_id       number(2,0),
   ingredient          VARCHAR2(55) NOT NULL,
   quantity_required   VARCHAR2(15) NOT NULL,
   optional_ingredient VARCHAR2(30) NOT NULL,
   CONSTRAINT pk_ingr_id PRIMARY KEY(ingredient_id),
   CONSTRAINT fk_ingredient_list FOREIGN KEY(id) REFERENCES ingredient_list(id)
);

解决方案

Take a look at the following line:

CONSTRAINT fk_ingredient_list FOREIGN KEY(id) REFERENCES ingredient_list(id)

Your table has no column named "id". I assume you meant to write

CONSTRAINT fk_ingredient_list FOREIGN KEY(ingredient_id) REFERENCES ingredient_list(id)

EDIT:
Additionally, as you suspected yourself, if you want to reference the ingredient_list table, you must create it before creating the ingredients table that references it.

这篇关于ORA-00904:“ID”:无效的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆