Subject | Tracking changes to records / triggers |
---|---|
Author | Robert martin |
Post date | 2009-09-24T22:26:19Z |
Hi
We have some update triggers that we use to track if any change has
occurred to a record in a table. These are sometimes used to transfer
information to web sites (for example) only when data has changed.
Sometimes however we recalculate values in records based on changes in
other tables. When we do this the values do not often change but our
trigger counts that as a change and 'marks' the record as updated. To
avoid this we could change our trigger to compare the Old and New field
values. This however has a large ongoing maintenance cost, if we change
a record (adding or deleting) a field we would need to also remember to
change the associated trigger (s).
Is it possible to write a trigger like....
Changed := False;
Counter := 0;
while (counter < Record.FieldCount) and (Changed = False) do begin
if (old.Fields[Counter] <> new.Fields[Counter]) then begin
Changed := True;
end;
end;
If (Changed = True) then begin
//Marke record as changed
end
A trigger such as the above would deal with any record structure
changes. Is it possible? Would it be a major performance hit?
Do I have any other options?
TIA
Rob
We have some update triggers that we use to track if any change has
occurred to a record in a table. These are sometimes used to transfer
information to web sites (for example) only when data has changed.
Sometimes however we recalculate values in records based on changes in
other tables. When we do this the values do not often change but our
trigger counts that as a change and 'marks' the record as updated. To
avoid this we could change our trigger to compare the Old and New field
values. This however has a large ongoing maintenance cost, if we change
a record (adding or deleting) a field we would need to also remember to
change the associated trigger (s).
Is it possible to write a trigger like....
Changed := False;
Counter := 0;
while (counter < Record.FieldCount) and (Changed = False) do begin
if (old.Fields[Counter] <> new.Fields[Counter]) then begin
Changed := True;
end;
end;
If (Changed = True) then begin
//Marke record as changed
end
A trigger such as the above would deal with any record structure
changes. Is it possible? Would it be a major performance hit?
Do I have any other options?
TIA
Rob