List columns by name length in SQL Server database

This query returns columns in a database sorted by their name.

Query

select col.name as column_name,
    len(col.name) as column_name_length,
    schema_name(tab.schema_id) as schema_name,
    tab.name as table_name
 from sys.tables as tab
        inner join sys.columns as col 
        on tab.object_id = col.object_id
order by len(col.name) desc,
    col.name

Columns

  • column_name - column name
  • column_name_length - column name length
  • schema_name - column table schema name
  • table_name - column table name

Rows

  • One row represents one column of each table in a database
  • Scope of rows: each column that exists in a database
  • Ordered by length descrending - from longhest to shortest

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.