I was curious about some of the databases I get to work with.
“How do my clients store their data? What data types are most
prevalent?” Well, a few keystrokes later, I had my answers:
SELECT c.data_type, count(c.data_type) AS frequency
FROM information_schema.columns AS c
INNER JOIN information_schema.tables AS t
ON c.table_schema = t.table_schema AND
c.table_name = t.table_name
WHERE c.table_schema NOT IN ('information_schema','mysql')
AND
t.table_type = 'base table'
GROUP BY data_type;
Which gave me a nice “data type distribution” table:
| data_type | frequency |
|---|---|
| blob | 7 |
| char | 611 |
| date | 85 |
| … |