如何使用 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)

現在,讓我們檢視任意表並查詢具有“客戶”列名的詞 -

更新於: 2019 年 10 月 9 日

1K+ 瀏覽量

開啟您的職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.