Guys i currently have 2 tables that reference a lookup table. Ive been tasked with modifiying the database to allow the tables to reference more than one value in the lookup table.
My idea is to create a new table that has a new PK and a column that references the lookup table. The PK of the new table is then dumped into the parent tables thus maintaining referential integrity E.G
Current
Contracts
=========
PK Id
FK lookupId
Warranties
==========
PK Id
FK lookupId
New
Contracts
=========
PK Id
FK LinkingTableId
Warranties
==========
PK Id
FK LinkingTableId
LinkingTable
============
PK Id
FK LookupId
Is this a good way of handling the multiple references?
Your NEW proposed table structure cannot handle multiple references, because each Contract and Warranty row is linked to just one single LinkingTable row.
I see two ways to do this:
Add two distinct linking tables, one for each many-to-many relationship:
Add a single new linking table, to handle both many-to-many relationships:
The first is the correct and preferrable solution, as the engine can enforce the table foreign keys and data integrity is less at risk. I have seen the latter used in some real world projects. It works, but it is not a good solution… and sooner or later you will have problems with it.