合并 2 个 id 重叠的表
我有 2 个表,它们的结构相同,但用于在 2 个不同的应用程序中提供服务。因此,它们每个都有唯一的记录(app1 中的记录不会存在于 app2 中)。但它们的 Id 是由 2 个应用程序单独维护的。因此,app1 中的 id 可能存在于 app2 中,但具有不同的信息。
我需要将这 2 个表记录合并到一张表中,因为这 2 个应用程序正在合并为一个表。问题出在 ids 上。我可能会重置 id 并为每条记录重新生成唯一的 id。 id 没有被其他表引用,因此重置它不是问题。但我不太确定如何执行此操作。
I have 2 tables, their structure is identical but used to serve in 2 different applications. So, each of them have unique records (records from app1 won't exist in app2). But their Ids are maintained separately by the 2 apps. So, ids from app1 might exist in app2 but with different information.
I need to merge these 2 tables records into one table because the 2 applications are being merged into one. The problem is with the ids. I will probably reset the ids and regenerate the unique id for each record. The ids is not referenced by other tables, so resetting it is not a problem. But I'm not really sure how to execute this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个具有自动递增 (id) 列的表。
然后创建一个 INSERT ... SELECT 查询以从每个表导入数据,
例如
Create a table with an auto incremend (id) column.
Then create an INSERT ... SELECT query to import data from each table
Eg
此处将使用
INSERT INTO .. SELECT FROM
- 不带id
列。同样,我会将 application_id 列放入新表中 - 只是为了确保我知道数据来自哪里:对于应用程序 2:
The
INSERT INTO .. SELECT FROM
is to be used here - without theid
column. Aslo, I would put an application_id column into the new table - just to be sure that I know what data came from where:For application 2:
您可能想要研究的一个选项是使用视图以任何应用程序可接受的格式合并两个表的数据。
One option you may want to look into is using a view to consolidate the data of both tables in a format acceptable for whatever application.