新增字段
语法:alter table 表名 add 列名 字段类型;
示例:
alter table message add message_type tinyint(4);
alter table message add message_type tinyint(4) not null comment '消息类型' after message_id;
alter table message add column1 int(4), add column2 int(4);
修改字段
语法:alter table 表名 change 老字段 新字段 新字段类型;
示例:
alter table message change message_type msg_type tinyint(20);
alter table message change message_type msg_type tinyint(20) not null comment '消息类型';
语法:alter table 表名 modify column 字段名 类型
示例:
alter table message modify column poi_lon decimal(10,6);
alter table message modify column poi_lon decimal(10,6) default null comment '地理位置纬度';
删除字段
语法:alter table 表名 drop 列名;
示例:
alter table message drop latLon_type;
alter table message drop column1, drop column2, drop coloum3;
添加索引
语法:alter table 表名 add index 索引名(列名1, 列名2, 列名3)
alter table table_name add index index_name (column_list);
alter table table_name add unique (column_list);
alter table table_name add primary key (column_list);
alter table conv_user add unique key idx_conv_user_id (conv_id,user_id) using btree comment '会话ID、用户ID唯一索引';
alter table conv_user add key idx_user_id (user_id) using hash comment '用户ID索引';
alter table friend_relation add index idx_user_id (user_id) using hash comment '用户ID索引';
alter table file_content add index idx_content (content(20)) using btree comment '字符串索引(仅对前20个字符进行索引)';
删除索引
语法:
drop index 索引名 on 表名
alter table 表名 drop index 索引名
drop index index_name on talbe_name;
alter table table_name drop index index_name;
alter table table_name drop primary key;