batsta13
batsta13

Reputation: 539

SQL, two foreign keys referencing the same primary key of another table

I have two tables:

Person(personID, name, phone, email);
Relation(child_personID, parent_playerID);

The relationship table helps identify children and their parent but to do this the personID from the person table has to be referenced twice as foreign. How exactly would I go about doing this?

Upvotes: 1

Views: 6920

Answers (1)

Mikael Eriksson
Mikael Eriksson

Reputation: 139010

Could look something like this.

create table Person
(
  personID int primary key,
  name varchar(50),
  phone varchar(50),
  email varchar(50)
)

create table Relation
(
  child_personID int references Person(personID),
  parent_playerID int references Person(personID),
  primary key (child_personID, parent_playerID)
)

Upvotes: 2

Related Questions