mysql中table schema的基本操作


我們通常對數據庫進行的增刪插檢操作,是針對數據庫中的文件。mysql數據庫中還有一些表(是view,只能做select操作)記錄了現有表的meta data,比如某個column的名字,它的定義是什么等等。

1. 列出test數據庫中所有的表名,類型(普通表還是view)和使用的引擎

  select table_name, table_type, engine
  FROM information_schema.tables
  WHERE table_schema = 'test'
  ORDER BY table_name DESC;

解釋: 對表的meta data的查詢需要使用information_schema.tables, table_schema是數據庫的名稱,table_name是具體的表明,table_type指的是表的類型

2. 檢查數據庫'test'中的某一個表'd_ad'是否存在

  select count(1) from information_schema.tables where table_schema = 'test' and table_name = 'd_ad';

3. 檢查都一張表‘test.d_ad’的某一欄'ad_id'的類型

select column_type from information_schema.columns where TABLE_SCHEMA = 'test' and TABLE_NAME = 'd_ad' and COLUMN_NAME = 'ad_id';

解釋: 對於某一個表中具體field的查詢,需要使用表information_schema.columns

4. 更改某一欄的定義;

alter table test.d_ad modify column ad_id bigint(20) DEFAULT 0;


免責聲明!

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



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