时间函数
timestampdiff
Timestampdiff(minute,begin,end)<5
Delect from exam_record where submit_time-start_time<=5 and score <60
date_sub
date_sub(end,interval 5 minute) <begin
date_add
Date_add(start,interval 5 minute) >end
2021-09-01 22:11:12’+ interval 50 minute
where year(submit_time)<2021
索引
Create方式创建索引
1.创建唯一索引
CREATE UNIQUE index 索引名称 on table_name (列名 长度 desc|asc)
3.创建全文索引
Create fulltext index 索引名称 on table_name (列名1 长度 desc|asc,列名2;长度 desc|asc)
3.创建普通索引
Create index 索引名称 on table_name (列名1,列名2)
Alter 方式增加索引
Alter table table_name add unique index 索引名称 列
Drop方式删除索引
Drop index 索引名 on 表名
Alter 方式删除索引
Alter table 表名 drop index 索引名
增
增新表
1.创建一张新表
primary key 主键
foreign key 外键
auto_increment 自增
unique 唯一性约束
not null 非空
Create table if not exists user_info_vip (
`id` int(11) primary key foreign key auto_increment unique not null comment ’自增ID’;
`uid` int(11) not nullComment’用户ID’;
`nick_name` varchar(64) default NULL comment’昵称’;
`achievement` int(11) default 0 comment ’成就值’;
`level` int(11) defaut NULL comment’用户等级’;
`job` varchar(32) default NULL Comment’职业方向’;
`registe datetir_time` default current_timestamp datetime commment’注册时间’
)
Character set(字符集名)
Collate(校对规则名)
增新列
Alter table table_name add 增加列的名称 位置after 某列;(在某列之后)
Alter table