Writing trigger to transfer data between two databases

I have similar databases(same tables, table structure) on two diferent servers. When the data is loaded onto server1, it has to be validated and if it meets a specific condition then data need to be transfered on to the server2. I can write a trigger to do the validation and condition checking. I need help in the second part. the databases are on separate machines.
Who is Participating?
zahid_synentiaConnect With a Mentor Commented:
Have a look at linked servers. You can link a server on a seperate machine and then refer to it in SQL by the server name.
You could use replication to transfer the data or call a stored procedure on the other server in a distributed transaction
pappalaAuthor Commented:
Thank you for the comments. I would like to know how it has to be done. How to link servers or replicate in the trigger?
If you use replication you wouldn't need to use the trigger just set up articles for replication. Using distributed transactions you could call a remote Sp fro ma trigger. Ensure that the remote sp has a return @error this will help cathcing any errors that have occured

if you choose doing it with replication i suggest you doing the following. Let's say you have 2 servers, let's call them BO (BackOffice) and PUB (Publication). Assume feed arrives to FEEDDB on BO and it's parsed there. If it's ok, you want it to be transferred to server PUB, PUBDB (same structure as FEEDDB). The simplest in my opinion would be to create a 3rd DB on BO, cal it TRANSDB.
Establish replication of your choice (merge, transactional, snapshot) between BO.TRANSDB and PUB.PUBDB. So all data enterred in BO.TRANSDB will be sent over to PUB.PUBDB. Now all what remains, is to populate TRANSDB, but since it's on the same server (BO) than FEEDDB, you can simply manage it in your FEEDDB..PARSEFEED trigger, like this

if (....criterias...)
   insert into TRANSDB..YOURTABLE select * from inserted

This solution can be programmed/set up in no time (1-2 hours depending the amount of tables you wanna include in this process). Also this solution doesn't deal with data manipulation on PUB server.

I'd go with this if the criterias are real complicated. Otherwise you can simply establish replication between FEEDB and PUBDB if your criterias are simple and you can set them in the article filtering.

All Courses

From novice to tech pro — start learning today.