Gabriel, I believe this is what you seek:
There are several ways to map the inheritance relationship in the bank. The best strategy will depend on the situation (types of queries that will be performed against the data, amount of common fields vs specific fields, hierarchy size, amount of data, etc).
1. Table by entity
Each table will contain not only the data of the daughter class but also the data of the parent class. This allows "independent" queries between car and motorbikes to be simpler and faster. However queries seeking data from more than one entity require the use of Union all queries (which is problematic for a number of reasons).
2. Single table + breakdown column
A single table will contain all data of all entities. To differentiate between cars and motorcycles we use a discriminating column. This allows "generic" queries (i.e., on all vehicles) to be faster. It is especially appropriate when there are few specific car and bike attributes (thus avoiding a lot of null values).
3. Main table + daughter table with FK for main table
This model is appropriate when normalization is essential and the daughter tables have many columns. Also this strategy is especially interesting to work with multiple inheritance (an entity can be of various types in the hierarchy simultaneously). The weakness of this modeling is that queries require Join, which makes code complex and brings performance problems as the amount of data and the depth of the hierarchy grows.
4. Joint strategies
Nothing prevents you from modelling part of your hierarchy according to one strategy and part according to another. For example, you can have a main vehicle table with the data common to all vehicles (speed, size, weight, etc.), but have unique tables for each type of vehicle (land vehicles, water vehicles, flying vehicles, etc.).
All strategies have their advantages and disadvantages; OO and relational representations are sufficiently different for several mapping problems to exist (see Object-Lational impedance Ismatch ). If your problem cannot be adequately handled by any of the strategies, there are also solutions with Object oriented database, (see Martin Fowler’s Schemaless Data Structures), indices, etc. Each with its respective strengths and weaknesses.
*** See more in:
Inheritance in relational database
Almost every course, book and article on OOP gives wrong examples of inheritance. Teacher is one of the roles that a Person can have, in this case a temporary position and only one of the multiple and possibly almost infinite characteristics that it can have. And so I generally disagree with everything that was posted here and I don’t give an answer because the question is closed. But yes, a table for thing, because it is not the same object but two related objects.
– Maniero