查数据库中包含某个字段的所有表

在数据库表较多的时候,需要查看某个字段存在于哪几张表中:
例如:查询hrm的数据库中,部门代码DEPARTMENT_CODE涉及到哪几张表的代码:

select distinct TABLE_NAME from information_schema.`COLUMNS` 
where COLUMN_NAME='DEPARTMENT_CODE' and TABLE_SCHEMA='hrm'
 and TABLE_NAME not like 'vm%';

结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42260782/article/details/129314900