question

tabularyee avatar image
tabularyee asked

Get trigger's parent object id

Hi all, The following
SELECT object_name(parent_id) from sys.triggers where name = 'tr1'
Will return the parent table name from within the trigger, but I was wondering if it's possible to return the parent's object id? I thought object_id may do that but returns null. Any help would be much appreciated. Thanks
sql-server-2008trigger
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mrs_Fatherjack avatar image
Mrs_Fatherjack answered
The Parent_obj column brings back the parent table's object id. To prove it run this: SELECT C.name, P.name, P.id, * FROM sysobjects C JOIN sysobjects P ON C.parent_obj = P.id WHERE C.name = 'enter trigger name here'
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
Be careful using those SQL 2000 system tables
1 Like 1 ·
Mrs_Fatherjack avatar image Mrs_Fatherjack commented ·
That's because we are still on SQL 2000 :(
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
Ouch! :(
0 Likes 0 ·
KenJ avatar image
KenJ answered
`parent_id` is the parent object's `object_id`. Check out `parent_id` in books-online - [ http://msdn.microsoft.com/en-us/library/ms188746.aspx][1] [1]: http://msdn.microsoft.com/en-us/library/ms188746.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.