What is the SQL command to return the field names of a table?

后端 未结 12 1172
野的像风
野的像风 2020-12-05 07:03

Say I have a table called myTable. What is the SQL command to return all of the field names of this table? If the answer is database specific then I need SQL Server right

相关标签:
12条回答
  • 2020-12-05 07:05

    MySQL

    describe tablename
    
    0 讨论(0)
  • 2020-12-05 07:06

    For those looking for an answer in Oracle:

    SELECT column_name FROM user_tab_columns WHERE table_name = 'TABLENAME'
    
    0 讨论(0)
  • 2020-12-05 07:13

    MySQL is the same:

    select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tablename'
    
    0 讨论(0)
  • 2020-12-05 07:20

    PostgreSQL understands the

    select column_name from information_schema.columns where table_name = 'myTable'
    

    syntax. If you're working in the psql shell, you can also use

    \d myTable
    

    for a description (columns, and their datatypes and constraints)

    0 讨论(0)
  • 2020-12-05 07:21

    In Sybase SQL Anywhere, the columns and table information are stored separately, so you need a join:

    select c.column_name from systabcol c 
           key join systab t on t.table_id=c.table_id 
           where t.table_name='tablename'
    
    0 讨论(0)
  • 2020-12-05 07:24

    This is also MySQL Specific:

    show fields from [tablename];
    

    this doesnt just show the table names but it also pulls out all the info about the fields.

    0 讨论(0)
提交回复
热议问题