在创建 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/