Monday, October 26, 2009

Trigger - After, Instead of

Trigger - After
An UPDATE trigger is used to perform an action after an update is made on a table

Trigger - INSTEAD OF
An Instead of trigger is used to replace the incoming statement with statemement declare in trigger.

Reference
Introduce to Trigger

Making use of INSTEAD-OF triggers in SQL Server 2005
This article explain why we use Instead-of triggers, and give example of Instead-of Triggers.

Using INSTEAD OF In Place of Triggers In SQL Server 2000
This article gives good example of "Instead of trigger". In the example, instead of trigger is used when we want replace insert statement with customize message.

Notes:
- We cannot create an AFTER trigger on views.
- AFTER triggers gets executed automatically after the PK and FK constraints.
- INSTEAD OF triggers can be created on views
- you cannot create two INSTEAD OF triggers on the view/ table for the same event.
- INSTEAD OF DELETE and INSTEAD OF UPDATE triggers cannot be defined on tables that have corresponding ON DELETE or ON UPDATE cascading referential integrity defined.

reference : Implementing Triggers in SQL 2000

No comments: