Comparing 2 tables 
Author Message
 Comparing 2 tables
Hi
Is there any way I can compare 2 tables in SQL Server ( Data as well as
Strusture)
I have tools to do that, but now I need to do inside a stored procedure .
One idea to compare data-- is  to union both tables and if count(*) of union
table is different from any table then  different.
But , any other ways - to compare structure ...

Thanks



Tue, 16 Aug 2005 04:03:40 GMT
 Comparing 2 tables

Abraham,

The schema of SQL Server tables is pretty much defined in the INFORMATION_SCHEMA views. These are ANSI SQL defined views so you should be able to depend upon them even in future versions of SQL Server (unlike directly accessing the system tables).

The SQL Server Books Online has documentation on the INFORMATION_SCHEMA views.

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.

Quote:

> Hi
> Is there any way I can compare 2 tables in SQL Server ( Data as well as
> Strusture)
> I have tools to do that, but now I need to do inside a stored procedure .
> One idea to compare data-- is  to union both tables and if count(*) of union
> table is different from any table then  different.
> But , any other ways - to compare structure ...

> Thanks



Tue, 16 Aug 2005 04:14:07 GMT
 Comparing 2 tables
Hi Abraham,

For data, we do this as well and we use a query similar to this:




This compares not just the rowcount but the actual contents as well.

For structure, I guess you could look at the system tables (syscolumns,
sysindexes, etc) to see if they're identical.

Randy
ChannelAdvisor Corp.


Quote:
> Hi
> Is there any way I can compare 2 tables in SQL Server ( Data as well as
> Strusture)
> I have tools to do that, but now I need to do inside a stored procedure .
> One idea to compare data-- is  to union both tables and if count(*) of
union
> table is different from any table then  different.
> But , any other ways - to compare structure ...

> Thanks



Tue, 16 Aug 2005 04:31:15 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Comparing two tables and appending data to destination table

2. comparing two tables

3. Comparing 2 tables on 2 different servers

4. Compare two tables

5. Comparing Two Tables for Inaccuracies

6. Compare 2 tables

7. Comparing two tables

8. compare 2 table schemas

9. Compare Two Tables

10. Comparing two tables in SQL 7.0 or SQL 6.5

11. NEWBIE: Comparing two tables using only a where-clause

12. comparing 2 tables


 
Powered by phpBB® Forum Software