C
C#2y ago
N0mlss

❔ 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
therealgooey
therealgooey2y ago
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.
N0mlss
N0mlssOP2y ago
That would create a relation one to many, wouldnt it?
therealgooey
therealgooey2y ago
Probably yeah. Depends on the business rules
N0mlss
N0mlssOP2y ago
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 :/
therealgooey
therealgooey2y ago
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.
N0mlss
N0mlssOP2y ago
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?
therealgooey
therealgooey2y ago
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".
N0mlss
N0mlssOP2y ago
Alright i think i will do two table in that case, thanks!
Anton
Anton2y ago
it's about the same performance-wise
N0mlss
N0mlssOP2y ago
Alright, but what is the best practice? Isnt there a guidline i should follow?
Anton
Anton2y ago
either way is fine
N0mlss
N0mlssOP2y ago
Alright! I think i will store them in two different table
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server