SQL SERVER – Enabling or Disabling Triggers with the Correct Scope

To disable all triggers correctly, I first identify the required scope. My original customer case concerned expensive table-trigger work.

Drawer, work-area and cabinet latches remain distinct beside one inspected fitting.

SELECT name,is_disabled,parent_class_desc FROM sys.triggers ORDER BY name;
SELECT name,is_disabled FROM sys.server_triggers ORDER BY name;
-- Targeted table trigger examples, after preserving original states:
-- DISABLE TRIGGER dbo.YourTrigger ON dbo.YourTable;
-- ENABLE TRIGGER dbo.YourTrigger ON dbo.YourTable;
-- Historical server-scope statements, not table-trigger controls:
-- DISABLE TRIGGER ALL ON ALL SERVER;
-- ENABLE TRIGGER ALL ON ALL SERVER;

Table or view DML triggers use ON schema.object. Database DDL triggers use ON DATABASE. Server DDL and logon triggers use ON ALL SERVER. The last form does not disable every table trigger.

The customer’s system improved when problematic trigger work was removed. That observation does not justify blanket disabling. Triggers can enforce auditing, business rules and replication behavior. Application replacements need every writer to follow the required workflow.

Inventory definitions and enabled states. Test a named change on a copy and preserve required behavior. Restore recorded states afterward. ENABLE ALL can unintentionally activate previously disabled triggers.

Reference: Trigger scope and permissions.

Related reading

A server-scoped trigger command is not a database-wide table-trigger command, it is an operation in a different scope.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Scripts, SQL Server, SQL Trigger
Previous Post
SQL SERVER – Function to Calculate Simple Interest
Next Post
SQL SERVER – List Service Broker Queue Count

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.