Sunday, February 15, 2009

Enable and disable Trigger in SQL Server

Disable Triggers instead of dropping them.
================================
Business rules in table often expect your application to update the table one row at a time. Also some triggers generate error when the code in the trigger assigns to a local variable returned by selecting a column from the inserted virtual table. The assignment fails if you are updating multiple rows because the inserted table contains more than one row so the sub query returns more than a single value. Multiple updates need special handling in such scenario. Developers often wind up dropping a trigger before multi- row updates then creating them later.

But this scenario can be overcome by disabling trigger

Alter Table Mytable Disable Trigger mytrigger

You can enable Trigger using
Alter Table Mytable Enable Trigger mytrigger

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails