1

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?

  • how many users, what data type and how large are the columns A,B,C,D? – kevinsky Dec 16 '14 at 17:46
2

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 with THINGS. In the THINGS table you will have a foreign key which is a column containing a user_id that points at the USERS 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.