check if all table rows are equal

Abe's answer is correct, but only if they have the same number of rows. (I misread the question when I wrote my original response "condemning" his answer.) If table1 may be a subset of (a larger) table2 or vice versa, I would try:

if 
(
not exists ( select * from table1
             except
             select * from table2
           )
and
not exists ( select * from table2
             except
             select * from table1
           )
)

This gives true if they are the same, and false if they are different.


Try this:

SELECT * FROM table1
EXCEPT
SELECT * FROM table2

If anything is returned then they are not equal.

Tags:

Sql

Sql Server