
Originally Posted by
pilou2
...
I found a way to compare two tables using MySQL derivated tables. It might be usefull to others, so here it is:
This query compares tables 'customers' from two different databases (here 'vanilla' and 'prod').
Code:
SELECT column_name,ordinal_position,data_type,column_type FROM
( SELECT column_name,ordinal_position, data_type,column_type,COUNT(1) rowcount FROM information_schema.columns WHERE
( (table_schema='vanilla' AND table_name='customers') OR (table_schema='prod' AND table_name='customers') )
GROUP BY column_name,ordinal_position, data_type,column_type HAVING COUNT(1)=1 ) A;
...
Well it seems I was tired when I did this post... I use derived table and not 'derivated'... And the SQL query is not optimized at all, there are some useless stuff left over...
The following query returns differences between tables 'products' in databases 'vanilla' and 'prod' based on GROUP BY parameters:
Code:
SELECT db as 'Database',column_name,ordinal_position,data_type,column_type FROM
( SELECT table_schema as db,column_name,ordinal_position,data_type,column_type FROM information_schema.columns WHERE
( (table_schema='vanilla' AND table_name='products') OR (table_schema='prod' AND table_name='products') )
GROUP BY column_name,data_type,column_type HAVING COUNT(1)=1 ) as A
ORDER BY ordinal_position ASC;
Bookmarks