SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need to get list of disable and enable triggers from server


Need to get list of disable and enable triggers from server

Author
Message
pols
pols
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 172
Hi,

I need to findout the list of enable and disable triggers from all the databses in server.
Pls help me.

The below query to get the list of triggers from all the dbs in server.But i need to know the disable and enable triggers in this.


Declare @sql varchar(MAX)
Set @sql = ''

Select @sql = @sql + 'USE ' + name + '
select '''+name+''' as DBName, p.name as [TableName], o.name, o.deltrig, o.instrig, o.updtrig
from sysobjects o
left outer join sysobjects p ON p.id = o.parent_obj
where o.type=''TR''
'
from master..sysdatabases
Where DBID > 4 --skip the system databases

EXEC (@sql)



Thanks
pols
pols
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 172
Got it.Smile


Declare @sql nvarchar(MAX)
Set @sql = ''

Select @sql = @sql + 'USE ' + name + '
select '''+name+''' as DBName, p.name as [TableName], o.name, o.deltrig, o.instrig, o.updtrig,
t.is_disabled
from sysobjects o
left outer join sysobjects p ON p.id = o.parent_obj
inner join sys.triggers t on t.object_id = o.id
where o.type=''TR''
'
from master..sysdatabases
Where DBID > 4 --skip the system databases
EXEC (@sql)
Nabha
Nabha
SSC Eights!
SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)SSC Eights! (933 reputation)

Group: General Forum Members
Points: 933 Visits: 1814
Another way would be this!


select CASE OBJECTPROPERTY(OBJECT_ID(name), 'ExecIsTriggerDisabled')
WHEN 1 THEN 'Disabled'
ELSE 'Enabled' END as Status
from sysobjects o
where o.type='TR'



---------------------------------------------------------------------------------
Adi Cohn
Adi Cohn
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3727 Visits: 6512
You can use the objectproperty function to check if the trigger is enabled. If you don’t mind getting it in few recordsets, you can also use the undocumented procedure sp_MSforeachdb that will run the statement on all databases. Notice that since this is an undocumented procedure I use it on my own scripts, but I never use it in a real production application.

exec sp_MSforeachdb 'use ? if DB_ID()>4 select ''?'' as DBName, name,
objectproperty(object_id,''ExecIsTriggerDisabled'') as IsDisabled
from sys.objects
where type = ''TR'''



Adi

--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
pols
pols
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 172
Thanks for replying..Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search