Mitch
Mitch

Reputation: 1173

SQL Server 2014 trigger across multiple databases

I have 2 databases test1 and test2. Let's say that I have a system, that updates specific values in database test1.

Now I want to create a trigger which is placed in database test2 to check if database test1 updates the values.

When it is updated, I want to write something to database test2.

I have tried it with the following trigger:

ALTER TRIGGER [dbo].[testtrigger] 
ON [test2].[dbo].[naam2]
AFTER UPDATE ON [test1].[dbo].[naam]

However, I get a syntax error at:

Incorrect syntax near 'ON'. Expecting ',',AS,NOT_FOR, or WITH

Now I wonder why this is happening. I have searched about how to do this, and the all reference to ON.

I'm using Microsoft SQL Server 2014

I will add a image to try and make it more clear if it isn't. Image of the 2 databases

Upvotes: 1

Views: 938

Answers (1)

TheGameiswar
TheGameiswar

Reputation: 28890

trigger is in database test2,when a table in database test1 changes,iwant to respond..

Your syntax is wrong..Below is overview of how you can do it

create trigger triggername on test1.dbo.table1
after update
as

begin
insert into test2.dbo.table2
select * from deleted

end

Upvotes: 1

Related Questions