sqlbulkcopy使用c与多个相关表进行交互#

r7s23pms  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(174)

我需要拍摄数据库的快照,并将这些快照存储在两个相关的表中。
快照数据源于多个表,将被整理成一个主目标表和一个相关表,该表将存储快照的拍摄日期。
目标表如下所示:
destinationtable id,snapshothistoryid dataitem1,dataitem2,
快照历史id,日期
此处destinationtable.snapshothistoryid=snapshothistory.id
用于获取快照的伪sql如下所示

select 
    Source1.X as DataItem1,
    Source2.Y as DataItem2
from SourceTable1
inner join SourceTable2 on Source1.Id = Source2.Source1Id

因此,现在我有了我的数据(我知道拍摄快照的日期),我想将此数据放在destinationtable中(同时在shapshothistory中插入一个条目),并确保destinationtable.snapshothistoryid=snapshothistory.id保持不变
如何最好地做到这一点?
我可以先在snapshothistory中插入日期条目并确定id,然后在将数据复制到destinationtable之前分配destinationtable.snapshothistoryid=id,但这感觉是错误的方法。
请给我们一个线索

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题