views:

75

answers:

6

there are 2 million users each user has 4 tables . the data in 4 tables is not going to be appended and will remain fix.

the structure of each users tables will be same.

To store the data of these users in mysql i have to design a database.

do i need to create 2 million databases each with 4 tables ?

any help appreciated

the 4 tables are the the

  1. incoming call records of the user for 1 month
  2. incming sms records of the user for 1 month
  3. outgoing calls records of the user for 1 month
  4. outgoing sms records of the user for 1 month

the calls tables will have following structure

date time number duration charges

the incoming sms will have following structure

date time number

the outgoing sms will have following structure

date time number charges

A: 

You just need a table for users, table1, table2, table3, table4. then when you need to enter data to table1 just include the users_id to table1

TABLE 1                              USERS

ID   usersID     amount   quantity   ID   Name
1       1           200      2        1   John
2       1           400      3

You can connect then using INNER JOIN by its table1.usersID=users.ID All table must have usersID(expect users table which has ID) to connect them

Hope you get the point

Treby
+3  A: 

No, you do not need 2 million databases with 4 tables each. You just need 1 database, 4 tables, and unique user ID for each user.

Something like:

users table:
| user_id (primary key) | username |

address table
| user_id (foreign key) | address  |

whatever table
| user_id (foreign key) | whatever |

I have to wonder why you need 4 tables per user? Hopefully you understand the basics of what I'm trying to convey here though.

Matt
+4  A: 

Most database servers (and filesystems) will not handle instances requiring that many separate databases. I'm guessing that what you actually require are four tables, each containing a row for each user. That's a totally reasonable requirement.

Michael Petrotta
+6  A: 

This is an SQL antipattern that I call Metadata Tribbles. They look cute and friendly, but soon they multiply out of control.

As soon as you hear phrases beginning "I have an identical table per..." or "I have an identical column per..." then you probably have Metadata Tribbles.

You should start out by making one database with four tables, and add a user_id attribute to each of the four tables.

There are exception cases where you'd want to split into separate databases per user, but they are exceptions. Don't go there unless you know what you're doing and can prove that it would be necessary.

Bill Karwin
I love the name "Metadata Tribbles". That by itself is worth an upvote.
Walter Mitty
A: 

hi no you do not nedd 2 million database! you actuasly need 2 million instance for 4 tables ofcouse you shoude design a relational database thad each table has a relational attribute for other tables

micromaster
+1  A: 

Consider this example -- borrowed from data warehousing -- it is a plain Kimball star. Very simplified model, but these four tables cover your described needs, and more.

alt text

Damir Sudarevic