MySQL關(guān)于查找模式對象的語句
作者:雪竹頻道
在日常工作中,搜索特定的數(shù)據(jù)庫對象,是最常見的一個工作,下面分享幾個關(guān)于mysql模式查找的語句。
在日常工作中,搜索特定的數(shù)據(jù)庫對象,是最常見的一個工作,下面分享幾個關(guān)于mysql模式查找的語句。
1. 在 MySQL 數(shù)據(jù)庫中查找名稱中包含數(shù)字的表
select table_schema as database_name,
table_name
from information_schema.tables
where table_type = 'BASE TABLE'
and table_name rlike ('[0-9]')
order by table_schema,
table_name;
說明:
- database_name - 找到表的數(shù)據(jù)庫(模式)的名稱
- table_name - 找到的表的名稱
2. 在 MySQL 數(shù)據(jù)庫中查找關(guān)于特定列名的表
select tab.table_schema as database_name,
tab.table_name
from information_schema.tables as tab
inner join information_schema.columns as col
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
where tab.table_type = 'BASE TABLE'
and column_name = 'idcity'
order by tab.table_schema,
tab.table_name;
說明:
- database_name - 找到表的數(shù)據(jù)庫(模式)的名稱
- table_name - 找到的表的名稱
3. 在 MySQL 數(shù)據(jù)庫中查找沒有特定名稱的列的表
select tab.table_schema as database_name,
tab.table_name
from information_schema.tables tab
left 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 here
where tab.table_schema not in ('information_schema', 'mysql',
'performance_schema', 'sys')
and tab.table_type = 'BASE TABLE'
and col.column_name is null
order by tab.table_schema,
tab.table_name;
說明:
- database_name - 找到的表的數(shù)據(jù)庫(模式)名稱
- table_name - 找到的表的名稱?
責任編輯:趙寧寧
來源:
今日頭條