Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Trigger between two databases

Status
Not open for further replies.

MasterPO

Programmer
Oct 10, 2002
51
0
0
US
This should be so simple, but I can't seem to get it!

I have two databases that are identical (Demodata and Data_01). When a user inserts or deletes a record in a specific table in Demodata, I want to make the same thing happen to the same table in Data_01.

I wrote an Insert trigger than works fine but, the Delete is giving me problems.

Here is the code that does not work:

Code:
CREATE TRIGGER utr_SyncSysCodes_Delete ON demodata.SYCDEFIL_SQL 
FOR  DELETE 
AS

Delete from Data_01.Sycdefil_SQL where 
Data_01.Sycdefil_SQL.cd_type = deleted.cd_type AND
Data_01.Sycdefil_SQL.sy_terms_cd = deleted.sy_terms_cd
Go

The error message is "The column prefix 'deleted' does not match with a table name or alias name used in the query".
How do I reference the fields in the 'deleted' table so I only delete this one identical record from the other database table??
 
Code:
USE demodata
GO

CREATE TRIGGER utr_SyncSysCodes_Delete
  ON SYCDEFIL_SQL
  FOR DELETE
AS

DELETE Data_01..Sycdefil_SQL
FROM Data_01..Sycdefil_SQL s
  JOIN deleted d
    ON s.cd_type = d.cd_type AND s.sy_terms_cd = d.sy_terms_cd
GO

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top