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;

posted @ 2020-09-19 15:34  huhuf6  阅读(3896)  评论(0编辑  收藏  举报