SQL: List All Tables and Get Count of Columns Within Each Table

12/17/2021 7:16:22 PM

The following query will list all tables within a database with a count of the columns within that table, sorted by column count desc.


SELECT		TABLE_NAME, COUNT(*) ColumnCount

FROM		INFORMATION_SCHEMA.COLUMNS

WHERE		table_catalog = 'YOUR_DATABASE_NAME'

GROUP BY	TABLE_NAME

ORDER BY	ColumnCount DESC