mysql查看表和字段注释

说明

在mysql中,information_schema这个数据库中保存了mysql服务器所有数据库的信息。
包括数据库名,数据库的表,表字段的数据类型等。
也就是说,我们想知道mysql中有那些库,那些表,表里面有那些字段以及他们的注释,
都可以从information_schema中获取。

1.查看数据库所有表名及注释

SELECT
table_name name,
table_comment comment
FROM
information_schema.TABLES
WHERE
table_schema = '数据库名'

在这里插入图片描述

2.查看数据库所有表及字段的注释

SELECT
distinct
a.table_name name,
a.table_comment comment,
b.COLUMN_NAME columnName,
b.column_comment columnComment,
b.column_type columnType,
b.column_key columnKey
FROM
information_schema.TABLES a
LEFT JOIN information_schema.COLUMNS b ON a.table_name = b.TABLE_NAME
WHERE
a.table_schema = '数据库名'

在这里插入图片描述

3.查看指定表的字段及注释

SELECT
	distinct
	a.table_name name,
	a.table_comment comment,
	b.COLUMN_NAME columnName,
	b.column_comment columnComment,
	b.column_type columnType,
	b.column_key columnKey
FROM
information_schema.TABLES a
LEFT JOIN information_schema.COLUMNS b ON a.table_name = b.TABLE_NAME
and a.TABLE_SCHEMA = b.TABLE_SCHEMA
WHERE
a.table_schema = 'demo'
and a.table_name = 'user'

在这里插入图片描述

参考文章:MySQL information_schema 详解

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高并发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值