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

  1. 检查数据库’test’中的某一个表’hello_world’是否存在

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值