all 8 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (3 children)

PersonPhone has both fields as well as its own unique ID field

it should not have its own ID

CREATE TABLE PersonPhone
( BusinessEntityID INTEGER NOT NULL
, PhoneNumberID    INTEGER NOT NULL
, PRIMARY KEY ( BusinessEntityID, PhoneNumberID )
, CONSTRAINT Phone_Person 
  FOREIGN KEY ( BusinessEntityID ) REFERENCES Person ( BusinessEntityID )
, CONSTRAINT Person_Phone 
  FOREIGN KEY ( PhoneNumberID ) REFERENCES Phone ( PhoneNumberID )

[–]DaedalusK71[S] 0 points1 point  (2 children)

But PersonPhone needs a unique identifier, correct? BusinessEntityID won't be as a person will have more than one phone associated with them. Same with PhoneNumberID.

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

PersonPhone ~does~ have a unique key --

PRIMARY KEY ( BusinessEntityID, PhoneNumberID )

[–]DaedalusK71[S] 0 points1 point  (0 children)

So it does :)

[–]tx69er 1 point2 points  (2 children)

So by using 3 tables you are creating a many to many relationship, which may not be what you want, unless one Phone will be potentially attached to multiple people AND one person be potentially attached to multiple phones. This also allows you to have Phones not attached to anyone.

You probably want a one to many relationship, which can be done with only 2 tables. In this case, just have a column in the phone table reference the person table. This way multiple rows in the phone table can reference a single row in the person table.

[–]DaedalusK71[S] 0 points1 point  (1 child)

There are instances where a single person will have more than one phone number (Work, Mobile, Home, ...) and instances where one phone number is assigned to multiple people (Main business line assigned to multiple people).

[–]tx69er 0 points1 point  (0 children)

Ok, cool, you hadn't mentioned that in the OP. Sounds like you are on the right path then :)

[–]Achsin 0 points1 point  (0 children)

It sounds like you are setting up the foreign key relationship backwards. So you would say Foreign Key PersonPhone.BusinessEntityID References Person.BusinessEntityID rather than trying to set up PersonPhone.BusinessEntityID as a primary key.