如何使用 MySQL 查詢具有特定列名的表?
要查詢列名,請使用 information_schema.columns。以下是語法 -
select distinct table_name from information_schema.columns where column_name like '%yourSearchValue%' and table_schema=database();
我們來實現上述語法,以便在各個表中查詢列名。在此,我們只想要包含特定列名詞“客戶”的表名 -
mysql> select distinct table_name from information_schema.columns where column_name like '%Client%' and table_schema=database();
這將產生以下輸出 -
+----------------+ | table_name | +----------------+ | demotable449 | | demotable450 | | demotable461 | | demotable517 | | demotable529 | | demotable534 | | demotable537 | | demotable543 | | demotable547 | +----------------+ 9 rows in set (1.19 sec)
現在,讓我們檢視任意表並查詢具有“客戶”列名的詞 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP