Search code examples
mysqldatabasedatabase-designdatabase-schema

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 about such concepts will be vry useful..

Thanks in Advance.


Solution

  • 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.