mysql和postgresql查询数据库中哪些表包含某个字段

 

想知道数据库中哪表含有edu_status字段
 
  1. mysql> select table_name,column_name from information_schema.columns where column_name like '%edu_status%';
  2. +-------------+-------------------+
  3. | table_name  | column_name       |
  4. +-------------+-------------------+
  5. | mytest     | edu_status        |
  6. +-------------+-------------------+
 
 
 
 
在MySQL和postgresql中,把 information_schema 看作是一个数据库,确切说是信息数据库。
COLUMNS表:提供了表中的列信息。
SCHEMATA表:提供了当前mysql实例中所有数据库的信息。
TABLES表:提供了关于数据库中的表的信息(包括视图)。
 
SELECT * FROM information_schema.columns WHERE table_schema = 'public' (table_schema在postgresql中筛选出需要的schema);
根据上面的字段用where条件筛选,筛选出自己需要的表名
 
postgresql中就可以
SELECT table_name FROM information_schema.columns WHERE table_schema = 'public' and column_name like '%edu_status%' ;
得到相应的结果:
m_rec_consume
maybe_late
radacct_increase
radacct_increase_middle
radacct_time
radacct_time_bak
maybe_late_bak_original
consume_increase
consume_increase_middle
dim_own_org_student_type
flux_timecount_action
student_dict_for_leavingschool
student_not_in_school
student_not_in_school_middle
t_access_record_second
m_rec_kqmj
 
 
 
如果仅需对表名进行筛选
SELECT * FROM information_schema.tables ;
则可以按照上图字段用where条件筛选
 
posted @ 2019-08-26 13:48  夏天换上冬装  阅读(2357)  评论(0编辑  收藏  举报