Monday, February 20, 2012

Programatically disable trigger

Is it possible to disable a trigger for the duration of a stored procedure
? It would become enbled after the sp runs.See "ALTER TABLE" in BOL.
Example:
ALTER TABLE t DISABLE TRIGGER tr_t_ins
GO
AMB
"Rob C" wrote:

> Is it possible to disable a trigger for the duration of a stored procedure
> ? It would become enbled after the sp runs.
>
>|||ALTER TABLE trig_example DISABLE TRIGGER trig1
GO
-- Re-enable the trigger.
ALTER TABLE trig_example ENABLE TRIGGER trig1
GO
BUT, if you disable the trigger, it is disabled for everyone connected to
the server that does something against the specific table. Use with great
caution.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Rob C" <rwc1960@.bellsouth.net> wrote in message
news:Ze9Pd.4999$a06.2028@.bignews1.bellsouth.net...
> Is it possible to disable a trigger for the duration of a stored procedure
> ? It would become enbled after the sp runs.
>|||alter table disble trigger - check the BOL for more details. but, be very
careful how you use this - it disables trigger (or all triggers for a given
table) for all sessions and for all users. make sure you enable it back
asap.
dean
"Rob C" <rwc1960@.bellsouth.net> wrote in message
news:Ze9Pd.4999$a06.2028@.bignews1.bellsouth.net...
> Is it possible to disable a trigger for the duration of a stored procedure
> ? It would become enbled after the sp runs.
>|||You can disable a trigger via the ALTER TABLE command but this will affect
all connections to the database.
One trick is to add a flag column to your table(s) that the triggers work on
which the trigger can examine in order to see if the logic should be
executed.
"Rob C" <rwc1960@.bellsouth.net> wrote in message
news:Ze9Pd.4999$a06.2028@.bignews1.bellsouth.net...
> Is it possible to disable a trigger for the duration of a stored procedure
> ? It would become enbled after the sp runs.
>

No comments:

Post a Comment