Let’s say I have table TabA with columns:
-
col1 – primary key (but not identity)
-
col2 – foreign key
-
col3 – with unique constraint
-
col4 – with check constraint
-
col5 – with NOT NULL constraint
Also, TabA has 2 triggers:
-
INSTEAD OF INSERT – this one cancel insert into TabA (of course), but in it’s own code insert new row into TabA. The values for all column in this new row are guaranteed correct
-
AFTER INSERT – this one just print string
Now, I am ready insert new row into TabA (INSERT INTO TabA VALUES(…)). Obviously, we have to expect some events:
-
value for col1 must be checked for uniqueness and NOT NULL(primary key)
-
value for col2 must be checked for conformity to the parental table(foreign key)
-
value for col3 must be checked for uniqueness
-
value for col4 must be checked against check constraint
-
value for col5 must be checked for NOT NULL
-
INSTEAD OF trigger must be executed
-
AFTER trigger must be executed
What I want is reorder this list(1-7) so that number 1 be on event that will happen first, 2=event that will happen second, …, and 7 for the last event.
Also, if event X produce error (col5=NULL, for example) – does this mean that events X+1,X+2.. will NOT happen?
Thanks for you help!
This is easy to test by setting up test tables as described with print statements in the triggers and simply trying to insert invalid values. Doing so gave for me
As far as I know the order of 1,7, and 8 are guaranteed. The rest are arbitrary. Any error will stop succeeding steps.