0

I have two different database server on two different IP addresses. Say SERVER_1 and SERVER_2 (SQL Server 2012).

How to write trigger on table from SERVER_1 database and insert record in SERVER_2 table ?

1
  • Whether both the servers are linked ? Commented Jul 4, 2016 at 4:25

2 Answers 2

3

Not sure why you want to use trigger to insert on different server,you also can use replication if you want to keep data upto date..The approach you are using has disadvantage,since for every insert ,this query has to insert on a different server..

if you want to use trigger,use it like below

create trigger trg_test
on dbo.yourtable
after insert 
as
begin

insert into server2.databasename.schemaname.tablename
select * from server1.databasename.schemaname.table

end
Sign up to request clarification or add additional context in comments.

Comments

1

First Create Link server between 2 server using below command and use the code which is given above.

sp_addlinkedserver 'Server1' or sp_addlinkedserver 'Server2'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.