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條件篩選
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM