Below is the effective query to get column names from a SQL table. We will use INFORMATION_SCHEMA to get the task done.
123SELECT
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.
123SELECT
name
FROM
sys.columns
WHERE
object_id = OBJECT_ID(
'TableName'
)
No comments:
Post a Comment