What would be the best way to design this MySQL database?
I have cars
, fuels
, and motor oils
. Each car can use any number of fuels
and any number of motor oils
. What would be the best way to design this database?
So, one car
can have one or many fuels
, and one or many motor oils
.
So I would need to have cars
, fuels
, and motor_oils
tables in my database.
Now since fuels
and motor_oils
have some similar properties like price, date_produced etc.
Would it be smart for me to create another table called lets say products
?
When using OOP language I would have Product
entity, Fuel
and MotorOils
would extend Product
and this way have properties defined in Product
.
How would I design this in Mysql database? Is there such thing as inheritance in MySQL? I know that relation database does not have inheritance, and that there is a way to mimic this in MySQL, just need someone to explain better how is this done?
You could have a products table and a foreign key in each, fuel and motor oils linking to the products table in order to have some kind of inheritance.
Many to many relationships you create by defining a mapping table with a foreign between the entities.
Given you have cars and fuels you could create a table carsFuelsMap which has two foreign key fields morors_id and fuels_id