SQL的操控(DML)与查询(DQL)

34 篇文章 0 订阅

DML-操控-数据的操作包括使用

insert //数据的插入
delete //数据的删除
update //数据的更新
完整插入
insert into 表名 values(所需要插入的内容 ‘,’ 隔开)字符需用‘’隔开
部分插入
insert into 表名 (列名,列名) values(值1,值2)
更新数据
update 表名 set 列名= 值 where condition
更改MySQL密码
update user set authentication_string=password(‘qianfeng@123’) where user=‘root’
password()密码加密
更新密码后需刷新数据库密码生效
flush privileges
删除数据
delete from 表名 (删除表内所有内容)
delete from 表名 where id=1 (删除某一项)

DQL-查询

select //查询操作
简单查询
select * from 表名 (查询所有列)
select 列名 from 表名 (查询部分列)
四则运算查询,通过加减乘除取得自己想要得到的结果(例如通过月薪*12得出年薪)
单条件查询
where //哪里
select name.age from 表名 where age=20 (查询表中所有年龄为20的人)
多条件查询
and //并且
select name.age from 表名 where age=20 and name=like ‘z%’ (查询表中所有年龄为20并且名字为z开头的人 %参考模糊查询)

or //或
select name.age from 表名 where age=20 or age=21((查询表中所有年龄为20和21的人)

between and //在什么之间
select name.age from 表名 where age between 20 and 25(查询表中所有年龄为20到25的人)

not between and //不在什么之间age
select name.age from 表名 where age not between 20 and 25(查询表中所有年龄不在20到25的人)

in //集合查询
select name.age from 表名 where age in(20,21,22) (查询年龄在20,21,22的人)

not in //排除查询
select name.age from 表名 where age not in(20,21,22) (查询年龄不在20,21,22的人)

is null //空值查询
select name.age from 表名 where age is null (找出所有没有填写年龄的人)

like‘%’ //模糊查询(通配符%代表多个任意字符)
select name.age from 表名 where name=like ‘z%’ (模糊查找,姓名为‘z’开头的人

查询排序
order by //查询结果排序
select * from 表名 order by age (查看表中年龄的排序)

desc //降序
select * from 表名 order by age desc(降序查看表中年龄的排序)

ASC //升序
select * from 表名 order by age asc(升序查看表中年龄的排序)

limit //限制,只看
select * from 表名 order by age desc limit 5(降序查看表中年龄最大的五个人的排序)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值