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:
- COLUMN_NAME - The name of each column in the table
- ORDINAL_POSITION - The position of the column in the table (1-based)
- DATA_TYPE - The SQL Server data type of the column
Output Format
| Column | Data Type | Description |
|---|---|---|
| COLUMN_NAME | nvarchar | Name of the column |
| ORDINAL_POSITION | int | Position of column in table (1, 2, 3...) |
| DATA_TYPE | nvarchar | SQL Server data type (varchar, int, datetime, etc.) |
Technical Implementation
The script uses:
INFORMATION_SCHEMA.COLUMNSsystem 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
SELECT
COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'Employeesecret'
ORDER BY 2Content Inventory
- Doc File:
content/docs/utilities/list_table_columns.mdx - SQL Script:
SQL/utilities/list_table_columns.sql