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

前端 未结 20 1566
既然无缘
既然无缘 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 10:09

    It will check whether the given the table is Base Table.

    SELECT 
        T.TABLE_NAME AS 'TABLE NAME',
        C.COLUMN_NAME AS 'COLUMN NAME'
    FROM INFORMATION_SCHEMA.TABLES T
    INNER JOIN INFORMATION_SCHEMA.COLUMNS C ON T.TABLE_NAME=C.TABLE_NAME
        WHERE   T.TABLE_TYPE='BASE TABLE'
                AND T.TABLE_NAME LIKE 'Your Table Name'
    

提交回复
热议问题