mysql笔记

添加列

alter table 表名 add column 字段名 varchar(20) default null comment '字段注释' ;

添加索引

# 主键索引 
alter table 表名 add PRIMARY KEY (`列名`);
# 唯一索引
alter table 表名 add UNIQUE (`列名`);
# 普通索引
alter table 表名 add INDEX idx_索引名 (`列名`);
# 全文索引
alter table 表名 add FULLTEXT (`列名`);
# 添加多列索引 
alter table 表名 add INDEX idx_索引名 (`列名1`,`列名2`,`列名3`);

修改表名

alter table 表名 rename 新表名;

修改表列名

#字段不为空
 alter table 表名 change  column 列名 新列名 varchar(3)  not null  default comment '字段注释';
#字段为空
 alter table 表名 change  column  列名 新列名 varchar(3)  default null comment '字段注释';

修改列字段长度

alter table 表名 modify column 列名 varchar(255) default null comment '字段注释' ;

更新数据

update 表名 set 字段名='新数据' where 条件 ;

创建表

create table `表名` ( 
 `主键`   bigint(20) NOT NULL AUTO_INCREMENT comment '主键注释',
 `字段1`  varchar(40) NOT NULL comment '字段1注释', #该字段不为空
 `字段2`  varchar(40) default null comment '字段2注释', #该字段允许为空
 PRIMARY KEY ( `主键`)
 ) ENGINE=InnoDB AUTO_INCREMENT=95223 DEFAULT CHAREST=utf8 COMMENT='表名注释'; 
 # 主键使用 AUTO_INCREMENT 声明后,插入数据时主键为空也会自动添加
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值