I've got a trigger that we thought would only update when among the posts was up-to-date not the table. It is possible to method to rewrite this therefore it only fires once the specified posts are up-to-date not other fields inside the table
CREATE TRIGGER [afm].[afm_rm_dwgs_t] ON [afm].[rm] FOR UPDATE AS IF (UPDATE(area) OR UPDATE(dv_id) OR UPDATE(dp_id) OR UPDATE(rm_cat) OR UPDATE(rm_type) OR UPDATE(rm_std)) BEGIN SET NOCOUNT ON; UPDATE afm.afm_dwgs SET dwg_updt = 1 WHERE afm_dwgs.dwg_name IN (SELECT dwgname FROM inserted) END
No, the trigger is understood to be FOR UPDATE ON [afm].[rm], so it'll always fire for every update on that table. There is no method to restrict that upfront.
Your check within the trigger will eliminate any "unnecessary" trigger activations from really doing anything.
suppose that you would like to see if the region column is up-to-date, then your code may be like this:
declare @oldArea varchar(50) declare @newArea varchar(50) select @oldArea= area from deleted select @newArea=area from inserted if ( @oldArea <> @newArea) -- area is updated
UPDATE() only implies that the column was incorporated within the data set. It can make no representation whether the actual information is different.
You will need to get a bit more complicated than this.
You have to compare the Erased and Placed values to be able to find out if there's a big change.
Check this link for a bit more information.