MySQL 和注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/199905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:12:56  来源:igfitidea点击:

MySQL and comments

mysqlcomments

提问by Humpton

Is it possible to add comments somehow, somewhere?

是否可以在某处以某种方式添加评论?

I don't pretend to be any sort of expert when using MySQL and certainly don't spend all day in it. More often than I would like I forget how I intend to use a column (usally the bit ones) and would be very excited if I could add a comment to remind me if 1 is good or bad, for example.

在使用 MySQL 时,我不会假装是任何类型的专家,当然也不会整天花在它上面。我经常忘记我打算如何使用一个列(通常是位列),并且如果我可以添加评论来提醒我 1 是好是坏,我会非常兴奋,例如。

I'd be happy if it only showed up in something like 'show create table', but any obscure place within the table structures would be better and easier to find than the current post-it notes on my desk.

如果它只出现在“show create table”之类的东西中,我会很高兴,但表格结构中任何晦涩的地方都会比我桌上当前的便利贴更好、更容易找到。

回答by micahwittman

http://dev.mysql.com/doc/refman/5.0/en/create-table.html

http://dev.mysql.com/doc/refman/5.0/en/create-table.html

table_option:
    {ENGINE|TYPE} [=] engine_name
  | AUTO_INCREMENT [=] value
  | AVG_ROW_LENGTH [=] value
  | [DEFAULT] CHARACTER SET [=] charset_name
  | CHECKSUM [=] {0 | 1}
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'string'


Example:

例子:

CREATE TABLE foo (
  id int(10) NOT NULL auto_increment COMMENT 'unique ID for each foo entry',
  bar varchar(255) default NULL COMMENT 'the bar of the foo',
  ....
) TYPE=MyISAM;

回答by Gary Richardson

You can comment columns and tables:

您可以评论列和表:

CREATE TABLE example (
  example_column INT COMMENT="This is an example column",
  another_column VARCHAR COMMENT="One more column"
) TYPE=MYISAM COMMENT="This is a comment about table";

回答by Robert Gamble

MySQL supports comments on tables and columns which will show up on show create:

MySQL 支持对表和列的注释,这些注释将在 show create 中显示:

create table example (field1 char(3) comment 'first field') comment='example table'

回答by Brad Kent

This is an oldie, and there many response on how to update a columns comment, or create a table with comments. But the given answers on how to view the comments are rather awful

这是一个老问题,关于如何更新列注释或创建带有注释的表有很多回应。但是关于如何查看评论的给出的答案相当糟糕

The easiest way to view the comments is via SHOW COLUMNSwith the FULL keyword:
SHOW FULL COLUMNS FROM mytable

查看评论的最简单方法是通过SHOW COLUMNS和 FULL 关键字:
SHOW FULL COLUMNS FROM mytable

回答by Anjani Barnwal

if you want comment in table (in phpmyadmin) then follow these steps

如果您想在表中发表评论(在 phpmyadmin 中),请按照以下步骤操作

  1. open localhost/phpmyadmin
  2. goto your database and select table
  3. now select operations menu from top.
  4. and goto table options and edit table comments. enter image description here
  1. 打开本地主机/phpmyadmin
  2. 转到您的数据库并选择表
  3. 现在从顶部选择操作菜单。
  4. 并转到表格选项并编辑表格注释。 在此处输入图片说明

回答by Hebe

Top voted answer worked for me only after equal sign removal. My working example would be

只有在删除等号后,最高投票的答案才对我有用。我的工作示例是

CREATE TABLE `example` (
`id` int(11) NOT NULL,
`two` varchar(255) COMMENT "comment text",
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

回答by Stringent Software

If you use the MySQL Administrator tool to manage/edit your databases, whenever you use the Table Editor, the comment for each column is automatically shown/editable.

如果您使用 MySQL Administrator 工具来管理/编辑您的数据库,那么每当您使用表编辑器时,每列的注释都会自动显示/可编辑。

回答by Edward Z. Yang

Are you sure you're not looking to use an ENUM column instead? Good MySQL tables should be self-documenting.

您确定不打算使用 ENUM 列吗?好的 MySQL 表应该是自我记录的。

An alternate approach would be to comment the schema files that have the SQL you use to define your tables (I assume you have those, and that you're not using PHPMyAdmin to grow table schemas on the fly...)

另一种方法是注释具有用于定义表的 SQL 的架构文件(我假设您拥有这些,并且您没有使用 PHPMyAdmin 来动态扩展表架构......)

But if you insist, the INFORMATION_SCHEMA COLUMNStable, specifically the COLUMN_COMMENT column, is probably what you're looking for. It's proprietary MySQL syntax though, so I would tend to avoid it (although the idea of database interoperability is really a joke).

但如果您坚持,INFORMATION_SCHEMA COLUMNS表,特别是 COLUMN_COMMENT 列,可能就是您要找的。虽然它是专有的 MySQL 语法,所以我倾向于避免它(尽管数据库互操作性的想法真的是一个笑话)。

回答by Dieter Gribnitz

I just wrote an app for this.

我刚刚为此编写了一个应用程序。

Can be found here: https://github.com/SplicePHP/mysql-comments

可以在这里找到:https: //github.com/SplicePHP/mysql-comments

Allows you to to update multiple database tables and columns in a single view.

允许您在单个视图中更新多个数据库表和列。

Instructions in link.

链接中的说明。