views:

295

answers:

2

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-
Unfortunately, I don't know the name of the trigger at runtime either.
You should avoid querying the system tables directly and use the system views instead.
DBAndrew
agree, just that i'm working on sql 2000
Jhonny D. Cano -Leftware-
+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