简体   繁体   English

如何将一个表拆分为多个表

[英]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.

相关问题 如何使用mysql命令行工具将大表拆分为较小的多个表? - How do I split a large table into a smaller multiple tables using mysql command line tool? 如何有效地将mysql表拆分为多个表(拆分列而不是行)? - How do I efficiently split a mysql table into multiple tables (splitting on columns not on rows)? 如何将mysql表拆分为多个表并查询正确的区域? - How can I split a mysql table into multiple tables and query the correct arrea? 如何将多个表连接在一起 - How do I join multiple tables together 我如何内部联接多个表? - How do I inner join multiple tables? 使用Perl,如何在保持参照完整性的同时从单个表加载多个表? - Using Perl, how do I load multiple tables from a single table while keeping referential integrity? 如果一个表没有引用,如何联接多个表? - how do I join multiple tables if one table doesn't have the reference? SQL Fiddle:如何从多个表插入一个表 - SQL Fiddle: How do I insert into a single table from multiple tables 使用Pentaho Kettle,如何在保持参照完整性的同时从单个表中加载多个表? - Using Pentaho Kettle, how do I load multiple tables from a single table while keeping referential integrity? 如何使用范围和随机名称的自动增量从其他多个表填充表 - How do i populate a table from other multiple tables with autoincrement of range and random names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM