Answer the question
In order to leave comments, you need to log in
What is the best way to store such data in a table?
Example:
While using the application, the user picks fruit. There are 18 types of fruits in total. In the entire history of using the application, he may not collect any types of fruit, or he may not collect a single fruit at all.
When a user wants to sell some type of fruit, there must be at least a certain number of fruits of this type, say - 100.
What is the best way to store data for such a task in a table?
1) In the form of 19 columns (1 for the user ID and 18 for fruit types), and if the user picks only one fruit of one type, the remaining columns will be zero and exist in vain (or maybe he will change his mind about picking fruit at all?).
2) As 2 columns (1 for user ID and 1 for fruit species ID), and multiple rows. Each line will mean the presence of a certain type of fruit.
Answer the question
In order to leave comments, you need to log in
2) As 2 columns (1 for user ID and 1 for fruit species ID), and multiple rows. Each line will mean the presence of a certain type of fruit.This option is more flexible.
I am for the first option. It will be most productive, though not correct if you read smart books.
Let it go. 18 ints won't take up much space.
Adding a new column in the future is not such a problem if you are sculpting new fruits, but the logic of working with the database itself will be greatly simplified.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question