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.
| 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 |
 |
|
|
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 thatthe trigger is turned on and then the events will be fired with the updateHow can I use alter table here |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
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 Table1ALTER TABLE ENABLE TRIGGERWhile 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 |
 |
|
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-08-13 : 19:23:15
|
| I got it..the syntax is like this....Thanks tdugganALTER TABLE table_name DISABLE TRIGGER trigger_name ALTER TABLE table_name ENABLE TRIGGER trigger_name |
 |
|
|
|
|
|