要識別列名,請在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 −
mysql> select table_name,column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = SCHEMA() AND column_name='EmployeeAge';
登錄后復制
This will produce the following output displaying the tables with specific column “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)
登錄后復制
為了證明,讓我們檢查上述任何一個表的描述 −
mysql> desc demotable1153;
登錄后復制
這將產生以下輸出,顯示在demotable1153中存在EmployeeAge列 −
+--------------+-------------+------+-----+---------+----------------+ | 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)
登錄后復制
以上就是MySQL如何識別某個列是否存在于所有表中?的詳細內容,更多請關注www.92cms.cn其它相關文章!