Many people are confused with this type of triggers (INSTEAD OF). This article is just another example.
The "solution" suggested in the article has a number of deficiencies.
The first was picked up as it was not able to handle multi-row updates.
Secondly, even after the suggested correction, the trigger will only do the job if the Id column's value is not changed. Consider this example:
CREATE TABLE Inmate( Id INT, Nickname VARCHAR(30), DateChanged DATETIME)
INSERT Inmate( Id, Nickname ) VALUES( 1, 'Rocky' )
-- Create INSTEAD OF UPDATE trigger on Inmate ...
UPDATE Inmate SET Id = 2 WHERE Id = 1
As a result, there will be 1 row in the table -
1, 'Rocky', NULL
The update statement from the trigger will not update this row because Inserted.Id = 2 and the join with Inmate is empty.
INSTEAD OF triggers are a delicate tool and should only be used when required. In this case - a normal AFTER trigger would do the job.
UPDATE Inmate SET DateChanged = GETDATE()
FROM Inmate
INNER JOIN Inserted ON Inmate.Id = Inserted.Id
Anatol RomanovSQL Server MCPSydney Australiahttp://www.fitbits.com.au