我正在尝试创建表(orderdetails2);该表在两个FK列上有两个FK和一个PK。这是我的代码:
create table OrderDetails2 (
PFOrder_ID Number(3) FOREIGN KEY REFERENCES Orderr(Order_ID),
PFProduct_ID Number(3) FOREIGN KEY REFERENCES Product(Product_ID),
CONSTRAINT PF PRIMARY KEY (PFOrder_ID,PFProduct_ID),
CONSTRAINT FK_1 FOREIGN KEY (PFProudct_ID)
REFERENCES Product(Product_ID),
CONSTRAINT FK_2 FOREIGN KEY (PFOrder_ID)
REFERENCES Orderr(Order_ID),
create table OrderDetails2 (
PFOrder_ID Number(3)
PFProduct_ID Number(3)
CONSTRAINT PF PRIMARY KEY (PFOrder_ID,PFProduct_ID),
CONSTRAINT FK_1 FOREIGN KEY (PFProudct_ID) REFERENCES Product(Product_ID),
CONSTRAINT FK_2 FOREIGN KEY (PFOrder_ID) REFERENCES Orderr(Order_ID)
);
我正在使用Oracle Express。运行代码时弹出一个问题。这是(对于版本1):
ORA-00907: missing right parenthesis
有什么问题?
答案 0 :(得分:4)
从代码的变体开始:
create table OrderDetails2 (
PFOrder_ID Number(3)
PFProduct_ID Number(3)
CONSTRAINT PF PRIMARY KEY (PFOrder_ID,PFProduct_ID),
CONSTRAINT FK_1 FOREIGN KEY (PFProudct_ID) REFERENCES Product(Product_ID),
CONSTRAINT FK_2 FOREIGN KEY (PFOrder_ID) REFERENCES Orderr(Order_ID)
);
您在PFOrder_ID NUMBER(3)
之后和PFPoduct_ID NUMBER(3)
之后缺少逗号。
CREATE TABLE OrderDetails2
(
PFOrder_ID NUMBER(3),
PFProduct_ID NUMBER(3),
CONSTRAINT PF PRIMARY KEY (PFOrder_ID, PFProduct_ID),
CONSTRAINT FK_1 FOREIGN KEY (PFProduct_ID) REFERENCES Product(Product_ID),
CONSTRAINT FK_2 FOREIGN KEY (PFOrder_ID) REFERENCES Orderr(Order_ID)
);
PRIMARY KEY子句必须与PFProduct_ID列分开,因为它是复合键。 (Orderr
拼写是否正确?)原文中的PFProudct_ID
不正确。如果你是一个程序员,你必须能够一致地拼写(即使在更广泛的写作意义上不正确)。
答案 1 :(得分:2)
将最后一个逗号更改为右括号:)
。
CREATE TABLE OrderDetails2
(
...,
CONSTRAINT FK_2 FOREIGN KEY (PFOrder_ID) REFERENCES Orderr(Order_ID)
)