Using IF UPDATE() in SQL Trigger

At times you have to update a particular record only when particular field has been updated. In that case you don’t necessary have to handle that on front end, you can handle that in SQL as well.

If you have a SQL Trigger and you need to make sure SQL Trigger fires only if value of particular field/column has been modified then you can use “IF UPDATE()” in trigger.

Following is the syntax of using the “IF UPDATE()” in SQL trigger,

create trigger trgUpdate 
on employees 
for update 
As 
Begin 
    if update (Dept) 
    Begin 
        update employees 
        set updated=1 
        where id=(select id from inserted) 
    End 
End 

The following line check if the Dept of particular employee has been updated, If it has, then only it executes the further query,

  if update (Dept) 

Hope this helps 🙂