MySQL数据表操作、查看mysql表的信息等

1、修改表字段类型

alter table users_log modify column code smallint(4);

2、增加表字段

alter table users_log add error_code mediumint(5);

ALTER TABLE 表明 add 字段名称 类型(int,char,VARCHAR...) DEFAULT 默认值 位置(FIRST, AFTER+字段名称);

3、删除表字段

alter table users_log drop column error_code;

4、查看表的注释

SELECT table_name,table_comment FROM information_schema.tables WHERE table_name = 'users_log';

5、查看所有字段和字段注释

1 select column_name,column_comment from information_schema.columns where table_name = 'users_log';
2 (and table_schema='数据库名')

6、修改现有表的注释

ALTER TABLE users_log COMMENT='我是表的注释';

7、修改现有列,加上注释

alter table users_log modify column phone varchar(13) comment '手机号';

8、看mysql支持哪些存储引擎:

mysql> show engines;

9、看mysql当前默认的存储引擎:

mysql> show variables like '%storage_engine%';

10、设置表id自增

alter table users_log change id id int auto_increment;

11、设置字段的默认值
alter table 表名 alter column 字段名 drop default; (若本身存在默认值,则先删除)

alter table users_log alter column is_validate set default 0;

(若本身不存在则可以直接设定)

12、判断字段是否为自增

SELECT extra FROM information_schema.columns WHERE TABLE_SCHEMA='database' AND table_name = 'users_log' AND column_name='id';

13.查看mysql表的信息,包括更新时间,创建时间等

show table status like 'users';

·GROUP BY 子句
·ORDER BY 子句
·聚合函数(SUM、COUNT、AVG、MAX、MIN)
·DISTINCT
·集合运算符(UNION、INTERSECT、EXCEPT)
·窗口函数(RANK、ROW_NUMBER 等)

原文地址:https://www.cnblogs.com/Wtingting/p/13441056.html