mysql切換schema,MySQL中table_schema的基本操作

 2023-11-30 阅读 27 评论 0

摘要:mysql數據庫中有一些表(是view,只能做select操作)記錄了現有表的meta data,比如某個column的名字,它的定義是什么等等。 列出test數據庫中所有的表名,類型(普通表還是view)和使用的引擎 select table_name, table_type, engine FRO

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指的是表的類型

  1. 檢查數據庫’test’中的某一個表’hello_world’是否存在

mysql切換schema,select count(1) from information_schema.tables where table_schema = ‘test’ and table_name = ‘hello_world’;

  1. 檢查都一張表‘hello_world’的某一欄’a’的類型

select column_type from information_schema.columns where TABLE_SCHEMA = ‘test’ and TABLE_NAME = ‘hello_world’ and COLUMN_NAME = ‘a’;

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

  1. 更改某一欄的定義;

alter table test.hello_world modify column a bigint(20) DEFAULT 0;

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/186162.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息