# comment 评论;意见;批评;描述
1,新建表以及添加表和字段的注释.
create table t_user(
ID INT(19) primary key auto_increment comment ‘主键‘,
NAME VARCHAR(300) comment ‘姓名‘,
CREATE_TIME date comment ‘创建时间‘
)comment = ‘用户信息表‘;
# 字段内在字段最后面添加COMMENT 注释 ,括号外面用COMMENT=‘‘来给表添加注释
2,修改表/字段的注释.
alter table t_user comment = ‘修改后的表注释信息(用户信息表)‘;
alter table t_user modify column id int comment ‘主键ID‘;
--注意:字段名和字段类型照写就行
3,查询数据库所有表的详细信息(包括表的注释).
use information_schema;
select * from TABLES where TABLE_SCHEMA=‘你的表所在的数据库‘;
--查询某一张表的
use information_schema;
select * from TABLES where TABLE_SCHEMA=‘你的表所在的数据库‘ and TABLE_NAME= ‘你的表名‘;
mysql> SELECT * FROM TABLES WHERE table_schema=‘test‘ AND table_name=‘test1‘\G *************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: test TABLE_NAME: test1 TABLE_TYPE: BASE TABLE ENGINE: InnoDB VERSION: 10 ROW_FORMAT: Dynamic TABLE_ROWS: 0 AVG_ROW_LENGTH: 0 DATA_LENGTH: 16384 MAX_DATA_LENGTH: 0 INDEX_LENGTH: 0 DATA_FREE: 0 AUTO_INCREMENT: NULL CREATE_TIME: 2020-03-26 22:47:59 UPDATE_TIME: NULL CHECK_TIME: NULL TABLE_COLLATION: utf8_general_ci CHECKSUM: NULL CREATE_OPTIONS: TABLE_COMMENT: 我是表解释 1 row in set (0.00 sec)
4,查询一张表的详细信息(包括字段注释,字段名称,类型等).
use information_schema;
select * from information_schema.columns where table_schema =‘你的表所在的数据库‘ and table_name = ‘你的表名‘;
mysql> mysql> SELECT * FROM COLUMNS WHERE table_schema=‘test‘ AND table_name=‘test1‘\G *************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: test TABLE_NAME: test1 COLUMN_NAME: tt ORDINAL_POSITION: 1 COLUMN_DEFAULT: NULL IS_NULLABLE: YES DATA_TYPE: int CHARACTER_MAXIMUM_LENGTH: NULL CHARACTER_OCTET_LENGTH: NULL NUMERIC_PRECISION: 10 NUMERIC_SCALE: 0 DATETIME_PRECISION: NULL CHARACTER_SET_NAME: NULL COLLATION_NAME: NULL COLUMN_TYPE: int(11) COLUMN_KEY: EXTRA: PRIVILEGES: select,insert,update,references COLUMN_COMMENT: 我是解释 GENERATION_EXPRESSION: 1 row in set (0.00 sec) mysql>
注:还有一种方式:
# 查看建表语句,可以看到你的表注释与字段注释
show create table table_name;
mysql> SHOW CREATE TABLE test1\G *************************** 1. row *************************** Table: test1 Create Table: CREATE TABLE `test1` ( `tt` int(11) DEFAULT NULL COMMENT ‘我是解释‘ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=‘我是表解释‘ 1 row in set (0.00 sec) mysql>
# SHOW 方式可以查看你的字段注释
show full columns from 表名;
mysql> SHOW FULL COLUMNS FROM test1; +-------+---------+-----------+------+-----+---------+-------+---------------------------------+--------------+ | Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | +-------+---------+-----------+------+-----+---------+-------+---------------------------------+--------------+ | tt | int(11) | NULL | YES | | NULL | | select,insert,update,references | 我是解释 | +-------+---------+-----------+------+-----+---------+-------+---------------------------------+--------------+ 1 row in set (0.00 sec) mysql>
所以总结来看,如果想查看表与字段的信息,最好通过建表语句来看。
就是SHOW CREATE TABLE xxx,这个最方便
原文地址:https://www.cnblogs.com/sidianok/p/12578663.html