我正在使用以下内容从表中获取列名:
SELECT
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = mytable
但需要很长时间才能做出回应。有更快的替代方案吗?
答案 0 :(得分:0)
您可以定义架构并仅选择所需的列:
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
答案 1 :(得分:0)
我选择了mysql + php解决方案
$query = 'EXPLAIN ' . $this->tableName;
$statement = $this->db->prepare($query);
$statement->execute();
while ($row = $statement->fetch()) {
$this->dbColumns[] = $row['Field'];
}
似乎很快