Skip to content

Instantly share code, notes, and snippets.

@carltondickson
Created July 1, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carltondickson/288772c69ce479d99673 to your computer and use it in GitHub Desktop.
Save carltondickson/288772c69ce479d99673 to your computer and use it in GitHub Desktop.
Creates SQL that retrieves all tables and row counts for a given schema
SELECT CONCAT(
'SELECT "',
table_name,
'" AS table_name, COUNT(*) AS exact_row_count FROM ',
table_schema,
'.',
table_name,
' UNION '
)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'your_db_here';
@carltondickson
Copy link
Author

Generate many SQL lines such as...

SELECT "FAQ_categories" AS table_name, COUNT(*) AS exact_row_count FROM dbname.FAQ_categories UNION
SELECT "FAQ_titles" AS table_name, COUNT(*) AS exact_row_count FROM dbname.FAQ_titles UNION

Remember to remove the final UNION piece of SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment