SQL Server Performance

Help with Triggers

Discussion in 'SQL Server 2005 General Developer Questions' started by shankbond, Feb 9, 2010.

  1. shankbond New Member

    Hi,
    is it possible to access the elements of the currently inserted row in a table( I have never designed a trigger)
    Please see this table structure
    CREATE TABLE [dbo].[alert](
    [id] [varchar](50) ,
    [alert_message] [varchar](1000)
    ) ;

    when I am Inserting:
    INSERT INTO dbo.alert (id) VALUES ('some value');
    Then a trigger will fire:
    CREATE TRIGGER [Insert_alert]
    ON [dbo].[alert]
    FOR INSERT
    AS
    --
    BEGIN

    --I need to access the currently inserted value(id ) here
    DECLARE @alert_message VARCHAR(1000)

    END

    Please help
  2. FrankKalis Moderator

    Yes, triggers do have access to the inserted & deleted pseudotables. In your case you would refer to the value by inserted.id.
    But maybe you should also have a look at the OUTPUT clause in SQL Server 2005 and above. Depending on what you want to do you may not need a trigger at all.

Share This Page