SQL 如何识别与 sybase 数据库中的表关联的触发器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/318528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:21:43  来源:igfitidea点击:

How do you identify the triggers associated with a table in a sybase database?

sqltriggerssybase

提问by Bill Rawlinson

I am using SQL Advantage and need to know what the SQL is to identify the triggers associated with a table. I don't have the option to use another tool so the good old fashioned SQL solution is the ideal answer.

我正在使用 SQL Advantage 并且需要知道 SQL 是什么来识别与表关联的触发器。我没有使用其他工具的选项,所以好的老式 SQL 解决方案是理想的答案。

回答by Bill Rawlinson

I also found out that

我也发现

sp_depends <object_name> 

will show you a lot of information about a table, including all triggers associated with it. Using that, along with Ray's query can make it much easier to find the triggers. Combined with this query from Ray's linked article:

将向您显示有关表的大量信息,包括与其关联的所有触发器。使用它以及 Ray 的查询可以更容易地找到触发器。结合 Ray 链接文章中的查询:

sp_helptext <trigger_name>

and you can see the definition of the trigger:

你可以看到触发器的定义:

sp_depends <trigger_name>

will also show you all tables related to a trigger

还将向您显示与触发器相关的所有表

回答by Ray

select *
from sysobjects
where type = 'TR'

Taken from here.

取自这里

回答by Richard

to show triggers and create sql for a table:

显示触发器并为表创建 sql:

select so.name, text
from sysobjects so, syscomments sc
where type = 'TR'
and so.id = sc.id
and text like '%TABLENAME%'

回答by Annie

SELECT 
    T.name AS TableName
    ,O.name  TriggerName  
    FROM sysobjects O 
    INNER JOIN sys.tables T ON T.object_id = O.parent_obj
    WHERE O.type = 'TR' AND T.name IN ('tableNames')
ORDER BY TableName

回答by John MacIntyre

I believe there is (or at least 'was') some issue where dependency information is not always accurate. Therefore I would attempt to approach it like this :

我相信存在(或至少“曾经”)一些依赖信息并不总是准确的问题。因此,我会尝试像这样处理它:

select name
from sysobjects
where xtype='TR'
and id in (select id from syscomments where text like '%MY-TABLE-NAME%')

Good luck.

祝你好运。

PS-This is untested code, leave a comment if it doesn't work, and I'll fix it.

PS-这是未经测试的代码,如果不起作用,请发表评论,我会修复它。

回答by Mark Meuer

  1. Open Sybase Central and navigate to the triggers view.
  2. Click on the "Object Name" column to sort.
  1. 打开 Sybase Central 并导航到触发器视图。
  2. 单击“对象名称”列进行排序。

The "Object Name" column apparently shows the table associated with the trigger. Scroll down to the table you're interested in.

“对象名称”列显然显示了与触发器关联的表。向下滚动到您感兴趣的表格。

回答by Tim

I would use following code, to make sure you're getting the right objects. Since Sybase 16 this won't be complete anymore, as there might be more triggers of the same type on one table.

我会使用以下代码,以确保您获得正确的对象。从 Sybase 16 开始,这将不再完整,因为一张表上可能有更多相同类型的触发器。

    select tr.id, tr.name, tr.type, tr.crdate, tr.loginame
from sysobjects u
  join sysobjects tr on tr.id in (u.instrig, u.deltrig, u.updtrig, u.seltrig)
where u.name = 'TABLENAME'

回答by Weihui Guo

I am using SQL Anywhere 16 and it's easy to find the triggers of a specific table. When you open the table, there is a tab named 'Triggers'. But the query to find all the triggers is a bit different from the answers above:

我使用的是 SQL Anywhere 16,很容易找到特定表的触发器。当您打开表格时,会出现一个名为“触发器”的选项卡。但是查找所有触发器的查询与上面的答案有点不同:

select * from SYS.SYSTRIGGERS --where trigdefn like '%exec%'