Kavindu Gayan Kavindu Gayan - 4 months ago 13
SQL Question

SQL Error: ORA-00903: invalid table name

I am trying to create table (orders) with some foreign keys by using this query statement,

CREATE TABLE orders

)
order_id VARCHAR2(20),
item_id VARCHAR2(30) CONSTRAINT item_id_not_null NOT NULL,
quantity_id VARCHAR2(30) CONSTRAINT quantity_id_not_null NOT NULL,
customer_id VARCHAR2(30) CONSTRAINT mobile_no_not_null NOT NULL,
CONSTRAINT order_pk PRIMARY KEY(order_id),
CONSTRAINT fk_customer FOREIGN KEY (customer_Id) REFERENCES ORDER(customer_Id),
CONSTRAINT fk_item FOREIGN KEY (item_Id) REFERENCES ORDER(item_Id),
CONSTRAINT fk_quantity FOREIGN KEY (quantity_Id) REFERENCES ORDER(quantity_Id)
);


I get the following back,


SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"

Answer

There is a typo in the FK definitions. The table should be ORDERS and not ORDER, which is a reserved keyword.