sql整理

时间函数

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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值