Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 trigger settings

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-08-13 : 17:47:36
how can we set a trigger to off and then make it active

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-13 : 17:48:53
You can enable and disable triggers with ALTER TABLE. Check BOL for the syntax.

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-08-13 : 18:17:43
For example:-
I have a trigger on the emp_detail table.consider
insert into emp_details(emp_id,emp_name,emp_age)values(1324,'Prash',28)
Now whenever an insert/update occurs to this table there is a trigger that fires a sequence of events.
Now for some testing purposes I have to turn off the trigger and then insert the dataset and then call an update so that
the trigger is turned on and then the events will be fired with the update

How can I use alter table here
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-13 : 18:25:34
Not sure that I understand what you are doing. When you disable a trigger, it disables it for everybody.

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-08-13 : 18:39:12
I need to disable the trigger when this insertion happens and then after a few things done I want to enable it again.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-13 : 19:05:03
So you would use ALTER TABLE. Syntax of it is in BOL.

Your script would look like this:

ALTER TABLE DISABLE TRIGGER (not exact syntax)
INSERT INTO Table1
ALTER TABLE ENABLE TRIGGER

While that trigger is disabled, it is disabled for everybody, so it will not fire if another user does any DML that would normally fire the trigger.

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-08-13 : 19:23:15
I got it..the syntax is like this....Thanks tduggan
ALTER TABLE table_name DISABLE TRIGGER trigger_name
ALTER TABLE table_name ENABLE TRIGGER trigger_name
Go to Top of Page
   

- Advertisement -