I have a table Product and another table ProductLog.
The log table needs to track two columns in the Product table. Each time there is an insert, update or delete on those columns I need to update the log table.
Do I need to write three separate triggers, or can one trigger handle these operations?
I also need to know the type of operation, for example I will need to know if the entry in the log table was because of insert or delete or update. If any one give me an example that would be great.
You need just one trigger
You can determine which DML statement fires the trigger based on number of records in
insertedanddeletedtables available within trigger body. ForINSERT,deletedis empty, forDELETE,insertedis empty, forUPDATEbothinsertedanddeletedare not empty. For example,Also, take a look on Tracking Data Changes, there is another option for tracking changes without triggers.