Search code examples
sqlsql-servercolumnheader

Column Names from SQL Server


I am trying without success to get column names of my table in SQL Server.

I have tried the following:

SELECT * FROM [myDB].INFORMATION_SCHEMA.COLUMNS where [TABLE_NAME] = N'myTable'
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='myTable'

SELECT COLUMN_NAME , * 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable' AND TABLE_SCHEMA='dbo'

SELECT [name] AS [Column Name]
FROM syscolumns
WHERE id = (SELECT id FROM sysobjects WHERE  [Name] = 'myTable')

SELECT c.name FROM sys.columns c
INNER JOIN sys.tables t 
ON t.object_id = c.object_id
AND t.name = 'myTable'

What is being returned is, what I think is, meta data of the table.

enter image description here

While in fact the actual column names are:

column-names2

How can I return the column names from 'myTable'?


Solution

  • This solution returned the list I was looking for

    SELECT name 
    FROM   sys.columns 
    WHERE  object_id = Object_id('myTable')