Reputation: 1734
Ok I am making a project on a DTH management system. I am using MySQL DB and Java GUI. The problem is that I have to make the DB such that everytime I add a user, a set of tables must be inserted (e.g 30 days, one table for each day) to add values. This new table will have the same format for all users, the only thing is the column values will be changing. It's like a Matrix where top horizontal row is for timings and left vertical row for channel name and if a user is watching a show on channel 9 at 9pm, then the cell (channel9, 9) will have a value 1, else 0. This has to be done for each day.
My question is simple how do you do this!! Secondly what will be the load on the system. As in the GUI must not crash or take a huge amount of time to access the data.
Is there any other method to do this more easily and efficientl.
Please help. :)
Upvotes: 0
Views: 92
Reputation: 7275
Reasons not to dynamically create tables:
You will ended up with orphaned tables. For example, a user signs up and then deletes his account. What do you do with all his tables?
The schema will change. Your table design is good now, but I guarantee you'll want to change it later. How do you update 10,000 tables automatically? (It's possible to script, but unpleasant.)
Everything has limits. I don't know what the table limit might be for MySQL, but I would guess with decent activity, you'll hit it.
It will be very hard to re-factor. If you hit 1-3 and decide it was a bad idea, it will take quite some time to change.
If you absolutely can't figure out a way to store what you have in MySQL ... as a last resort you could always serialize your object into something like JSON and put that result in a field. Very quick and easy to do and doesn't require a million tables.
Upvotes: 1