Database design - MySQL view table and field annotation information

I. Introduction

Explanation
In mysql, information_schemathis database stores the information of all databases of the mysql server.
Including the database name, the table of the database, the data type of the table field, etc.
In short, if you want to know which libraries are in mysql, which tables, which fields are in the tables and their comments, you can get them from information_schema.

2. View all table names and comments of the data

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

insert image description here

3. View the comments of all tables and fields in the database

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 = '数据库名'

insert image description here

4. View the fields and comments of the specified table

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'

insert image description here

References: Detailed explanation of MySQL information_schema

Guess you like

Origin blog.csdn.net/qq_44723773/article/details/130614544