若有错误,欢迎指正
比如下面的例子,黑马的瑞吉外卖中的数据库
SELECT
TABLE_NAME,
TABLE_COMMENT
FROM
INFORMATION_SCHEMA.TABLES
WHERE
table_schema = 'reggie';
SELECT
column_name,
column_comment
FROM
information_schema.COLUMNS
WHERE
table_name = 'dish'
AND table_schema = 'reggie';
如果不加限制条件
AND table_schema = 'reggie';
,则是查询所有数据库中表明为它的所有字段;
如图,本机mysql中有两个数据库中表明都为tb_user。
SELECT DISTINCT
TABLE_NAME
FROM
information_schema.COLUMNS
WHERE
COLUMN_NAME = 'price'
AND TABLE_SCHEMA = 'reggie';