如何从 mysql 表访问表注释?

发布于 2024-09-27 16:58:25 字数 1115 浏览 0 评论 0原文

如何从 mysql 表中获取只是表注释?我尝试了以下方法,但由于各种原因它们没有工作。我想弄清楚如何获取字符串“我的评论”(最好通过 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' | 
+-------+------------------------------------------------------------------------------+

How can I get just the table comment from a mysql table? I tried the following, but they didn't work for various reasons. I want to figure out how to get just the string 'my comment' (ideally via perl =)

Any help?

-- 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    | 
+------+--------+---------+------------+------+----------------+---------------+

and

SHOW CREATE TABLE foo;
+-------+------------------------------------------------------------------------------+
| Table | Create Table                                                                 |
+-------+------------------------------------------------------------------------------+
| fooo  | CREATE TABLE `fooo` (`id` int(11) NOT NULL PRIMARY KEY) COMMENT='my comment' | 
+-------+------------------------------------------------------------------------------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不乱于心 2024-10-04 16:58:25

基于OMG Ponies的答案,但使用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       | 
+--------------------------+

Based on the answer by OMG Ponies, but using INFORMATION_SCHEMA.TABLES instead of INFORMATION_SCHEMA.COLUMNS. When looking around on the web, all I could find was info on the columns' comments, but never on the table's. This is how to get a table's comment.

SELECT table_comment 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE table_schema='my_cool_database' 
        AND table_name='user_skill';
+--------------------------+
| table_comment            |
+--------------------------+
| my awesome comment       | 
+--------------------------+
叫嚣ゝ 2024-10-04 16:58:25

如果你不想在查询中同时使用数据库名和表名,你可以使用 :

SHOW TABLE STATUS WHERE Name='table_name';

,然后选取结果的“Comment”键(你必须使用像 php 中的 mysqli_fetch_assoc() 这样的关联函数)。

If you don't want to have both database name and table name in the query, you can use :

SHOW TABLE STATUS WHERE Name='table_name';

and then pick up the "Comment" key of the result (you have to use an associative function like mysqli_fetch_assoc() in php).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文