主键由两个外键组成?甲骨文

时间:2022-05-21 11:29:51

I have a question regarding a table creation. I want to combine the attributes of "Ono" and "Pno" into a primary key for a new table. These are both foreign keys, each from different tables. Do I just use a CONSTRAINT Ono_Pno_PK PRIMARY KEY (Ono,Pno)?

我有一个关于创建表的问题。我想将“Ono”和“Pno”的属性组合为新表的主键。它们都是外键,每个都来自不同的表。我是否只使用约束Ono_Pno_PK主键(Ono,Pno)?

what I have used so far:

到目前为止我所使用的:

CREATE TABLE ODetails
(
    Ono Number Not Null,
    Pno Number Not Null,
    Qty Number(3) Not Null,
    Creation_Date Date Not Null,
    Created_By VARCHAR(10) Not Null,
    Last_Update_Date Date Not Null,
    Last_Updated_By VARCHAR2(10) Not Null,
    CONSTRAINT Ono_FK FOREIGN KEY (Ono) REFERENCES Orders (Ono),
    CONSTRAINT Pno_FK FOREIGN KEY (Pno) REFERENCES Parts (Pno)
);

1 个解决方案

#1


5  

just add this line after the constraints,

在约束之后加上这条线,

CONSTRAINT tb_PK PRIMARY KEY (Ono, Pno)

#1


5  

just add this line after the constraints,

在约束之后加上这条线,

CONSTRAINT tb_PK PRIMARY KEY (Ono, Pno)