Pages

Thursday, June 18, 2009

What Happens When You Issue INSERT statement

Today I was in the interview panel, and one of the panelists asked one very basic question. The question is “What happens when you execute INSERT statement on table which has Identity column, Primary Key, Check constraint, Not Null Constraint, Foreign key, Instead Of Trigger and After Trigger.” Which one gets executed first?

This question looks very simple but its bit tricky. by the time he answers the question, I was trying to find the answer to this by creating simple example.

The Order is:

1) IDENTITY Insert check
2) Not Null Constraint Validation.
3) Data Type Verification
4) Instead of trigger execution If it exists.
5) Primary key Constraint Validation
6) Check Constraint Validation
7) Foreign Key Constraint Validation
8) After Trigger Execution