sql server 查询某个表的所有触发器名称

来源:互联网 发布:逆战刷永久枪软件 编辑:程序博客网 时间:2024/05/16 09:44

查出所有用到某个表的SQL

select   *   from   sysobjects   where   xtype='TR'   
select   *   from   sysobjects   where   xtype='TR'   and   parent_obj=object_id('表名')


xtype   char(2)   对象类型。可以是下列对象类型中的一种:     
  C   =   CHECK   约束   
  D   =   默认值或   DEFAULT   约束   
  F   =   FOREIGN   KEY   约束   
  L   =   日志   
  FN   =   标量函数   
  IF   =   内嵌表函数   
  P   =   存储过程   
  PK   =   PRIMARY   KEY   约束(类型是   K)   
  RF   =   复制筛选存储过程   
  S   =   系统表   
  TF   =   表函数   
  TR   =   触发器   
  U   =   用户表   
  UQ   =   UNIQUE   约束(类型是   K)   
  V   =   视图   
  X   =   扩展存储过程  


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'

0 0
原创粉丝点击