Web Code Blog

A web repository of coding tips and knowledge base articles

Archive for October, 2010

Disable all triggers for a database

Posted by Stefan Zvonar on October 4, 2010

Here is a nice little bit of T-SQL that will help with your scripting woes.

Ever wanted to disable all triggers in a database so you can merrily import or merge data and other such tasks?

Well here is what you can do, it simply disables all triggers for all tables in your active database and then enables them again at the end of your changes.


----------------------------------------------------------
EXEC sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
----------------------------------------------------------

-- Write some SQL Modifications here

---------------------------------------------------------
EXEC sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
---------------------------------------------------------

Hope this helps,

Stefan.

For more Web Code, ASP.NET, SQL Server and other development tips, please check back here at webcodeblog.com often.

Posted in SQL Server | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.