Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

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)

Show content differences between two tables/views

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.


Total article views: 1460 | Views in the last 30 days: 4
Related Articles




Raw File Destination in a loop where OLE source is changing

Dynamically changing sources and destinations


Performance Improvement for Cursors in Stored Procedures

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 => Dynamics AX

Could not complete cursor operation because the table schema changed after the cursor was declared =...



How to Update using Cursors?


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones