-1

Lets say I would like to make a database of cars and their owners in RDBMS e.g. Postgres. Each car has a unique serial code (maybe some other properties e.g. brand, color etc.) and an owner. The owner could be a person (name, last_name, address) or could be a company (registration_id, company_name)

If cars could be owned only by persons I would just add a column in the cars table with a foreign key to person_id. How would one handle it in this situation though - should I somehow use inheritance for this?

sev
  • 1,500
  • 17
  • 45
  • Does this answer your question? [How can you represent inheritance in a database?](https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database) – philipxy Sep 26 '22 at 17:24

1 Answers1

0

I would create an intermediary table with 3 columns: id, car_id, owner_id and would create a link between those tables alowing you to register more then one onwer to each car and more then one car to each owner. car_id and owner_id with foreign keys to their respective table. In the table owner, I would create a field named type which you could register if it is a company or a human. This way, you can restrict the results of the table owner to only show human using a view.

Frederico
  • 21
  • 4