mysql查询库中所有的表名,表中所有的字段名,查询库中有含有某个字段的表
程序员文章站
2024-03-08 23:02:40
...
查询该库中有所有的表名
SELECT DISTINCT
TABLE_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = '库名';
例如:
SELECT DISTINCT
TABLE_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'information_schema';
结果:
查询该表中有所有的表名
SELECT
COLUMN_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_NAME = '表名';
例如:
SELECT
COLUMN_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_NAME = 'CHARACTER_SETS';
结果:
查询该库中含有某个字段的表名
SELECT DISTINCT
TABLE_NAME
FROM
information_schema.COLUMNS
WHERE
COLUMN_NAME = '字段名'
AND TABLE_SCHEMA = '库名';
例如:
SELECT DISTINCT
TABLE_NAME
FROM
information_schema.COLUMNS
WHERE
COLUMN_NAME = 'ID'
AND TABLE_SCHEMA = 'information_schema';
结果:
上一篇: JavaMail入门教程之接收邮件(4)
下一篇: Yii2实现自定义独立验证器的方法