我正在使用以下内容从表中获取列名:
SELECT
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = mytable
但是需要很长时间才能做出反应。有更快的选择吗?
我选择了 mysql + php 解决方案
$query = 'EXPLAIN ' . $this->tableName;
$statement = $this->db->prepare($query);
$statement->execute();
while ($row = $statement->fetch()) {
$this->dbColumns[] = $row['Field'];
}
看起来相当快
您可以定义架构并仅选择您需要的列:
SELECT table_schema,
table_name,
column_name,
data_type,
character_maximum_length,
is_nullable,
column_default,
numeric_precision,
numeric_scale
FROM information_schema.columns
WHERE table_name = 'yourtable'
AND table_schema = 'yourschema'
ORDER BY table_schema,
table_name,
ordinal_position