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

后端 未结 12 1200
野的像风
野的像风 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条回答
  •  萌比男神i
    2020-12-05 07:30

    MySQL 3 and 4 (and 5):

    desc tablename
    

    which is an alias for

    show fields from tablename
    

    SQL Server (from 2000) and MySQL 5:

    select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS 
    where TABLE_NAME = 'tablename'
    

    Completing the answer: like people below have said, in SQL Server you can also use the stored procedure sp_help

    exec sp_help 'tablename'
    

提交回复
热议问题