MySQL常用SQL

darrenduan發表於2016-08-13


mysql常用sql語句

---- 遷移完成後的資料物件
select db 資料庫,type 物件型別,cnt 物件數量 from 
(select '表' type,table_schema db, COUNT(*) cnt  from information_schema.`TABLES` a where table_type='BASE TABLE' group by table_schema
union all
select '事件' type,event_schema db,count(*) cnt from information_schema.`EVENTS` b group by event_schema
union all
select '觸發器' type,trigger_schema db,count(*) cnt from information_schema.`TRIGGERS` c group by trigger_schema
union all
select '儲存過程' type,db ,count(*) cnt from mysql.proc d where`type` = 'PROCEDURE' group by db
union all
select '函式' type,db,count(*) cnt  from mysql.proc e where`type` = 'FUNCTION' group by db
union all
select '檢視' type,TABLE_SCHEMA,count(*) cnt  from information_schema.VIEWS f group by table_schema  ) t
where db='lhrdb'
order by db,type;
--- MySQL無主鍵的表
select table_schema, table_name
 from information_schema.tables
where table_type='BASE TABLE'
and   table_name not in (select distinct table_name
                           from information_schema.columns
                          where column_key = "PRI")
  AND table_schema not in  
      ('mysql', 'information_schema', 'sys', 'performance_schema');






About Me

........................................................................................................................

● 本文作者:小麥苗,部分內容整理自網路,若有侵權請聯絡小麥苗刪除

● 本文在個人微 信公眾號( DB寶)上有同步更新

● QQ群號: 230161599 、618766405,微信群私聊

● 個人QQ號(646634621),微 訊號(db_bao),註明新增緣由

● 於 2020年9月 在西安完成

● 最新修改時間:2020年9月

● 版權所有,歡迎分享本文,轉載請保留出處

........................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

● 小麥苗出版的資料庫類叢書: http://blog.itpub.net/26736162/viewspace-2142121/

小麥苗OCP、OCM、高可用、DBA學習班http://blog.itpub.net/26736162/viewspace-2148098/

● 資料庫筆試面試題庫及解答: http://blog.itpub.net/26736162/viewspace-2134706/

........................................................................................................................

請掃描下面的二維碼來關注小麥苗的微 信公眾號( DB寶)及QQ群(230161599、618766405)、新增小麥苗微 信(db_bao), 學習最實用的資料庫技術。

........................................................................................................................

 

 



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2724792/,如需轉載,請註明出處,否則將追究法律責任。

相關文章