您好,欢迎访问一九零五行业门户网

MySQL如何识别某个列是否存在于所有表中?

要识别列名,请在mysql中使用information_schema.columns。以下是语法 -
select table_name,column_namefrom information_schema.columnswhere 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如何识别某个列是否存在于所有表中?的详细内容。
其它类似信息

推荐信息