Setting relationship between a table with one Primary Key and a table with two primary keys

Arnold Layne
Arnold Layne used Ask the Experts™
on
I have a bridge table DL that has values from a Drivers table and a Locations table.

Locations can have more than one driver and drivers can be signed up at more than one location, which is why I have the bridge.
Drivers
PK = Drivercode

Locations
PK = LocationCode

DL (bridge table)
PK = DriverCode
PK = LocationCode

I want to relate the PK DriverCode column on DL to the PK DriverCode column on Drivers and I want to relate the PK LocationCode column on DL to the PK LocationCode column on Locations.

It seems as though since I have two primary keys on DL, I cannot relate each key to another table because it tells me that the values must represent something unique. So it seems like the problem is having two primary keys in DL instead of one, but I need them because each column on DL can repeat, but both columns cannot.

So what do I do about a situation like this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Citrix Technology Professional / Director of TechDev Services, IPM
Commented:
You cannot have two primary keys, but you can have the primary key span both fields.

This is called a composite key:
https://database.guide/how-to-create-a-composite-primary-key-in-sql-server-t-sql-example/
Arnold LayneDeveloper

Author

Commented:
It was a simple question and I got the simple, straightforward answer I needed, plus a link that further explains. Thank you.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
You are most welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial