This method would have to go through the whole of both tables each time it's run, even if you just change one value in one table.
I would use an Output clause on your Update statement to just grab the rows and values that are actually changed, for each transaction.
Example:
Update
dbo.Employees
Set
NameLast = @NameLast,
NameFirst = @NameFirst
Output
deleted.EmployeeNumber,
deleted.NameLast,
deleted.NameFirst
Into dbo.LogTable (
EmployeeNumber,
OldNameLast,
OldNameFirst)
Where
EmployeeNumber = @EmployeeNumber
Variations on that will log just the rows that were actually changed.
Would that do what you need?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon