想知道數據庫中哪表含有edu_status字段
- mysql> select table_name,column_name from information_schema.columns where column_name like '%edu_status%';
- +-------------+-------------------+
- | table_name | column_name |
- +-------------+-------------------+
- | mytest | edu_status |
- +-------------+-------------------+
在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條件篩選