SQL Column Names From Table | SJB -->

This website uses cookies to ensure you get the best experience. More info...

Pages

SQL Column Names From Table

Below is the effective query to get column names from a SQL table. We will use INFORMATION_SCHEMA to get the task done.

1
2
3
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'TableName'
In the alternate example below, we will use sys.columns to get the task done.
1
2
3
SELECT name
FROM sys.columns
WHERE object_id = OBJECT_ID('TableName')

No comments:

Post a Comment