Can i create each table for each user in my social networking site?
I'm creating a social networking site with features similar to Facebook. I want to start with schema design for my database. What i thought was to create each table for each user who registers to our site.. am i doing right?
If a million users register to my site, a million tables will be created. how to go on about optimizing this? Please do suggest me techniques to overcome this and some references or books to learn a开发者_如何学Cbout such concepts will be vry useful..
Thanks in Advance.
This is not the way you want to do it.
What you want to do is have a table (perhaps called 'users'
) that contains one row for each user that registers. Creating a new table for each user is completely pointless and would cause terrible performance.
Maybe something like this:
TABLE users - username AS VARCHAR(255) - password AS VARCHAR(255) (use a hashed password, of course) - ...
Then when a user registers, simply insert the information they provide into the users
table as a new row.
That would be massive overkill. You should probably read up on database design (start with normalisation, but don't overdo it). Then write down what you want to save for each user, and think about how to save it without saving data double.
But I'm pretty sure a table-per-user is not an option for this.
You must be confusing the meaning of the words database, table, field (or column), record (or row).
- A database contains all your data for a specific project. There is always one database per project (or almost always)
- A table contains all data of a specific entity and by saying entity, I mean an object type that is imaginable as real or seperatelly existing by itself. A person is an entity, a book is an entity, a phone is an entity, a movie is an entity, etc. Each of these would be seperate tables in a database.
- A field (or column) is a data type that represents a specific characteristic (feature) of a table's entity. For example a table of users can have the fields:
NAME
,SURNAME
,AGE
, etc. These are all features that a user has. - A record (or row) is an actual item of one table. It is a single 'piece' of the table's entity. For example in a table of users, one record is one single user, namely
{NAME:"John", SURNAME:"Smith", AGE:"32"}
.
In your example, I can tell you for sure that you only need one database. You want to store information for many users, so you need one table called USER
. You will need to store features to your users, like: name, surname, age, address, etc., then you will need to create the respective fields in this table: NAME
, SURNAME
, AGE
, ADDRESS
, etc. Then you will need to insert your data in the database as records. It will be one record per user you want to store.
精彩评论