Denis Nurasy
Denis Nurasy

Reputation: 41

Creating SQL table, foreign_key confusion

schema

One question, I have supervisor set as foreign key. He collect information through Activity Participant and take it from person ID.

Question:

How should I create the Activity table? 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()
);

Upvotes: 1

Views: 161

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562250

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)

Upvotes: 2

Related Questions