Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a trigger, you have access to the 'inserted' and 'deleted' system tables. Those tables contains the records in the table that have been updated by the statement that caused the trigger to execute.</p> <p>For an 'UPDATE' trigger, the 'inserted' table contains the records like they are in the new state, the 'deleted' table contains the records with the old values.</p> <p>You'll have to make use of those 2 tables to find out which records have really changed, and update the ModificationDate for those records.</p> <p>I think the statement inside the trigger will look something like this. (I haven't tested it)</p> <pre><code>UPDATE myTable SET ModificationDate = getdate() FROM inserted, deleted WHERE inserted.EmployeeId = deleted.EmployeeId AND (inserted.Name &lt;&gt; deleted.Name OR inserted.Address &lt;&gt; deleted.Address) </code></pre> <hr> <p>Edit: I've played around a bit:</p> <pre><code>create trigger upd_employee on [employee] after update as begin update employee set modifdate = getdate() where employee.empid in ( select i.empid from inserted i inner join deleted d on i.empid = d.empid where (i.name &lt;&gt; d.name or i.address &lt;&gt; d.address ) ) end insert into employee values (1, 'Frederik' , '', null) insert into employee values (2, 'User', '', null) update employee set [address] = 'some address' select * from employee update employee set [name] = 'test' where empid = 2 select * from employee update employee set [name] = 'test' where empid = 2 select * from employee </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload