sql - Update Trigger only update if the data has changed -


i have update trigger updates null records when record update in table. problem data in gridview, , when update runs update query on records in grid not updated record. when trigger fires updates every row in target table matches want update 1 data has changed. here trigger.

alter trigger [dbo].[trigger_update_deschedule] on [dbo].[tbatchdetails]      after update ,insert      begin set nocount on     declare @batchid int           , @ethanol varchar(10)           , @glucose varchar(10)           , @sampleage varchar(10);      select @batchid = b.[batchid]         ,@ethanol = [ethanol]         ,@glucose= [glucose]         ,@sampleage = sa.sampleage       inserted bd         inner join  [dbo].[tsampleage] sa on sa.sampleageid = bd.sampleage          inner join  [dbo].[tbatch] b on b.id =bd.id      update [dbo].[deschedule]      set [ethanol] = @ethanol       , [glucose] = @glucose       , [samplecompleted] = 1      [batchid] = @batchid          , [sampleage] = @sampleage          , siteid = 6          , samplecompleted null  end 

how can in trigger update record data has changed in?

this long comment.

first thing should separate insert , update triggers. doing them in single trigger causes problems. going cause problems here. code posted should looking when insert.

however, when update need add join deleted. , need add predicates every column in base table. way know if actual value has changed compare values inserted , deleted.

something this:

i.cola <> d.cola  or i.colb <> d.colb etc... 

some may use update function not work you. returns true if column in list of values being updated. not care if value same before.

and current trigger using scalar values. not approach trigger fires once per operation. code needs set based.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -