I have a multi-part question regarding trigger performance. First of
all, is there performance gain from issuing the following within a
trigger:
SELECT PrimaryKeyColum n FROM INSERTED
opposed to:
SELECT * FROM INSERTED
Secondly, what is the optimum way to determine which action fired an
AFTER trigger that is defined for INSERT, UPDATE, DELETE? Is it
something similiar to:
IF NOT EXISTS(SELECT * FROM DELETED)
--sql block for insert
ELSE
IF NOT EXISTS(SELECT * FROM INSERTED)
--sql block for delete
ELSE
--sql block for update
or is there a superior method?
Lastly, is checking @@ROWCOUNT at the beginning of an AFTER trigger the
best way to differentiate between multiple rows being affected or just
a single row? Can using this @@ROWCOUNT test fail? Are there any
situations where it would return erroneous results?
I realize I'm being somewhat nitpicky on these matters but any feedback
would be greatly appreciated!
all, is there performance gain from issuing the following within a
trigger:
SELECT PrimaryKeyColum n FROM INSERTED
opposed to:
SELECT * FROM INSERTED
Secondly, what is the optimum way to determine which action fired an
AFTER trigger that is defined for INSERT, UPDATE, DELETE? Is it
something similiar to:
IF NOT EXISTS(SELECT * FROM DELETED)
--sql block for insert
ELSE
IF NOT EXISTS(SELECT * FROM INSERTED)
--sql block for delete
ELSE
--sql block for update
or is there a superior method?
Lastly, is checking @@ROWCOUNT at the beginning of an AFTER trigger the
best way to differentiate between multiple rows being affected or just
a single row? Can using this @@ROWCOUNT test fail? Are there any
situations where it would return erroneous results?
I realize I'm being somewhat nitpicky on these matters but any feedback
would be greatly appreciated!
Comment