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

前端 未结 20 1357
既然无缘
既然无缘 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
    2020-11-22 10:19

    You can obtain this information and much, much more by querying the Information Schema views.

    This sample query:

    SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = N'Customers'
    

    Can be made over all these DB objects:

    • CHECK_CONSTRAINTS
    • COLUMN_DOMAIN_USAGE
    • COLUMN_PRIVILEGES
    • COLUMNS
    • CONSTRAINT_COLUMN_USAGE
    • CONSTRAINT_TABLE_USAGE
    • DOMAIN_CONSTRAINTS
    • DOMAINS
    • KEY_COLUMN_USAGE
    • PARAMETERS
    • REFERENTIAL_CONSTRAINTS
    • ROUTINES
    • ROUTINE_COLUMNS
    • SCHEMATA
    • TABLE_CONSTRAINTS
    • TABLE_PRIVILEGES
    • TABLES
    • VIEW_COLUMN_USAGE
    • VIEW_TABLE_USAGE
    • VIEWS

提交回复
热议问题