希望在一段时间后连续从一个本地数据库表更新到其他服务器数据库表。 [英] Want to update from one Local database table to other server database table continuously after some interval of time.

查看:65
本文介绍了希望在一段时间后连续从一个本地数据库表更新到其他服务器数据库表。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部



我有3个本地数据库,表名为TransactionDetails,有3个diff机器的唯一ID。

和我在dekstop上有一个服务器数据库,具有相同的表结构和名称TransactionDetails。



我想从所有机器复制所有表的内容到一个数据库服务器表,经过一段时间间隔后,当新行添加到本地机器时。



如何为此编写sql querry和windows服务这个?我知道windows服务,但是如何实现整体。

Hi, All

I have 3 local database with a table name as "TransactionDetails" with some unique ID for 3 diff machines.
and I have one server database on dekstop, having same table structure and name "TransactionDetails."

I want to copy the contents of all the tables from all machines to one database server table, after certain time of interval, as an when new rows are added to local machine.

How to write sql querry for this and windows service for this? I know windows services, but how to implement overall.

推荐答案





有两件事可以这样做。



1.在本地数据库的任何表中插入任何行后立即更新主表。



这可以在插入触发器后使用。



2.定期更新主表。



如果您创建一个proc来从本地表中插入主表中的数据,则可以执行此操作。在每个本地数据库上创建此proc,因为您可以从本地数据库调用服务器表。



在本地计算机上安排此proc以在您希望表的任何时间间隔执行要更新(每日,每周,每月)。



插入时,请记住不要插入表中已存在的数据。对于此用途:



- 使用下面的代码。

插入< server name =>。< database name =>。< schema name =>。[交易表]

select * from [Transaction Table] where not exists(select * from< server name = >。< database name =>。< schema name =>。[交易表])



这将只插入行主表中没有。





快乐编码!!
Hi,

There are two things that can be done.

1. Update the main table as soon as any row is inserted in any of the tables in local databases.

This can be done using after insert trigger.

2. Update the main table periodically.

This can be done if you create a proc to insert data in the main table from the local table. Create this proc on every local database as your server table can be called from local database.

Schedule this proc on local machines to be executed at whatever interval you want your table to be updated (daily, weekly, monthly).

While inserting you should keep in mind not to insert the data that is already there in the table. For this use:

--Use the code below.
insert into <server name="">.<database name="">.<schema name="">.[Transaction Table]
select * from [Transaction Table] where not exists (select * from <server name="">.<database name="">.<schema name="">.[Transaction Table] )

This will insert only the rows not there in the main table.


Happy Coding !!


这篇关于希望在一段时间后连续从一个本地数据库表更新到其他服务器数据库表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆