之前由于做项目客户要求要看到表注释和表中字段注释,刚开始做的时候是一头雾水,之前没有做过,还是一步一步来
测试:【之前数据库中已经存在一个表,特此说明】
1 新建表
mysql> create table stu1(
-> id int not null auto_increment primary key comment "a"
-> )
-> comment ="备注1";
Query OK, 0 rows affected (0.11 sec)
mysql> create table stu2(
-> id int not null auto_increment primary key comment "b"
-> )
-> comment ="备注2";
Query OK, 0 rows affected (0.07 sec)
mysql> create table stu3(
-> id int not null auto_increment primary key comment "C"
-> )
-> comment ="备注3";
Query OK, 0 rows affected (0.11 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| stu1 |
| stu2 |
| stu3 |
| test_table |
+----------------+
4 rows in set (0.01 sec)
2 查看数据库中所有表注释
精要:select table_comment from information_schema.tables where table_schema="数据库名";
mysql> select table_comment from information_schema.tables where table_schema="test"; +---------------+ | table_comment | +---------------+ | 备注1 | | 备注2 | | 备注3 | | 测试表 | +---------------+ 4 rows in set (0.01 sec)
3 查看数据表中所有字段注释
精要:select column_comment from Information_schema.columns where table_name="表名";
mysql> select column_comment as "字段注释" from Information_schema.columns where table_name="stu1"; +----------+ | 字段注释 | +----------+ | a | +----------+ 1 row in set (0.04 sec) mysql>
总结:
这些语句的实现有利于提高用户体验,实现软件的傻瓜的目的
浙公网安备 33010602011771号