SQL Server 2005: T-SQL to temporarily disable a trigger

前端 未结 7 1127
太阳男子
太阳男子 2020-12-08 04:33

Is it possible to disable a trigger for a batch of commands and then enable it when the batch is done?

I\'m sure I could drop the trigger and re-add it but I was won

7条回答
  •  借酒劲吻你
    2020-12-08 04:45

    However, it is almost always a bad idea to do this. You will mess with the integrity of the database. Do not do it without considering the ramifications and checking with the dbas if you have them.

    If you do follow Matt's code be sure to remember to turn the trigger back on. ANd remember the trigger is disabled for everyone inserting, updating or deleting from the table while it is turned off, not just for your process, so if it must be done, then do it during the hours when the database is least active (and preferably in single user mode).

    If you need to do this to import a large amount of data, then consider that bulk insert does not fire the triggers. But then your process after the bulk insert will have to fix up any data integrity problems you introduce by nor firing the triggers.

提交回复
热议问题