Table Triggers

  • I am wondering if there is a @@ Global Variable that can be use in a trigger that will supply the name of the table being modified.

    --------------------------------------------------------------------------------

    James Taylor

    Systems Engineer

    E-mail: mailto:James.Taylor@fma.uk.com


    --------------------------------------------------------------------------------


    James Taylor
    Systems Engineer
    E-mail: mailto:James.Taylor@fma.uk.com

  • I don't think that it will exists. But you can query

    select object_name(parent_obj)

    from pubs.dbo.sysobjects

    where xtype = 'TR'

    AND Name = 'trigger_name'

    TO know in witch table the trigger was define, but it doesn't mean that it is the name of the table been modified by the trigger.

  • Not good enough, specially in the case where multi updates participate in same transaction.

    Seem to be working in simple, single updates.

    Need some more grey stuff + time!

    CREATE TRIGGER Test_Trig ON [dbo].[Test] FOR INSERT, UPDATE, DELETE AS

    Select Object_Name(id)

    From Master..SysLocks

    Where dbid=db_id() And

    spid=@@SPID And

    object_name(id) is Not NULL

  • Ive used the following to retrieve the table name;

    declare @TbleName nvarchar(324)

    SET @TbleName=(Select name from sysobjects where sysobjects.id = (select parent_obj from sysobjects where sysobjects.id =@@PROCID))

    Of course then what you do with the @TblName value is up to you, throw it into a table somewhere, or a variable for later use.

    Rick Brown


    Rick Brown

  • Thanks rbrow112, I just could not remember yesterday. Know it was quit uneventfull. Thanks!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply