Get column name length distribution in SQL Server database

Query below returns distribution of column name lengths (number of characters).

Query

select len(col.name) as column_name_length,
       count(*) as columns,
       count(distinct tab.object_id) as tables
   from sys.tables as tab
       inner join sys.columns as col 
       on tab.object_id = col.object_id
group by len(col.name)
order by len(col.name)

Columns

  • column_name_length - lenght in characters of column name
  • columns - number of columns with this length
  • tables - number of tables that have columns with this name length

Rows

  • One row represents one name lenght (number of characters)
  • Scope of rows: each column length that exists in a database
  • Ordered by length ascending (from 1 to max)

Sample results

If you put it into chart it looks like this: