Something like that??
CREATE TRIGGER tr_Employee_Insert
ON dbo.Employee
FOR INSERT
AS
UPDATE b
SET Status = 'Inserted'
FROM dbo.Employee_Backup b
INNER JOIN Inserted i ON b.EmployeeID = i.EmployeeID
CREATE TRIGGER tr_Employee_Update
ON dbo.Employee
FOR UPDATE
AS
UPDATE b
SET Status = 'Updated'
FROM dbo.Employee_Backup b
INNER JOIN Inserted i ON b.EmployeeID = i.EmployeeID
You basically need to join the Inserted
pseudo table which contains all rows that have been inserted (or updated) from the base table (dbo.Employee
) and the Employee_Backup
table - and then use that result set from the JOIN as the basis for your UPDATE
statement.
Note: this will NOT insert any new rows into Employee_Backup
when you add new rows to dbo.Employee
- is that what you want? If not, you'd have to change the FOR INSERT
trigger a bit ....