List tables with the largest number of columns in Azure SQL Database

The query below returns tables with their number of columns, ordered from highest to lowest.

Query

select schema_name(tab.schema_id) + '.' + tab.name as [table], 
       count(*) as [columns]
   from sys.tables as tab
        inner join sys.columns as col
            on tab.object_id = col.object_id
group by schema_name(tab.schema_id), 
       tab.name
order by count(*) desc

Columns

  • table - name of the table (with schema name)
  • columns - number of columns in table

Rows

  • One row: represents one table in a database
  • Ordered by: number of columns in descending order - from tables with the largest number of columns to the lowest

Sample results

0
There are no comments. Click here to write the first comment.