Search code examples
mysqluser-accountsconnection

Should each end user account get their own table in mysql?


n00b mysql question:

If i have a table with all end-user names and Id's and I want to keep track of each users's connections, should each end-user get their own table?

e.g.

end user A is connected to User B, User C and User D; should there be a separate table, just for user A, that has a list:

User B  |    84746
User C  |    94837
User D  |    03265

Solution

  • I'd strongly suggest against it -- do not create multiple tables that will need to be the result of queries (e.g. SELECT * from (CONCAT(...))). Instead create a table that maps end users with their connections:

     id (primary key) | endUser  | connectedUser | connections
     ---------------------------------------------------------
     1                | User A   | User B        | 84746
     2                | User A   | User C        | 94837
     3                | User A   | User D        | 03265
    

    index the endUser column for faster access, and you should be set.