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?
A:
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
Jhonny D. Cano -Leftware-
2009-04-07 18:26:35
Unfortunately, I don't know the name of the trigger at runtime either.
2009-04-07 18:36:44
You should avoid querying the system tables directly and use the system views instead.
DBAndrew
2009-04-07 18:53:21
agree, just that i'm working on sql 2000
Jhonny D. Cano -Leftware-
2009-04-07 18:59:06
+5
A:
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
gbn
2009-04-07 18:48:24