简体   繁体   English

创建SQL表,foreign_key混乱

[英]Creating SQL table, foreign_key confusion

模式

One question, I have supervisor set as foreign key. 一个问题,我将主管设置为外键。 He collect information through Activity Participant and take it from person ID. 他通过活动参与者收集信息,并从人员ID中获取信息。

Question: 题:

How should I create the Activity table? 我应该如何创建Activity表? what do I have to write down about supervisor? 我要写下有关主管的内容吗?

CREATE TABLE activity
(
act_id VARCHAR(8) CONSTRAINT activity_pk PRIMARY KEY,
act_type VARCHAR2(20),
act_desc VARCHAR2(30),
act_date DATE,
mor_aft VARCHAR2(9),
CONSTRAINT activity_sup_fk FOREIGN KEY (act_supVisor) REFERENCES person()
);

A foreign key must reference a unique key of the referenced table. 外键必须引用被引用表的唯一键。 Either the table's primary key, or else a secondary unique key. 表的主键或辅助唯一键。

CONSTRAINT activity_sup_fk FOREIGN KEY (act_supVisor) 
  REFERENCES person(Person_id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM