网站什么时候做SEO优化最合适,做设计的去哪些大厂,广州番禺区偏僻吗,网站建设费 科研 类像代码一样#xff0c;可以为表以及表中的列添加注释#xff0c;方便其他人知晓其功能。对于一些字段#xff0c;在经过一定时间后#xff0c;创建者未必也能想起其具体的含意#xff0c;所以注释显得尤为重要。 注释的添加 注释的添加是通过在定义表或列的时候在末尾加上… 像代码一样可以为表以及表中的列添加注释方便其他人知晓其功能。对于一些字段在经过一定时间后创建者未必也能想起其具体的含意所以注释显得尤为重要。 注释的添加 注释的添加是通过在定义表或列的时候在末尾加上 COMMENT 关键字来实现的最长支持 1024 个字符。 可以在创建表的时候为表和列添加相应的注释。 CREATE TABLE test_comment ( id SERIAL PRIMARY KEY, col1 INT comment 列的注释 )
comment 表的注释; 执行上面的语句后创建了一个名为 test_comment 的表并且为表和其中的 col1 列指定了相应的注释。 然后可通过 SHOW CREATE TABLE table_name 来查看。 mysql SHOW CREATE TABLE test_comment\G
*************************** 1. row ***************************Table: test_comment
Create Table: CREATE TABLE test_comment (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,col1 int(11) DEFAULT NULL COMMENT 列的注释,PRIMARY KEY (id),UNIQUE KEY id (id)
) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_general_ci COMMENT表的注释
1 row in set (0.00 sec) 注释的查看 除了 SHOW CREATE TABLE table_name 语法还有其他一些查看注释的方式。 SHOW TABLE STATUS 能够查看表的注释其语法为 SHOW TABLE STATUS WHERE nametable_name; 以下是通过 SHOW TABLE STATUS 查看的结果 mysql SHOW TABLE STATUS WHERE nametest_comment\G
*************************** 1. row ***************************Name: test_commentEngine: InnoDBVersion: 10Row_format: DynamicRows: 0Avg_row_length: 0Data_length: 16384
Max_data_length: 0Index_length: 16384Data_free: 0Auto_increment: 1Create_time: 2019-05-11 15:41:01Update_time: NULLCheck_time: NULLCollation: utf8mb4_general_ciChecksum: NULLCreate_options:Comment: 表的注释
1 row in set (0.00 sec) 而通过 SHOW FULL COLUMNS 则可查看列的注释其语法为 SHOW FULL COLUMNS FROM tablename 以下是通过 SHOW FULL COLUMNS 查看的结果 mysqlSHOW FULL COLUMNS FROM test_comment\G
*************************** 1. row ***************************Field: idType: bigint(20) unsignedCollation: NULLNull: NOKey: PRIDefault: NULLExtra: auto_increment
Privileges: select,insert,update,referencesComment:
*************************** 2. row ***************************Field: col1Type: int(11)Collation: NULLNull: YESKey:Default: NULLExtra:
Privileges: select,insert,update,referencesComment: 列的注释
2 rows in set (0.00 sec) 借助 INFORMATION_SCHEMA 中的表 也能查看表或列的注释。 比如查看表的注释 SELECT table_comment
FROM information_schema.tables
WHERE table_name test_comment; 执行结果 mysql SELECT table_comment- FROM information_schema.tables- WHERE table_name test_comment;
---------------
| TABLE_COMMENT |
---------------
| 表的注释 |
---------------
1 row in set (0.01 sec) 查看列的注释 SELECT column_comment
FROM information_schema.columns
WHERE column_name col1; 执行结果 mysql SELECT column_comment- FROM information_schema.columns- WHERE column_name col1;
----------------
| COLUMN_COMMENT |
----------------
| 列的注释 |
----------------
1 row in set (0.00 sec) 注释的更新 对已经存在的表和列可通过相应的更新修改操作来添加注释。 列注释的添加更新 CHANGE 和 MODIFY 等效区别在于 CHANGE 重写定义列需要书写完整的列定义包括新的列名称即使你并不想修改列的免而 MODIFY 则不用指定新的列名称。 通过 CHANGE 语法 mysql ALTER TABLE test_comment CHANGE col1 col1 INT COMMENT 列的注释2;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 通过 MODIFY 语法 mysql ALTER TABLE test_comment MODIFY col1 INT COMMENT 列的注释2;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0 查看修改结果 mysql SHOW CREATE TABLE test_comment\G
*************************** 1. row ***************************Table: test_comment
Create Table: CREATE TABLE test_comment (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,col1 int(11) DEFAULT NULL COMMENT 列的注释2,PRIMARY KEY (id),UNIQUE KEY id (id)
) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_general_ci COMMENT表的注释
1 row in set (0.00 sec) 表注释的添加更新 通过 ALTER TABLE 来完成对表注释的添加和更新。 mysql ALTER TABLE test_comment comment 表的注释2;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 查看更新结果 mysql SHOW CREATE TABLE test_comment\G
*************************** 1. row ***************************Table: test_comment
Create Table: CREATE TABLE test_comment (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,col1 int(11) DEFAULT NULL COMMENT 列的注释2,PRIMARY KEY (id),UNIQUE KEY id (id)
) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_general_ci COMMENT表的注释2
1 row in set (0.00 sec) 注释的删除 更新注释时指定为空即可。 mysql ALTER TABLE test_comment COMMENT ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0mysql ALTER TABLE test_comment MODIFY col1 INT COMMENT ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 查看删除结果 mysql SHOW CREATE TABLE test_comment\G
*************************** 1. row ***************************Table: test_comment
Create Table: CREATE TABLE test_comment (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,col1 int(11) DEFAULT NULL,PRIMARY KEY (id),UNIQUE KEY id (id)
) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_general_ci
1 row in set (0.00 sec) 相关资源 MySQL Manual - 13.1.20 CREATE TABLE SyntaxMySQL Manual - 13.7.6.36 SHOW TABLE STATUS SyntaxAlter MySQL table to add comments on columnsChanging mysql table commentChapter 25 INFORMATION_SCHEMA Tables转载于:https://www.cnblogs.com/Wayou/p/mysql_comments_for_table_and_column.html