Sql Trigger - in which table does it belong?

Is there a way in a Sql Server 2005 trigger to get the name and schema of the table to which the trigger is connected at run time?

+3
source share
2 answers
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 additional information, like after / before, delete / insert / update, first / last, etc.

+12
source

This is a dirty way to find out.

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

[EDIT]

According to another answer and comments, I think this can fit you (version MSSQL2000)

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

Source: https://habr.com/ru/post/1706065/


All Articles