简体   繁体   English

表从DB2同步到SQL Server

[英]Table Sync from DB2 to SQL Server

We have a tables in Db2, That which we need to get that table to MS SQL server (only for read), And I want it to be in sync for every 15 minutes (one way from DB2 to SQL Server). 在Db2中有一个表,我们需要将该表发送到MS SQL Server(仅用于读取),并且我希望它每15分钟同步一次(从DB2到SQL Server的一种方式)。 Can you suggest the best approach? 您能建议最好的方法吗?

让SQL代理作业每15分钟执行一次SSIS包。

I know that all the time MERGE is the right option to sync the tables in the SQL. 我知道,MERGE一直是同步SQL中的表的正确选择。 But I am not sure, whether we can use it in linked servers also. 但是我不确定是否也可以在链接服务器中使用它。 Anyway, after some research I got this task accomplished by using the merge join. 无论如何,经过一些研究,我通过使用合并连接来完成了这项任务。 Merge will update, insert, delete what ever required. 合并将更新,插入,删除所需的内容。 But it will take a little bit more time to update the table for every 15 min, when the job runs. 但是,在作业运行时,每15分钟需要花一点时间来更新表。 So, you can create a #Temptable to insert the transactions that were done from the lastjob done.You can use the datetime stamp in that source table to retrieve the transactions that were done from the last job done(15min). 因此,您可以创建一个#Temptable来插入从上一次完成的工作中完成的事务。您可以在该源表中使用datetime戳来检索从上一次完成的工作(15分钟)中完成的事务。 If you don't have the date time in source table, you can use the audit table for that source table(if applicable). 如果源表中没有日期时间,则可以将审计表用于该源表(如果适用)。

(JLT table have 3 columns (last_job_end)( cur_job_start)(some job identity). JLT is the job log table we need to create in linked server to get the last job end and cur job start time, We need to update last job end every time at the end of query in JOB. As well as cur job start in the beginning of the job ) (JLT表具有3列(last_job_end)(cur_job_start)(一些作业标识)。JLT是我们需要在链接服务器中创建的作业日志表,以获取最后的作业结束和当前的作业开始时间,我们需要更新最后的作业结束)每次在JOB中查询结束时。以及cur job在job的开头开始)

SELECT * 
INTO #TEMPtable 
FROM OPENQUERY([DB2], 'Select *  from source_table
                       where some_id_column in 
                            (select some_id_column  
                             from audit_table AT, Job_log_table  JLT
                             where datetime > last_job_end 
                               and datetime <= cur_job_start
                               and c_job = ''some_job_id'')’)`

If you don't have the audit table and you have the datetime in Source. 如果您没有审核表,而Source中有日期时间。

SELECT * 
INTO #TEMPtable 
FROM OPENQUERY([DB2], 'Select * 
                       from source_table s, JOB_CYCLE_TABLE pr
                       where s.DATETIME <= pr.cur_job_start 
                         and s.DATETIME > pr.last_job_end
                         and pr.c_job = ''some_job_id''')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM