trigger

  •  I am using the follwing trigger where it updates all records in lastmodified column to current date when there is an update on the table but wht i need is, i just want to update only those records where there is a an update . pls help.

    CREATE TRIGGER Q_U on dbo.Quarter

    FOR UPDATE

    AS

    BEGIN

    UPDATE Quarter

    SET LastModified = getdate()

    END

  • To say directly what i need...

    I have to get the modified date n time automatically of a single record when it is changed. How can I do tht?

  • Hi..

    Y u trying trigger only..u can u simple procedure also

    like

    create proc update_test

    @id int

    as

    begin

    update test_table

    set Date_test = getdate()

    where id = @id

    end


    Regards,

    Papillon

  • Post the DDL of the table, or at least tell us what the primary key is, and we'll show you how to join to the inserted virtual table to update only the updated row or rows.

     

  • Like PW said change pkey in the join for your primary key column(s)

     

    CREATE TRIGGER Q_U on dbo.Quarter

    FOR UPDATE

    AS

    BEGIN

    if @@rowcount = 0 return

    UPDATE Q SET LastModified = getdate()

    FROM Quarter Q join inserted i on Q.pkey = i.pkey

    END

     

    Cheers,

     


    * Noel

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

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