Thursday, July 23, 2009

TRIGGER - After / Before / deleted / inserted - MS SQL

 

TRIGGER

            There are

                        BEFORE (trigger)

                        AFTER (trigger)

 

In BEFORE Trigger .

            There is no keyword in MS sql. Instead it defines for.

It is a default trigger

 

In AFTER Trigger.

            There is a keyword in MS sql.i,e After.

 

 

We can get rows which are stored in temporary table by trigger.

            Insert / update

                        Get values from inserted. ( select * from inserted) (copy of a row(s) effected).

            Delete

                        Get values from deleted .  ( select * from deleted) (copy of a row(s) effected).

 

 

During UPDATE

            On Before trigger – we can get row which is not effected by a update in deleted table.

                                                Basically we get rows from deleted table when we are maintaining log/history table.

 

            On After trigger – we can get row which is effected by a update in inserted table.

 

 

Note : there is no updated temporary table.

 

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code