MySQL:如何使用ODBC获取表中的字段列表

时间:2022-10-21 23:37:36

I am connecting to a MySQL DB trough a terminal who only have a program with an ODBC connection to a MySQL DB. I can put querys in the program, but not access MySQL directly.

我通过终端连接到MySQL数据库,该终端只有一个与MySQL数据库建立ODBC连接的程序。我可以在程序中放置查询,但不能直接访问MySQL。

I there a way to query the DB to obtain the list of fields in a table other than

我有办法查询数据库以获取除表之外的表中的字段列表

select * from table

??

(don't know why but the select returns a error)

(不知道为什么但是select返回错误)

4 个解决方案

#1


1  

describe *tablename*

#2


3  

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

More info on INFORMATION_SCHEMA is in the docs.

有关INFORMATION_SCHEMA的更多信息,请参阅文档。

#3


1  

This works on most databases:

这适用于大多数数据库:

select * from table where 1=0

select * from table from 1 = 0

You get no data in the result set but you do get the column metadata.

结果集中没有数据,但您确实获得了列元数据。

#4


0  

This:

SHOW COLUMNS FROM Tablename

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

列出表中的字段及其属性(数据类型,是否允许空值,字段是否为主键,默认值是否已设置,等等)

#1


1  

describe *tablename*

#2


3  

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

More info on INFORMATION_SCHEMA is in the docs.

有关INFORMATION_SCHEMA的更多信息,请参阅文档。

#3


1  

This works on most databases:

这适用于大多数数据库:

select * from table where 1=0

select * from table from 1 = 0

You get no data in the result set but you do get the column metadata.

结果集中没有数据,但您确实获得了列元数据。

#4


0  

This:

SHOW COLUMNS FROM Tablename

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

列出表中的字段及其属性(数据类型,是否允许空值,字段是否为主键,默认值是否已设置,等等)