Have you ever spent hours looking at an issue only to have your investigation hindered by a trigger? I know I have and on more than one occasion! This little script can be added to a SQL Agent Job and scheduled as you require to email an operator with a list of all triggers for all user databases, the table they are on and the status.
----------------------------------------------------------------- ----------------------------------------------------------------- For more SQL resources, check out SQLServer365.blogspot.com ----------------------------------------------------------------- You may alter this code for your own purposes. You may republish altered code as long as you give due credit. You must obtain prior permission before blogging this code. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" ----------------------------------------------------------------- DECLARE@EmailProfile VARCHAR(255) DECLARE@EmailRecipient VARCHAR(255) DECLARE@EmailSubject VARCHAR(255) SET@EmailProfile = 'SQLReports'; --Drop temporary table if exists IF OBJECT_ID('tempDB.dbo.#TriggerStatus')IS NOT NULL DROP TABLE #TriggerStatus ; -- Create temporary table CREATE TABLE #TriggerStatus TriggerName VARCHAR(255), INSERT INTO #TriggerStatus IF ''?'' NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''distribution'', ''reportserver'', ''reportservertempdb'') SELECT DB_NAME() AS DatabaseName, OBJECT_NAME(parent_id) AS TableName, FROM sys.triggers WITH ( NOLOCK ) -- Check for unused indexes DECLARE@tableHTML NVARCHAR(MAX); SET@tableHTML = N'<style type="text/css">' + N'.h1 {font-family: Arial, verdana;font-size:16px;border:0px;background-color:white;} ' + N'.h2 {font-family: Arial, verdana;font-size:12px;border:0px;background-color:white;} ' + N'body {font-family: Arial, verdana;} ' + N'table{font-size:12px; border-collapse:collapse;border:1px solid black; padding:3px;} ' + N'td{background-color:#F1F1F1; border:1px solid black; padding:3px;} ' + N'th{background-color:#99CCFF; border:1px solid black; padding:3px;}' + N'</style>' + N'<table border="1">' + N'<tr>' + N'<th>DatabaseName</th>' + N'<th>TriggerName</th>' + N'<th>TriggerStatus</th>' + CAST(( SELECT td =DatabaseName, )AS NVARCHAR(MAX)) + N'</table>'; SET @EmailSubject = 'Trigger Status Report For ' + @@SERVERNAME EXECmsdb.dbo.sp_send_dbmail @profile_name = @EmailProfile, @recipients = @EmailRecipient, @subject = @EmailSubject, @body =@tableHTML, @body_format = 'HTML'; Remember, fully understanding your environment, the features you use and what is the norm is something that pays dividends when things go bad.
Enjoy!
Chris