How to find all the tables in MySQL with specific

2018-12-31 14:16发布

I have 2-3 different column names that I want to look up in the entire DB and list out all tables which have those columns. Any easy script?

9条回答
不流泪的眼
2楼-- · 2018-12-31 14:37
SELECT DISTINCT TABLE_NAME, COLUMN_NAME  
FROM INFORMATION_SCHEMA.COLUMNS  
WHERE column_name LIKE 'employee%'  
AND TABLE_SCHEMA='YourDatabase'
查看更多
怪性笑人.
3楼-- · 2018-12-31 14:39
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%wild%';
查看更多
怪性笑人.
4楼-- · 2018-12-31 14:45

If you want "To get all tables only", Then use this query:

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME like '%'
and TABLE_SCHEMA = 'tresbu_lk'

If you want "To get all tables with Columns", Then use this query:

SELECT DISTINCT TABLE_NAME, COLUMN_NAME  
FROM INFORMATION_SCHEMA.COLUMNS  
WHERE column_name LIKE '%'  
AND TABLE_SCHEMA='tresbu_lk'
查看更多
登录 后发表回答