简体   繁体   English

在MySQL中创建动态数量的表

[英]Creating Dynamic amount of tables in MySQL

Ok I am making a project on a DTH management system. 好的我正在DTH管理系统上做一个项目。 I am using MySQL DB and Java GUI. 我正在使用MySQL DB和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 (eg 30 days, one table for each day) to add values. 问题是我必须使DB这样每次添加用户时,必须插入一组表(例如30天,每天一个表)来添加值。 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. 它就像一个矩阵,其中顶部水平行用于定时,左侧垂直行用于频道名称,如果用户在晚上9点观看频道9上的节目,则单元格(channel9,9)将具有值1,否则为0.必须每天完成。

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. 因为在GUI中不得崩溃或花费大量时间来访问数据。

Is there any other method to do this more easily and efficientl. 有没有其他方法可以更容易和有效地做到这一点。

Please help. 请帮忙。 :) :)

Reasons not to dynamically create tables: 不动态创建表的原因:

  1. 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? 你怎么用他的桌子做什么?

  2. 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? 你如何自动更新10,000个表? (It's possible to script, but unpleasant.) (它可以编写脚本,但令人不愉快。)

  3. 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. 我不知道MySQL的表限制可能是什么,但我猜想有了不错的活动,你会发现它。

  4. 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. 如果你达到1-3并且认为这是一个坏主意,那么改变将需要相当长的时间。

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. 如果你绝对无法找到一种方法来存储你在MySQL中拥有的东西...作为最后的手段,你总是可以将你的对象序列化为类似JSON的东西并将结果放在一个字段中。 Very quick and easy to do and doesn't require a million tables. 非常快速和容易做,并不需要一百万个表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM