How can I get column names from a table in SQL Server?

前端 未结 20 1313
既然无缘
既然无缘 2020-11-22 09:29

I want to query the name of all columns of a table. I found how to do this in:

  • Oracle
  • MySQL
  • PostgreSQL

But I also need to know:

20条回答
  •  抹茶落季
    2020-11-22 10:13

    One other option which is arguably more intuitive is:

    SELECT [name] 
    FROM sys.columns 
    WHERE object_id = OBJECT_ID('[yourSchemaType].[yourTableName]') 
    

    This gives you all your column names in a single column. If you care about other metadata, you can change edit the SELECT STATEMENT TO SELECT *.

提交回复
热议问题