Triggers in different schemes

I am new to SQL Server.

I need to write a trigger to insert and update a table in another schema in MS SQL.

Example:

TEMP1 table in one schema

TEMP2 table in another schema

How can I do that?

+3
source share
3 answers

As long as SCHEMA have the same owner (the AUTHORIZATION bit in CREATE SCHEMA ), you simply reference the objects using 2 part names.

See CREATE TRIGGER

create trigger MyTrigger on Schema1.Table1
for insert
as
set nocount on
insert Schema2.Table2 (...)
select (..) from inserted
go
+2
source

Not sure if I fully understand the problem, but the basic syntax will look like this:

create trigger MyTrigger on Schema1.Table1
after insert, update
as
    insert Schema2.Table2 values(1, 'test', ...)

    update Schema3.Table3
    set Name = 'XX'
    where Id = 1
go
+1
source

All Articles