数据库的一些基本操作(mysql)(Workbench)

我们用的数据库是mysql 5.7.18,采用的 GUI方式创建数据库,相应的GUI是Workbench。

1.首先,创建数据库,选择utf8的容器。

2.创建表user

3.插入操作

4.选择操作(用得最多的)

#选择语句格式
#select(colA,colB) from(table)
#where(condition)
#order by (col) desc
#limit (off),(count)
#选择id为1的数据
SELECT * FROM toutiao.user where id = 1;
#选择id为1,5,6的数据
SELECT * FROM toutiao.user where id in (1,5,6);
#选择id在2到5之间的数据,前开后闭
SELECT * FROM toutiao.user where id between 2 and 5;
#记录id大于2的有多少人
SELECT count(id) FROM toutiao.user where id > 1;
#降序排序
SELECT * FROM toutiao.user order by id desc;
#升序排序
SELECT * FROM toutiao.user order by id asc;
#组合,先选择大于1的,再降序排序,偏移两个数据后,取前三个数据
SELECT * FROM toutiao.user where id > 1 order by id desc limit 2,3;

5.更新操作

6.删除操作(几乎不用)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值