数据库设计——MySQL查看表和字段注释信息

一、前言

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

二、查看数据所有表名及注释

select
	t.TABLE_NAME,
	t.TABLE_COMMENT
from
	information_schema.tables t
where
	t.TABLE_TYPE = 'BASE TABLE'
	and TABLE_schema = '数据库名'

在这里插入图片描述

三、查看数据库所有表及字段的注释

select
	b.ordinal_position,
	b.COLUMN_name,
	b.COLUMN_type,
	b.COLUMN_comment,
	b.is_nullable,
	b.column_key
from
	information_schema.TABLES a
left join information_schema.COLUMNS b on
	a.table_name = b.TABLE_NAME
where
	a.table_schema = '数据库名'

在这里插入图片描述

四、查看指定表的字段及注释

select
	a.ordinal_position,
	a.COLUMN_name,
	a.COLUMN_type,
	a.COLumn_comment,
	a.is_nullable,
	a.column_key
from
	information_schema.COLUMNS a
where
	TABLE_schema = 'sy-zhhg'
	and TABLE_name = 'acc_d_bjlx'

在这里插入图片描述

参考资料:MySQL information_schema 详解

猜你喜欢

转载自blog.csdn.net/qq_44723773/article/details/130614544
今日推荐