This type of query is very interesting, querying information about tables and fields in a database. It can be summarized by permutations 4
species query.
1. Query all table names and table comments in the database
SELECT
TABLE_NAME AS 表名,
TABLE_COMMENT AS 表注释
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'dms_app_dev';
2. Query all field names, data types, and field comments in the dictionary table under the database
SELECT
COLUMN_NAME AS 字段名,
DATA_TYPE AS 数据类型,
COLUMN_COMMENT AS 字段注释
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'dms_app_dev'
AND TABLE_NAME = 'dicts';
3. Query all field names, data types, and field comments under all tables in the database
SELECT
COLUMN_NAME AS 字段名,
DATA_TYPE AS 数据类型,
COLUMN_COMMENT AS 字段注释
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'dms_app_dev';
4. Query all table names, table comments, and all field names, data types, and field comments in the database
SELECT
t.TABLE_NAME AS 表名,
t.TABLE_COMMENT AS 表注释,
c.COLUMN_NAME AS 字段名,
c.COLUMN_TYPE AS 数据类型,
c.COLUMN_COMMENT AS 字段注释
FROM
INFORMATION_SCHEMA.TABLES AS t,
INFORMATION_SCHEMA.COLUMNS AS c
WHERE
c.TABLE_NAME = t.TABLE_NAME
AND t.TABLE_SCHEMA = 'dms_app_dev';
In fact, the principle is very simple, when we create databases, tables, fields, and MySQL
put the details in our data storage information_schema
system database, so that we can SQL
be a simple query, are interested can look.