To automate the backup process of the Users
database, I would like to compare the structure of two tables (Users
vs ArchivedUsers
).
I want to compare the columns between both tables to make sure that the the same columns exist, i.e a column like firebase_id
isn't added to the Users
table without being added to the ArchivedUsers
table as well.
A user on stackexchange, @RolandoMySQLDBA, put together a query that compares two tables in a database.
SELECT IF(COUNT(1)>0,'Differences','No Differences') Comparison FROM
(
SELECT
column_name,ordinal_position,
data_type,column_type,COUNT(1) rowcount
FROM information_schema.columns
WHERE table_schema=DATABASE()
AND table_name IN ('users','archived_users')
GROUP BY
column_name,ordinal_position,
data_type,column_type
HAVING COUNT(1)=1
) A;
Can you think of a query that can compare the columns in two tables?