mysql数据库中有一些表(是view,只能做select操作)记录了现有表的meta data,比如某个column的名字,它的定义是什么等等。
- 列出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指的是表的类型
- 检查数据库’test’中的某一个表’hello_world’是否存在
select count(1) from information_schema.tables where table_schema = ‘test’ and table_name = ‘hello_world’;
- 检查都一张表‘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
- 更改某一栏的定义;
alter table test.hello_world modify column a bigint(20) DEFAULT 0;