Thursday 28 July 2016

Triggers_Tit_Bits

Some tit-bits about Triggers and today session

*Turn off Trigger while bulk process.
 We can disable trigger instead of delete it permanantly. (Mohan know about this practically)

*DML triggers control data's, DDL Trigger Control Schema's and structure of db.

*We can use DDL and DML triggers for auditing purpose

*We can set multible trigger on same table. But it will create data discrepancy.
 So avoid to create multible triggers on same table.

*Triggers will affect @@identity property (We already discussed about this)

*Triggers not works when you Truncate table (Because truncate does not log transation)

*We can track bulk data changes using trigger. But in BAS it not working.
 Because in BAS, trigger not executed when more than one row changed.
 They Checked like this..

 IF (SELECT COUNT(*) FROM INSERTED) > 1
  RETURN

 Why they checked like this? (Just review the logic they used. you can find it out)

*We Can Create Trigger on Views..

Advanced Tit-Bits:

*We can set Trigger Order using sp_settriggerorder

*We can create Recursive Triggers (Trigger on Table1 updates Table2,
 Trigger on Table2 updates Table1, It again Repeats (upto 32 level)..
 (Research more on this)

*Check about Server Level Triggers (Its more risk for beginners)



Finally....Using Triggers, You can play in SQL... But , be cautious to create triggers.

Good Day.. Thank You!

No comments:

Post a Comment