SQL Server Interview Question and answers-Triggers, Instead of triggers, after triggers, inserted and deleted tables?
- By Shiv Prasad Koirala in SQL
- Nov 14th, 2012
- 15488
- 0
Triggers are special kind of stored procedure. They can be executed after or before data modification happens on a table. There are two types of triggers "Instead of triggers" and "After triggers".
"Instead of triggers" executes prior to data modification while "after trigger" executes after data modification.
In what scenarios will you use instead of trigger and after trigger?
You will use "INSTEAD trigger" to take alternative actions before the update happens.
Some of the uses of instead of trigger's are:-
While "AFTER trigger" is useful when you want to execute trigger logic after the data has been updated.
Some uses of after triggers are:-
What are inserted and deleted tables?
During triggers we sometimes need old and new values. Insert and deleted tables are temporary tables created by SQL server itself which have new and old values. Inserted tables have one record for newly added data and deleted table has one record of the old version of the data.
So for instance let's say we add a new record called as "Shiv". The inserted table will have "Shiv" and deleted table will have nulls because the record did not exist. Now let's say some user updates "Shiv" to "Raju". Then inserted table will have "Raju" and deleted tables will have "Shiv".
Here is our latest 20+ SQL Interview Questions and Answers video :-
See for more stuffs on SQL server interview questions | Click to view more from authors on SQL server interview questions
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more