LogoSupport Hub

List Table Columns

List Table Columns

Script: scripts/utilities/list_table_columns.sql

Overview

This utility script retrieves detailed column information for a specific table. It provides column names, ordinal positions, and data types, making it useful for understanding table structure and for documentation purposes.

Parameters

  • TABLE_NAME - The name of the table to analyze (currently hardcoded to 'Employeesecret')

Data Components

The script returns column metadata including:

  1. COLUMN_NAME - The name of each column in the table
  2. ORDINAL_POSITION - The position of the column in the table (1-based)
  3. DATA_TYPE - The SQL Server data type of the column

Output Format

ColumnData TypeDescription
COLUMN_NAMEnvarcharName of the column
ORDINAL_POSITIONintPosition of column in table (1, 2, 3...)
DATA_TYPEnvarcharSQL Server data type (varchar, int, datetime, etc.)

Technical Implementation

The script uses:

  • INFORMATION_SCHEMA.COLUMNS system view
  • Filters by specific table name
  • Orders results by ordinal position for logical column sequence

Notes

  • Currently hardcoded for 'Employeesecret' table - modify TABLE_NAME as needed
  • Can be easily adapted to accept parameters or analyze multiple tables
  • Useful for database documentation and schema analysis
  • Consider adding additional column metadata like nullable, max_length, or default values for more comprehensive analysis

T-SQL

list_table_columns.sql
SELECT
    COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
        TABLE_NAME = 'Employeesecret'
ORDER BY 2

Content Inventory

  • Doc File: content/docs/utilities/list_table_columns.mdx
  • SQL Script: SQL/utilities/list_table_columns.sql