代码之家  ›  专栏  ›  技术社区  ›  Sir Robert

如何从mysql表访问表注释?

  •  20
  • Sir Robert  · 技术社区  · 14 年前

    我怎么才能得到 只是 来自mysql表的表注释?我试过下面的方法,但由于种种原因,它们没有起作用。我想知道如何只获取字符串'my comment'(理想情况下是通过perl=)

    -- Abbreviated output for convenience.
    SHOW TABLE STATUS WHERE Name="foo"
    +------+--------+---------+------------+------+----------------+---------------+
    | Name | Engine | Version | Row_format | Rows | Create_options | Comment       |
    +------+--------+---------+------------+------+----------------+---------------+
    | foo  | MyISAM |      10 | Fixed      |    0 |                | my comment    | 
    +------+--------+---------+------------+------+----------------+---------------+
    

    SHOW CREATE TABLE foo;
    +-------+------------------------------------------------------------------------------+
    | Table | Create Table                                                                 |
    +-------+------------------------------------------------------------------------------+
    | fooo  | CREATE TABLE `fooo` (`id` int(11) NOT NULL PRIMARY KEY) COMMENT='my comment' | 
    +-------+------------------------------------------------------------------------------+
    
    2 回复  |  直到 7 年前
        1
  •  43
  •   Equal    5 年前

    基于答案 OMG小马 INFORMATION_SCHEMA.TABLES 而不是 INFORMATION_SCHEMA.COLUMNS 桌子的 评论。

    SELECT table_comment 
        FROM INFORMATION_SCHEMA.TABLES 
        WHERE table_schema='my_cool_database' 
            AND table_name='user_skill';
    
    +--------------------------+
    | table_comment            |
    +--------------------------+
    | my awesome comment       | 
    +--------------------------+
    
        2
  •  3
  •   Jerry    7 年前

    SHOW TABLE STATUS WHERE Name='table_name';