Suppose I have two tables, t1 and t2 which are identical in layout but which may contain different data.
What\'s the best way to diff these two tables?
In addition to some of the other answers provided, if you wanted to look at the differences in table structure with a table that might have the similar but differing structure, you could do this in multiple ways:
First - If using Oracle SQL Developer, you could run a describe on both tables to compare them:
descr TABLE_NAME1
descr TABLE_NAME2
Second - The first solution may not be ideal for larger tables with a lot of columns. If you only want to see the differences in the data between the two tables, then as mentioned by several others, using the SQL Minus operator should do the job.
Third - If you are using Oracle SQL Developer, and you want to compare the table structure of two tables using different schemas you can do the following:
Fourth - If the tables two tables you wish to compare have more columns, are in the same schema, have no need to compare more than two tables and are unappealing to compare visually using the DESCR command you can use the following to compare the differences in the table structure:
select
a.column_name || ' | ' || b.column_name,
a.data_type || ' | ' || b.data_type,
a.data_length || ' | ' || b.data_length,
a.data_scale || ' | ' || b.data_scale,
a.data_precision || ' | ' || b.data_precision
from
user_tab_columns a,
user_tab_columns b
where
a.table_name = 'TABLE_NAME1'
and b.table_name = 'TABLE_NAME2'
and (
a.data_type <> b.data_type or
a.data_length <> b.data_length or
a.data_scale <> b.data_scale or
a.data_precision <> b.data_precision
)
and a.column_name = b.column_name;