[英]How do I split a table into multiple tables
I'd like to split my current HUGE table into multiple tables. 我想将当前的HUGE表拆分为多个表。 The new tables should be split according to an they entry on a specific field.
新表应根据它们在特定字段上的输入进行拆分。
Eg if the field is Gender with each record selected as male and female, id like two tables one for male the other female. 例如,如果该字段是“性别”,则每条记录均选择为男性和女性,则id就像两个表,一个是男性,另一个是女性。
Old table:
Gender First Name Last Name
Male John Smith
Female Sally Smith
New tables:
Name: Male
Gender First Name Last Name
Male John Smith
Name: Female
Gender First Name Last Name
Female Sally Smith
Except the field is city. 除了田野是城市。 Rather than name each city separately within the code, id like all the same cities to be picked up and grouped into an individual tables.
无需像在代码中分别命名每个城市,而是像要拾取的所有相同城市并将其分组到一个单独的表中一样使用id。 Any help would be much appreciated.
任何帮助将非常感激。
First query: 第一个查询:
Insert into Table2 select * from Table1 where gender = 'female'
Second query: 第二个查询:
Delete from Table1 where gender = 'female'
Anyway, I would do some research to understand if table splitting is really needed for your case, or if it just increase the DB structure (and relative code) complexity 无论如何,我将进行一些研究以了解您的情况是否确实需要表拆分,或者是否只是增加了数据库结构(和相对代码)的复杂性
What you are asking can be accomplished using partitioning. 您要问的是可以使用分区来完成的。 Since you are using MySQL then you need to checkout list partitioning specifically as it will partition the table according to the specified values.
由于使用的是MySQL,因此您需要特别检查列表分区,因为它将根据指定的值对表进行分区。 You can still use the same queries but the database will automatically use the underlying correct partition.
您仍然可以使用相同的查询,但是数据库将自动使用基础正确的分区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.