您的位置:首页 > 数据库

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

2014-08-23 14:17 225 查看
查出所有用到某个表的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'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: