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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16381773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:38:14  来源:igfitidea点击:

Primary key composed of two foreign keys? Oracle

sqloracledatabase-designforeign-keysprimary-key

提问by Lost_in_SQL_wilderness

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”的属性组合成一个新表的主键。这些都是外键,每个都来自不同的表。我是否只使用 CONSTRAINT Ono_Pno_PK PRIMARY KEY (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)
);

回答by John Woo

just add this line after the constraints,

只需在约束后添加这一行,

CONSTRAINT tb_PK PRIMARY KEY (Ono, Pno)