简体   繁体   English

MSSQL自动合并数据库

[英]MSSQL Automatic Merge Database

I have a PC that has a MSSQL database with 800 variables being populated every second. 我有一台装有MSSQL数据库的PC,该数据库每秒填充800个变量。 I need that database to merge/backup to a second database on another server PC at least every 10 minutes. 我需要该数据库至少每10分钟将其合并/备份到另一台服务器PC上的另一个数据库中。 Additionally, the first database needs to be wiped clean once per week, in order to save local drive space, so that only 1 week's worth of data is stored on that first database at any given time; 另外,为了节省本地驱动器空间,每周必须擦除一次第一个数据库,以便在任何给定时间仅将1周的数据存储在该第一个数据库上。 meanwhile, the second database keeps everything intact and never gets cleared, only being added upon by the merges that occur every 10 minutes. 同时,第二个数据库使所有内容保持不变,并且永远不会被清除,只有每10分钟进行一次合并时才会添加。

To my knowledge, this means I cannot rely on database mirroring, since the first one will be wiped every week. 据我所知,这意味着我不能依赖数据库镜像,因为第一个数据库将每周擦除一次。 So from what I have gathered, this means I have to have scheduled merges going on every 10 minutes. 因此,从我收集到的信息来看,这意味着我必须每10分钟进行一次预定的合并。

I will readily admit I know next to nothing about SQL. 我会很容易地承认我对SQL几乎一无所知。 So my two questions are: 所以我的两个问题是:

  1. How do I set up scheduled merges to occur from one database to another in 10 minute frequencies? 如何设置计划的合并,使其以10分钟的频率从一个数据库发生到另一个数据库?
  2. How do I set a database to be scheduled/scripted so that it gets cleared every week? 如何设置一个计划/脚本化的数据库,以便每周清除一次?

(Note: both databases are running on MS SQL Server 2012 Standard .) (注意:两个数据库都在MS SQL Server 2012 Standard上运行。)

Assuming you can create a linked server on server A that connects to server B ( Here's a guide ) 假设您可以在连接到服务器B的服务器A上创建一个链接服务器( 这是指南

Then create a trigger on your table, for example table1: 然后在您的表上创建一个触发器,例如table1:

CREATE TRIGGER trigger1
ON table1
AFTER INSERT
AS
    INSERT INTO ServerB.databaseB.dbo.table1
    select *
    from inserted

More on triggers here . 更多有关触发器的信息

For part 2, you can schedule a job to truncate the table on whatever schedule you would like. 对于第2部分,您可以安排作业以所需的时间表截断表。 How to create a scheduled job . 如何创建计划的工作
The trigger only fires on Inserts so deleting rows does nothing to the table on server B. 触发器仅在插入上触发,因此删除行对服务器B上的表没有任何作用。

How is the purging/deleting of the data happening, via a stored proc? 如何通过存储的proc清除/删除数据? If so, you could also try transactional replication, and replicate the execution of that particular stored proc, but dummy the proc on the subscriber, so when the proc gets replicated and executed on the subscriber, nothing will get deleted/purged. 如果是这样,您还可以尝试事务复制,并复制该特定存储的proc的执行,但是在订阅服务器上虚拟该proc,因此,当在订阅服务器上复制并执行proc时,不会删除/清除任何内容。

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

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