从 sysdatabases 取所有数据库名, 拼动态 SQL 把每个库查询触发器的语句 UNION ALL 起来, 执行 SQL。
declare @str varchar(max) select @str=isnull(@str+' ','')+'union all select '''+name+''' as db,t2.name as tb,t1.name as trg from '+name+'.sys.triggers t1 inner join sys.tables t2 on t1.object_id=t2.object_id' from sys.databases where database_id>4select @str=stuff(@str,1,10,'')exec( @str)
拼动态 SQL 把每个库查询触发器的语句 UNION ALL 起来,
执行 SQL。
select @str=isnull(@str+'
','')+'union all
select '''+name+''' as db,t2.name as tb,t1.name as trg
from '+name+'.sys.triggers t1
inner join sys.tables t2 on t1.object_id=t2.object_id'
from sys.databases
where database_id>4select @str=stuff(@str,1,10,'')exec( @str)