❔ SQL: Shared data. One or two table
Hey, im currently creating a database and I need to store the information about vehicles.
The vehicles can be bought or rented. Obviously depending on the type of financing, one will need some fields while the other would need other fields.
That being said, most information are the same no matter the financing type such as the model, the year etc.
My question is: Should I create two table to store the information to avoid having row with empty data in my table or should i not care and just do one table?
PS: For bought vehicles we are talking about 10 fields more or less and rented one about 20 fields
13 Replies
I would have a vehicle table with the vehicle information, and then I would have a finance table, and possible break that up into sales and rentals if the information diverged between the two.
That would create a relation one to many, wouldnt it?
Probably yeah. Depends on the business rules
I think it would and I think its not the best since one vehicle can only have one rentals/sales and one sale/rentals can only have one vehicles :/
Is that a hard requirement? If that's the case, I would only have two tables if the rental and sale data differed enough to warrant it.
Yeah, rentals have 20 fields or so that sales dont and sales have about 10 fields that rentals dont have.
So in your opinion, you think it would be better to create two tables than having a large table with empty fields in each row?
Yes. You don't want to have misc information attached to data that isn't related to what it's actually storing. I.e. if you're storing sales data, you don't want a column like "additional drivers".
Alright i think i will do two table in that case, thanks!
it's about the same performance-wise
Alright, but what is the best practice? Isnt there a guidline i should follow?
either way is fine
Alright! I think i will store them in two different table
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.