How do I achieve this sort of replication?
I have a main SQL Server
A that data is inserted into. The table of interest on
A looks like this:
Name|Entry Time|Exit Time|Comments
From this main table, I want to construct a table on another server
B that contains the same data from
A but with some additional filters using a
WHERE clause i.e.
WHERE Name IN ('John', 'Adam', 'Jack').
I am not sure what this is called and if this is even supported by SQL Server natively (or I should setup a script to achieve this). Replication means replicating entire data but can someone tell me what is it that I am looking for and how to achieve this?
2 Solutions collect form web for “How do I achieve this sort of replication?”
Transactional replication does support filters on articles, but I’ll be honest – I’ve never set it up with articles with filters. This article may help as well as this topic in Books Online.
If it’s only one table and/or you are uncomfortable diving into replication, you may want to populate the remote table with a trigger (this will obviously be easier if the data is only written to the table on insert and never updated). But you’ll need to have logic set up to deal with situations where the remote server is down.
A third solution might be viable if you do not need server B to be continuously up to date – you can manually move data over every n minutes using a job – either using an outer join / merge or completely swapping out the set of data that matches the filter (I’ve used shadow schemas for this scenario to minimize the impact this has on readers of server B – see this dba.stackexchange answer for more details).
Transactional replication with SQL Server supports the ability to filter data. In fact, when you set up your replication, there is an Add Filter dialog box (assuming you’re using SSMS) that allows you to create your filter (Where clause).
You can learn more about this here.