How to get column names from a table in SQL Server?

7

Languages table:

HowdoIselecttheColumnNamesofthistable?

Theresultwouldbe:

"IDIdioma", "Sigla" and "IDioma".     

asked by anonymous 02.03.2017 / 14:20

2 answers

9

Another way to get the column names of some table is by using sys.columns using the object_id () function that gets the name of the table / view and returns its internal id. / p>

This works from SQL Server 2008

SELECT * FROM sys.columns WHERE object_id = object_id('nome_tabela')

Reference: How do you return the column names from a table?

    
03.03.2017 / 01:14
11

Make a select in INFORMATION_SCHEMA.COLUMNS asking for the COLUMN_NAME column. In INFORMATION_SCHEMA.COLUMNS you have information about all the columns for all the tables in a database schema.

Query:

SELECT COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'NomedaTabela'

SQLFiddle

    
02.03.2017 / 14:35