获取表列的速度比信息模式更快?

时间:2013-10-24 15:35:54

标签: mysql sql

我正在使用以下内容从表中获取列名:

SELECT
    COLUMN_NAME
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
    TABLE_NAME = mytable

但需要很长时间才能做出回应。有更快的替代方案吗?

2 个答案:

答案 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'];
        }

似乎很快