Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
General
»
Disable and enable trigger
13 posts, Page 1 of 2
1
2
»»
Disable and enable trigger
Rate Topic
Display Mode
Topic Options
Author
Message
anbillava
anbillava
Posted Monday, January 19, 2009 5:44 PM
SSC Rookie
Group: General Forum Members
Last Login: Tuesday, August 07, 2012 1:29 AM
Points: 46,
Visits: 91
Is there any way to enable and disable triggers during transaction. ?
Post #639577
Jeff Moden
Jeff Moden
Posted Monday, January 19, 2009 6:09 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
Yes... there is. Please see "Enable Trigger" and "Disable Trigger" in Books Online.
Also, I'd be very, very wary of doing such a thing. The tirgger(s) were put on the table for a reason and disabling them may violate that reason. In practice, it's rarely a good thing to do.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #639581
Jack Corbett
Jack Corbett
Posted Monday, January 19, 2009 11:51 PM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:07 PM
Points: 10,613,
Visits: 11,959
I agree with Jeff. The only time you may want to disable a trigger is when you are doing a mass load/update/delete that does not have to be covered by the purpose of a trigger (auditing, alerting, etc...).
Jack Corbett
Applications Developer
Don't let the good be the enemy of the best. --
Paul Fleming
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #639684
Dutta, Amartha
Dutta, Amartha
Posted Wednesday, January 21, 2009 7:03 AM
Valued Member
Group: General Forum Members
Last Login: Tuesday, May 01, 2012 12:43 AM
Points: 63,
Visits: 110
To disable / enable selective triggers...
ALTER TABLE
tableName
DISABLE TRIGGER
triggername
ALTER TABLE
tableName
ENABLE TRIGGER
triggername
To disable / enable all triggers...
ALTER TABLE
tableName
DISABLE TRIGGER ALL
ALTER TABLE
tableName
ENABLE TRIGGER ALL
Use this with caution and ensure proper handling as a transaction might have disabled but an error in the script might fail to enable it back.
Happy SQLing...
Post #640677
Jeff Moden
Jeff Moden
Posted Wednesday, January 21, 2009 6:44 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
amartha_dutta (1/21/2009)
To disable / enable selective triggers...
ALTER TABLE
tableName
DISABLE TRIGGER
triggername
ALTER TABLE
tableName
ENABLE TRIGGER
triggername
To disable / enable all triggers...
ALTER TABLE
tableName
DISABLE TRIGGER ALL
ALTER TABLE
tableName
ENABLE TRIGGER ALL
Use this with caution and ensure proper handling as a transaction might have disabled but an error in the script might fail to enable it back.
Happy SQLing...
Heh... and the OP actually misses the opportunity to use Books Online for the first time in their life. ;)
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #641303
SG_Explorer
SG_Explorer
Posted Thursday, January 22, 2009 11:58 PM
SSC Veteran
Group: General Forum Members
Last Login: Tuesday, July 24, 2012 5:38 AM
Points: 282,
Visits: 103
IN SQL-2000
To disable / enable selective triggers...
ALTER TABLE tableName DISABLE TRIGGER triggername
ALTER TABLE tableName ENABLE TRIGGER triggername
To disable / enable all triggers...
ALTER TABLE tableName DISABLE TRIGGER ALL
ALTER TABLE tableName ENABLE TRIGGER ALL
*******************
IN SQL-2005
To disable / enable selective triggers...
DISABLE TRIGGER triggername ON tableName
ENABLE TRIGGER triggername ON tableName
To disable / enable all triggers...
DISABLE TRIGGER ALL ON tableName [optional:All server]
ENABLE TRIGGER ALL ON tableName [optional:All server]
Post #642291
anbillava
anbillava
Posted Friday, January 23, 2009 6:30 AM
SSC Rookie
Group: General Forum Members
Last Login: Tuesday, August 07, 2012 1:29 AM
Points: 46,
Visits: 91
I am able to do it by some of other posts in the portal. Thanks for all your info. I am actually working mas data archive and restore stuff. During that time if i enable triggers it leads to lot of other problems. So disabling trigger is must i feel.
Post #642413
Jeff Moden
Jeff Moden
Posted Friday, January 23, 2009 10:01 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
anbillava (1/23/2009)
I am able to do it by some of other posts in the portal. Thanks for all your info. I am actually working mas data archive and restore stuff. During that time if i enable triggers it leads to lot of other problems. So disabling trigger is must i feel.
And, if someone happens to try adding rows during your archive process, BOOM! Bad data because the trigger isn't active.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #642623
Jizzy Wig
Jizzy Wig
Posted Tuesday, March 20, 2012 4:03 AM
Forum Newbie
Group: General Forum Members
Last Login: Saturday, July 14, 2012 2:59 AM
Points: 9,
Visits: 41
What utter nonsense
altering a table within a transaction requires an exclusive lock on the table
so nobody can change the table in any way once the trigger is disabled (DDL or DML)
that lock will persist until the end of the transaction
This is basic database locking - if you don't know how locks work - you don't know how transactions work - and you don't know how databases work
This can be proved in 10 seconds by opening two query windows in SSMS and just typing:
[query1]
begin tran
alter table dbo.Container disable trigger trContainer
(execute)
[query2]
select * from dbo.Container
(execute)
-- note the lock wait ...
[query1]
rollback tran
(execute)
[query2]
oh look ... lock finished waiting results return
(execute)
Post #1269424
Jeff Moden
Jeff Moden
Posted Tuesday, March 20, 2012 6:18 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 33,112,
Visits: 27,038
Jizzy Wig (3/20/2012)
What utter nonsense
Thanks for the example and no problem with disagreement but you really don't need to be that way.
Yes, if you have an explicit transaction or your settings are set to such a thing but a lot of folks forget about things like setting an explicit transaction when they disable triggers. You really don't need to be such a snot about it.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1269480
« Prev Topic
|
Next Topic »
13 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.