MySQL增加字段,修改字段,增加索引等语句

mysql增删改查基本语句:

1、修改表名:

rename table 旧表名 to 新表名;

2、修改字段类型:

alter table 表名 modify column 字段名 字段类型(长度)

3、修改字段名称和类型:

   alter table 表名 change 现有字段名称  修改后字段名称 数据类型

4、增加字段:

alter table 表名 add 字段名 字段类型(长度)

//批量增加字段

alter table 表名 add (字段名1 字段类型(长度),字段名2 字段类型(长度),...)

5、删除字段:

alter table 表名 drop column 字段名

//批量删除字段

alter table 表名 drop column 字段名1drop column 字段名2

6、修改字段默认值:

alter table 表名 alter column 字段 set default  默认值

7、添加字段备注:

alter table 表名 add 字段名 字段类型(长度)default null comment '备注'

// 为表添加注释


```vbnet
alter table 表名 comment '注释'; 

索引:
1.普通索引 添加index

alter table `表名` add index 索引名 ( `字段名` )

2.主键索引 添加primary key

alter table `表名` add primary key ( `字段名` )

3.唯一索引 添加unique

alter table `表名` add unique ( `字段名` )

4.全文索引 添加fulltext

alter table `表名` add fulltext( `字段名`)

5.如何添加多列索引

alter table `表名` add index 索引名 ( `字段名`, `字段名`, `字段名` )

参考文章:https://www.cnblogs.com/qiufang/p/9445156.html

  • 10
    点赞
  • 95
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值