Column Names from SQL Server

﹥>﹥吖頭↗ 提交于 2020-01-21 21:18:06

问题


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.

While in fact the actual column names are:

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


回答1:


This solution returned the list I was looking for

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


来源:https://stackoverflow.com/questions/50183257/column-names-from-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!