delete trigger to delete row in another table in another database sql

8.3k views Asked by At

I have a database schema called Fulcrum that has a table called Orders with PK on OrderNO, OrderDate, TenantID

I have a bridge database schema called XFer where I also have a table called Orders with the same field names but no keys on OrderNO, OrderDate, TenantID

I need to create a trigger behind the Orders in Xfer that deletes the matching row in Fulcrum.dbo.Orders when I delete the row in XFer.dbo.Orders

thank you

1

There are 1 answers

8
Amogh On BEST ANSWER

Considering you are using Microsoft SQL Server syntax to create such trigger is :

CREATE TRIGGER [XFer].[dbo].[OrderDeleted]
ON [Xfer].[dbo].[Orders]
AFTER DELETE
AS
BEGIN

   DELETE FROM [Fulcrum].[dbo].[Orders] WHERE [Fulcrum].[dbo].[Orders].[OrderNO] IN (SELECT [XFer].[dbo].[Orders].[OrderNO] FROM DELETED)  

END

Obviously the syntax might not be perfect, but this is close to what you need.