Friday, March 9, 2012

getting name of trigger in trigger itself

Hello,
i have a trigger on every table to check that only one row is to handle.
If there are more rows i want to show an error message with the
name of the trigger in which the error occured.
Now i have nearly 100 tables and also so much triggers which are
all identically from the statements inside, only the triggername for
the message is different. So is there a way to get the actual trigger
name instead of having the name hardcoded in each trigger?
tia,
HelmutWhy!!? It seems perverse to prevent multiple row updates. Especially
since the code to do this is probably less efficient than actually
performing the update.
Triggers have global scope and aren't easy to bypass on a live system,
so doing what you propose will make it extremely difficult to perform
any administrative maintenance on the data. Think very carefully about
the implications of this. Even if it is a requirement to limit users in
this way I strongly recommend you do so through SPs rather than
triggers. A trigger should always perform correctly for 0,1 or N rows
updated.
OBJECT_NAME(@.@.PROCID) will return the name of the executing trigger or
proc.
David Portas
SQL Server MVP
--

No comments:

Post a Comment