合并各个表?

发布于 2024-10-14 15:51:11 字数 472 浏览 1 评论 0原文

我有5张桌子。 表1表2表3表4表5

所有这些表都以相同的方式进行索引,这意味着,例如,对于名称 john75detable1 包含个人详细信息 table2 包含他的技能组合,table3 包含专业经验,table4 包含资格,table5 包含其他资格。

这些表从一开始就存在,但我认为我需要将所有数据合并到一个表中,因为这 5 个表都是使用相同的索引引用的。所有这些表中有 500k 个名称和详细信息。

名称或任何数据之间不存在其他交叉关系。那你觉得怎么样。我需要合并它吗?如果是,我该怎么做?由于与一个名称相关的所有数据都将位于一行中,我希望这会更容易。哦,是的,名字很独特。

I have 5 tables. table1, table2, table3, table4 and table5.

All these tables are indexed the same way, which means, for example, for name john75de, table1 contains personal details
table2 contains his skill set, table3 contains the professional experience, table4 contains the qualifications, and table5 contains additional qualifications.

These tables have been there from the beginning, but I think I need to merge all of the data into one table because these 5 tables are all referenced using the same index. There are 500k names and details in all these tables.

There are no other cross-relations between names or any data. So what do you think. Do I need to merge it? If yes, how can I do it? Since all the data relating to one name will be in a single row, I hope this will be easier. Oh, yeah, names are unique.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆凄美了谁 2024-10-21 15:51:11

合并这些表听起来是个坏主意。一个人可以拥有多个地址、多种技能、多个以前的工作和多个资格。要对此进行建模,您需要一对多关系,最好使用单独的表来完成。

如果“资格”和“附加资格”具有相同的结构,我可能会想将这两个表合并到一个表中。为此,您可以从一个表中选择所有行并将它们插入到另一个表中,然后删除不需要的表。如果您需要区分这两种类型的资格,您可以为此添加一列。下面是一些用于将数据从一个表复制到另一个表的 SQL 示例:

INSERT INTO qualifications (col1, col2, ... coln, is_additional)
SELECT col1, col2, ... coln, 1
FROM addtional_qualifications

如果两个表中的 AUTO_INCRMENT PRIMARY KEY 列具有相同的值,并且其他表通过外键约束引用这些值,那么合并两个表可能会很棘手。

It sounds like a bad idea to merge these tables. A person can have multiple addresses, multiple skills, multiple previous jobs and multiple qualifications. To model this you need one to many relationships, which is best done using separate tables.

If "qualifications" and "additional qualifications" have the same structure I might be tempted to merge those two tables into a single table. To do that you can select all rows from the one table and insert them into the other, then delete the unneeded table. If you need to distinguish between the two types of qualification you can add a column for that. Here's some example SQL for copying data from one table to the other:

INSERT INTO qualifications (col1, col2, ... coln, is_additional)
SELECT col1, col2, ... coln, 1
FROM addtional_qualifications

Merging two tables can be tricky if you have an AUTO_INCREMENT PRIMARY KEY column with the same values in both tables, and other tables refer to these values via foreign key constraints.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文