Sql Trigger - which table does it belong to?

只愿长相守 提交于 2019-12-23 21:44:09

问题


Is there a way within a Sql Server 2005 Trigger to get the name and schema of the table that the trigger is attached to during execution?


回答1:


SELECT
    OBJECT_NAME(parent_id) AS [Table],
    OBJECT_NAME(object_id) AS TriggerName
FROM
    sys.triggers
WHERE
    object_id = @@PROCID

Then you can also use OBJECTPROPERTY to get extra info, such as after/before, delete/insert/update, first/last etc




回答2:


This is a dirty way to know it

SELECT o.name
FROM sysobjects t
JOIN sysobjects o ON t.parent_obj = o.id
WHERE t.name = 'your_trigger_name'

[EDIT]

According to the other answer and the comments, i think this can fit to you (MSSQL2000 version)

SELECT o.name
FROM sysobjects t
JOIN sysobjects o ON t.parent_obj = o.id
WHERE t.id = @@PROCID


来源:https://stackoverflow.com/questions/726993/sql-trigger-which-table-does-it-belong-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!