Monday, October 31, 2011

Compare Two Databases [TableName,ColumnName ............etc]

SELECT
table_schema,
MIN(Table_Name) AS TableName,
column_name,
column_default,
is_nullable,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale,
column_comment
FROM (
SELECT
table_schema,
Table_Name,
column_name,
ordinal_position,
column_default,
is_nullable,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale,
character_set_name,
collation_name,
column_type,
column_key,
extra,
privileges,
column_comment
FROM information_schema.columns AS i1
WHERE table_schema='DATABASE_NAME1'

 

UNION ALL
SELECT
table_schema,
Table_Name,
column_name,
ordinal_position,
column_default,
is_nullable,
data_type,
character_maximum_length,
numeric_precision,
numeric_scale,
character_set_name,
collation_name,
column_type,
column_key,
extra,
privileges,
column_comment
FROM information_schema.columns AS i2
WHERE table_schema=''DATABASE_NAME2'
) AS tmp
GROUP BY table_name,column_name,data_type
HAVING COUNT(*) = 1
ORDER BY column_name

0 comments:

Post a Comment