在不同数据库的表之间复制数据,无需 PK(如同步)

发布于 2024-08-02 07:51:50 字数 589 浏览 9 评论 0原文

我的数据库中有一个表 ( A ),它没有 PK,它有大约 300 k 条记录。

我在其他数据库中有该表的子集副本 (B),该副本只有 50k,并且包含给定时间范围(7 月数据)的备份。

我想从表 B 中将丢失的记录复制到表 A 中,当然不复制现有记录。 (我可以创建一个数据库链接以使事情变得更容易)

我可以遵循什么策略来成功地将 B 中丢失的行插入到 A 中。

这些是表列:

IDLETIME    NUMBER  
ACTIVITY    NUMBER      
ROLE    NUMBER          
DURATION    NUMBER      
FINISHDATE  DATE    
USERID  NUMBER
.. 40 extra varchar columns here ... 

我最担心的是缺乏 PK。我可以使用所有列创建哈希或 PK 之类的内容吗?

在这种情况下,可行的处理方法是什么?

我在表 A 中使用 Oracle 9i,在 B 中使用 Oracle XE (10)。

要复制的元素的大约数量是 20,000

提前致谢。

I have a table ( A ) in a database that doesn't have PK's it has about 300 k records.

I have a subset copy ( B ) of that table in other database, this has only 50k and contains a backup for a given time range ( july data ).

I want to copy from the table B the missing records into table A without duplicating existing records of course. ( I can create a database link to make things easier )

What strategy can I follow to succesfully insert into A the missing rows from B.

These are the table columns:

IDLETIME    NUMBER  
ACTIVITY    NUMBER      
ROLE    NUMBER          
DURATION    NUMBER      
FINISHDATE  DATE    
USERID  NUMBER
.. 40 extra varchar columns here ... 

My biggest concern is the lack of PK. Can I create something like a hash or a PK using all the columns?

What could be a possible way to proceed in this case?

I'm using Oracle 9i in table A and Oracle XE ( 10 ) in B

The approximate number of elements to copy is 20,000

Thanks in advance.

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

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

发布评论

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

评论(2

魔法唧唧 2024-08-09 07:51:50

如果数据量足够小,我会选择以下内容:

CREATE DATABASE LINK A CONNECT TO ... IDENTIFIED BY ... USING ....;
INSERT INTO COPY
SELECT * FROM table@A
MINUS
SELECT * FROM COPY;

您说大约有 20,000 个要复制,但不是整个数据集中有多少个。
另一种选择是删除副本的当前内容并插入原始表的全部内容。

如果完整数据集很大,您可以使用

If the data volumes are small enough, I'd go with the following

CREATE DATABASE LINK A CONNECT TO ... IDENTIFIED BY ... USING ....;
INSERT INTO COPY
SELECT * FROM table@A
MINUS
SELECT * FROM COPY;

You say there are about 20,000 to copy, but not how many in the entire dataset.
The other option is to delete the current contents of the copy and insert the entire contents of the original table.

If the full datasets are large, you could go with a hash, but I suspect that it would still try to drag the entire dataset across the DB link to apply the hash in the local database.

紫﹏色ふ单纯 2024-08-09 07:51:50

只要表中不存在重复行,您就可以将唯一键或主键应用于所有列。如果维护键/索引的开销太大,您还可以在应用程序中查询数据库以查看它是否存在,并且仅在不存在时才执行插入

As long as no duplicate rows should exist in the table, you could apply a Unique or Primary key to all columns. If the overhead of a key/index would be to much to maintain, you could also query the database in your application to see whether it exists, and only perform the insert if it is absent

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