Discussion Locked

Using a Single Trigger for Insert and Update

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have been trying to handle Insert and Update using one trigger. Does anydody know how to detect that a row is being updated in SQL Server 2005? Thanks.

William.

4 replies

by tony hopkinson

if you have common code to run for both transactions put it in a stored proc and the call it from trigger for update and trigger for insert.

The other way is to make use of the inserted and deleted tables. on an insert, the deleted table will be empty.

by wcovuaku

Thanks Tony, i have been considering that. The thing is that i wanted to have everything in one trigger, ie for insert,update.

by tony hopkinson

They are available with in the trigger, inserted has the new version of the record deleted has the old one. If deleted is empty there was no old one therefore it's an insert.

This discussion is closed to new replies.