Quantcast
Channel: Questions in topic: "distinct"
Viewing all articles
Browse latest Browse all 38

How to return mismatched rows from two tables?

$
0
0
I have created two tables in the same database as below which gives the row count of tables across all databases before and after an DB restore operation. CREATE TABLE before_restore ( db_name VARCHAR(100) , table_name VARCHAR(1000) , row_count INT ) INSERT INTO before_restore EXEC sp_msforeachdb 'USE [?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by o.name' CREATE TABLE after_restore ( db_name VARCHAR(100) , table_name VARCHAR(1000) , row_count INT ) INSERT INTO after_restore EXEC sp_msforeachdb 'USE [?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by o.name' I want to compare these two tables and it should only return me rows that have changed after the restore operation is complete. Eg: Table xyz has rowcount of 100 before restore and the restore was not proper and after restore count is 50. So it should return me the result set as below; Db_name Table_Name row_count_before_restore row_count_after_restore abc xyz 100 50 Thanks!!!

Viewing all articles
Browse latest Browse all 38

Trending Articles