Average number of columns per table in Azure SQL Database

Rene Castro - Dataedo Team Rene Castro 2018-12-10

Table of Contents:

    The query below returns the average number of columns per table in a database.


    select [columns],
        CONVERT(DECIMAL(10,2),1.0*[columns]/[tables]) as average_column_count
    from (
        select count(*) [columns],
               count(distinct schema_name(tab.schema_id) + tab.name) as [tables]
           from sys.tables as tab
                inner join sys.columns as col
                    on tab.object_id = col.object_id
    ) q


    • columns - total number of columns in a database
    • tables - number of tables in a database
    • average_column_count - average number of columns in a table in a database


    • The query returns just one row

    Sample results

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

    By continuing to use our website, you consent to the use of cookies in accordance with our Privacy Policy.