MySQL: how to get list of fields in a table using ODBC

I am connecting to MySQL database via terminal which only has a program with ODBC connection to MySQL database. I can put queries into the program, but not directly access MySQL.

Is there a way to query the DB to get a list of fields in a table other than

select * from table

      

??

(not sure why, but selection returns an error)

+1


source to share


4 answers


describe *tablename*

      



+1


source


SELECT
  COLUMN_NAME
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_NAME       = 'MyTable'
  AND TABLE_SCHEMA = 'SchemaName'  /* added upon Bill Karwin comment (thanks) */

      



More information on INFORMATION_SCHEMA in the docs .

+3


source


This works in most databases:

select * from table where 1 = 0

You don't get the data in the result set, but you get the column metadata.

+1


source


It:

SHOW COLUMNS FROM Tablename

      

lists the fields in the table and their properties (data type, whether null values ​​are allowed, whether the field is a primary key, the default value if set, etc.)

0


source