I am trying to make an application which users can have their own account
For the account, I have an single table and now I would like to add a function which
allows users to items in to their account
For example, user A want to add item A ,B ,C ,D to his account,
then on the database should have 4 rows of new data
Also there are no limit on the maximum number of item users can add.
My question will be how the item should I store on the database.
In a single table or a new table for each of the users?
Will the data retrieving time be very slow if there are lots of users with items?
And will many tables in a single database affect my works?
Best Answer
A general rule of thumb is that you will have a table for each type of thing that you are recording information about. Each instance of a thing will be a record in a table.
It would probably* be a terrible idea to have one table per user. Have one table with
USERS
and one table withTHINGS
. In theTHINGS
table you will have a foreign key which is a column containing auser_id
that points at theUSERS
record for the owner of the thing.Relational databases are designed specifically to make this kind of structure easy and fast to work with. You shouldn't* ever need to worry about how many users there are or how many things they have.
* NOTE: Your requirements are very sparse. These are rules of thumb.