简体   繁体   中英

MSSQL Automatic Merge Database

I have a PC that has a MSSQL database with 800 variables being populated every second. I need that database to merge/backup to a second database on another server PC at least every 10 minutes. 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; meanwhile, the second database keeps everything intact and never gets cleared, only being added upon by the merges that occur every 10 minutes.

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.

I will readily admit I know next to nothing about 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?
  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 .)

Assuming you can create a linked server on server A that connects to server B ( Here's a guide )

Then create a trigger on your table, for example 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. How to create a scheduled job .
The trigger only fires on Inserts so deleting rows does nothing to the table on server B.

How is the purging/deleting of the data happening, via a stored 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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