0

I have a trigger in a database.

CREATE TRIGGER trigg_varer_ledit_iu
ON items
FOR INSERT, UPDATE
AS
BEGIN
    UPDATE items
    SET lastedit = GETDATE()
    WHERE itemnr IN (SELECT
    itemnr
    FROM inserted)
END;

It works good. Every time I update and insert new data to items the "lastEdit" field is updated.

But: I have some spesific fields in that table that should NOT trigger to update this lastEdit field. How can I achieve that?

Now it works for every fields that is updated. I need to keep some of them out of the circus.

Kannan Kandasamy
  • 13,405
  • 3
  • 25
  • 38
Lars Ørjan Nese
  • 123
  • 2
  • 14
  • i think you can have the logic in the trigger itself to check if the said column is being updated and then return back with out any processing – vamsi Sep 22 '16 at 20:00
  • Any example of that? – Lars Ørjan Nese Sep 22 '16 at 20:08
  • You can use [`update(colname)`](https://msdn.microsoft.com/en-us/library/ms187326.aspx) function to check a single column or [`columns_updated()`](https://msdn.microsoft.com/en-us/library/ms186329.aspx) to check multiple columns. – Alex Kudryashev Sep 22 '16 at 20:30

1 Answers1

0

You can use an if construct to check. For example on updates inserted.column = deleted.column

Related question - Compare deleted and inserted table in SQL Server 2008

Community
  • 1
  • 1
Joe C
  • 3,925
  • 2
  • 11
  • 31