MySQL关于查找模式对象的语句

网友投稿 491 2023-06-10

MySQL关于查找模式对象的语句

MySQL关于查找模式对象的语句

在日常工作中,搜索特定的数据库对象,是最常见的一个工作,下面分享几个关于mysql模式查找的语句。

1. 在 MySQL 数据库中查找名称中包含数字的表

select table_schema as database_name, table_namefrom information_schema.tableswhere table_type = 'BASE TABLE' and table_name rlike ('[0-9]')order by table_schema, table_name;

说明:

database_name - 找到表的数据库(模式)的名称table_name - 找到的表的名称

2. 在 MySQL 数据库中查找关于特定列名的表

select tab.table_schema as database_name, tab.table_namefrom information_schema.tables as tabinner join information_schema.columns as col on col.table_schema = tab.table_schema and col.table_name = tab.table_namewhere tab.table_type = 'BASE TABLE' and column_name = 'idcity'order by tab.table_schema, tab.table_name;

说明:

database_name - 找到表的数据库(模式)的名称table_name - 找到的表的名称

3. 在 MySQL 数据库中查找没有特定名称的列的表

select tab.table_schema as database_name, tab.table_namefrom information_schema.tables tableft join information_schema.columns col on tab.table_schema = col.table_schema and tab.table_name = col.table_name and col.column_name = 'id' -- put column name herewhere tab.table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys') and tab.table_type = 'BASE TABLE' and col.column_name is nullorder by tab.table_schema, tab.table_name;

说明:

database_name - 找到的表的数据库(模式)名称table_name - 找到的表的名称​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
下一篇:抽丝剥茧—千万级数据之SQL优化
相关文章