Simple trigger

  • Hi,

    We have a column syncUpdate in some tables and we need a trigger (or one for each table) which will set the current dateTime for the syncLastUpdate (dateTime) when either the row is inserted or updated (we have to ignore the syncLastUpdate column itself as this would be an infinite loop, I think).

    I don't know much about DB but I think that is easly doable.

    Can anyone help me with that, please?

    Cheers

  • can you post DDL of your sample table.

    The only thing needed is an after trigger which fires on inserts and updates.


    * Noel

  • Hi Noel!

    A guy in another forum has helped us with that, the answer is:

    CREATE Trigger [dbo].[contactsLastUpdate] on [dbo].[contacts] for Insert, Update

    AS

    Begin

    Update t

    set syncLastUpdate = GetDate()

    From contacts t

    Join inserted i

    On t.id = i.id

    End

    Work as a charm!!

    Thanks very much

Viewing 3 posts - 1 through 2 (of 2 total)

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