Mysql字段变更

新增字段

语法: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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗小爬EX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值