如何在数据库中查询出所有有触发器的表?

2025-03-23 06:42:10
推荐回答(2个)
回答1:

select name from sysobjects where xtype='TR' --所有触发器名称
select name from sysobjects where xtype='P' --所有存储过程
select name from sysobjects where xtype='V' --所有视图
select name from sysobjects where xtype='U' --所有表
全部禁用:Alter table t1 disable trigger all;
全部生效:Alter table t1 enable trigger all;
单个禁用:Alter table t1 disable trigger 触发器名;
查出指定TR的内容:sp_helptext 't_test'
查出所有非系统数据库并列出:
select * from sysdatabases where dbid>4
查出某表中所有字段名与字段类型:
select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('employee') and a.xtype=b.xtype!

回答2:

select name 表格名称 from sysobjects where xtype='U' AND id in(select parent_obj from sysobjects where xtype='TR')------查询有触发器的表

select name 表格名称 from sysobjects where xtype='U' AND id NOT in(select parent_obj from sysobjects where xtype='TR')------查询没有触发器的表

有多少触发器用下面的就行:

select a.name 数据表名,sysobjects.name as 触发器名,sysobjects.crdate as 创建时间 from sysobjects
left join (select *from sysobjects where xtype='U')as a on sysobjects.parent_obj=a.id
where sysobjects.xtype='TR'