This query returns the columns in a database sorted by their name length.
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 - name of the column
- column_name_length - length of the column name
- schema_name - schema name of the column table
- table_name - table name of the column
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 descending - from longest to shortest