mysql - Mysql建表时注释

标签 mysql

在创建 MYSql 表时是否可以添加注释/描述?目的是使用这些信息来通知其他用户有关软件中表格的用途/用途。我知道我们可以在创建表格时对列进行评论,但在任何地方都没有相同的东西。

任何帮助都将不胜感激。此外,请共享查询以从表中检索信息/评论/描述。

最佳答案

你有没有在 create table statement 上查看过 mysql 的手册? , 你会发现你可以在语句的末尾添加一个 comment 子句:

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

...

COMMENT

A comment for the table, up to 2048 characters long.

...

The comment is displayed as part of the ouput of SHOW CREATE TABLE. The text of the comment is also available as the TABLE_COMMENT column of the MySQL Information Schema TABLES table.

This comment syntax is also supported with ALTER TABLE statements for NDB tables. Keep in mind that a table comment used with ALTER TABLE replaces any existing comment which the table might have had perviously.

CREATE TABLE t1 (
    c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    c2 VARCHAR(100),
    c3 VARCHAR(100) )
ENGINE=INNODB
COMMENT='Whatever'

关于mysql - Mysql建表时注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47385869/

相关文章:

python - UPDATE 和 INSERT 在 Python 中不起作用

mysql - 使用Where子句从连接的mysql表中过滤数据

mysql - 我的 docker-compose.yml 有什么问题?

mysql - 从主 id 中选择相关 id 和映射值

mysql - 如何根据另一个 SELECT 查询的结果对列的值求和?

php - mysql_result 变成更高级的 mysqli 函数

mysql - 支持股票拆分/合并的股票投资组合数据库设计

PHP/MySQL 关系/Echo 字段

mysql - Teradata 上的 Inner Join 有问题

mysql - LOAD DATA LOCAL INFILE 插入空白记录