user3549542
user3549542

Reputation: 1

SQL Multiple Main Tables Sharing A Common Table

We have a number of top level tables (e.g., room_traveler, air_traveler) which want to share a single table with common data (e.g., address_traveler). The only way we can think to do this is to have the common table have a foreign key column for each top level table (e.g., address_traveler would have two foreign key columns, one for room_traveler and one for air_traveler).

This would work, but we expect to have more top level tables that need to use this common table. This would mean we would have to continue adding foreign key columns to the common table for each new top level table.

I there a better solution to this problem?

Upvotes: 0

Views: 75

Answers (1)

Frazz
Frazz

Reputation: 3043

That is not a good solution. It complicates queries and maintenance.

I am assuming that the address_traveler table contains addresses. Then give it a primary key... and id column. Then in the room_traveler and air_traveler tables (and any others that may come up in the future) you just add an address_id column that references the address_traveler table.

Upvotes: 1

Related Questions