首頁 > 資料庫 > mysql教程 > MySQL如何辨識某個欄位是否存在於所有表中?

MySQL如何辨識某個欄位是否存在於所有表中?

王林
發布: 2023-09-01 22:57:03
轉載
950 人瀏覽過

MySQL如何辨識某個欄位是否存在於所有表中?

要識別列名,請在MySQL中使用INFORMATION_SCHEMA.COLUMNS。以下是語法-

select table_name,column_name
from INFORMATION_SCHEMA.COLUMNS
where table_schema = SCHEMA()
andcolumn_name='anyColumnName';
登入後複製

Let us implement the above query in order to identify a column with its existence in all tables. Here, we are finding the existence of column EmployeeAge −

r
mysql> select table_name,column_name
   FROM INFORMATION_SCHEMA.COLUMNS
   WHERE table_schema = SCHEMA()
   AND column_name='EmployeeAge';
登入後複製

+---------------+-------------+
| TABLE_NAME    | COLUMN_NAME |
+---------------+-------------+
| demotable1153 | EmployeeAge |
| demotable1297 | EmployeeAge |
| demotable1303 | EmployeeAge |
| demotable1328 | EmployeeAge |
| demotable1378 | EmployeeAge |
| demotable1530 | EmployeeAge |
| demotable1559 | EmployeeAge |
| demotable1586 | EmployeeAge |
| demotable1798 | EmployeeAge |
| demotable1901 | EmployeeAge |
| demotable511  | EmployeeAge |
| demotable912  | EmployeeAge |
+---------------+-------------+
12 rows in set (0.00 sec)
登入後複製
produce the following output displaying the tables with specific column “EmployeeAge” −

mysql> desc demotable1153;
登入後複製

為了證明,讓我們檢查上述任何一個表的描述−

+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| EmployeeId   | int(11)     | NO   | PRI | NULL    | auto_increment |
| EmployeeName | varchar(40) | YES  | MUL | NULL    |                |
| EmployeeAge  | int(11)     | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
登入後複製
這將產生以下輸出,顯示在demotable1153中存在EmployeeAge列−rrreee###

以上是MySQL如何辨識某個欄位是否存在於所有表中?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板