Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Douwe Miedema,
A while back, i needed a possibility to determine the difference of the contents between a table and a view while on T-sql.
Regulary i had to test the consequences of changing the where clause of a complex view (interfaces),
therefore i wanted to see the differences in the data before and after the change.
So creating a table containing the data according to the old-view-def (select * into tmptb from oldvw)
Then calling ACDIFF TESTDB, newvw, tmptb
gives me the folliwing results:
>Generating Difference program, Parameters: DB=TESTDB, SRC=NEWVW, DST=TMPTB, CMD=S>Showing modifications to be effectuated onto the destination object: PERS_TBL>>SourceObj=(NEWVW ), DestObj=(TMPTB), Using-KEYS:( PERS_ID ), LenPrg=3835/200000>Executing generated Difference program...>INS-ForKey:PERS_ID=(00123224)-Newvalues:(GRON~Groningen~ABC~Jan 1 1901 12:00AM>Total: Compares: 14, Updates: 0, Inserts: 1, Deletes: 0, Command=S
Is shows that one extra record exists in the SRC-view
The program does this by by defining two cursors and walking balanced line through the records, using a key (key is determined by all "not null" columns in the destination-table.
It has helped me a lot to easily monitor the differences for a couple of days via a scheduled job.
Later on I changed it, to also support to update the destination table, I am using it now for some months and it works fine for me.
Be aware, when it returns errors (eg. it couldnt find the specified destination table) then the cursors stay open, when you execute it the next time it gives errors "cursor already open",
just executing again solves that.
Dynamically changing sources and destinations
Exploring some differences between using cursors, local fast forward cursors and using set logic.
Could not complete cursor operation because the table schema changed after the cursor was declared =...
How to Update using Cursors?