在我的上一篇文章中讲述了关于SQL语句关于创建数据库的操作,那接下来就学习一下关于表记录的增删改查。
一:插入记录
insert into 表名 (字段名)values (数据)
二:删除记录
delete from 表名 where 条件
三:更改记录
update 表名 set 所要更改的内容 where 条件
接下来再讲查询语句之前我们先来讲一下 where语句:
where 语句是用来过滤数据的
典例:
> < = != 代表 大于 小于 等于 不等于 可以任意组合(你懂的!)
math between 20 and 69 匹配数学成绩再20到69之间的记录
is null 空值检查
math in (23,34) 匹配math分数是23 或者是 34的记录
利用通配符进行过滤:
where name like yan%-------------%代表无数个任意字母 所以意思是匹配yan开头的所有单词
where name like yan_--------------_代表一个任意字母 所以意思是匹配yan开头的4个字母的单词
where name like [jm]%-------------找到name是以j或m开头的单词
四:查询记录
select name form 表名 【where 条件】
selsect id [as] new_id from student where math > 20
五:排序
select id , name ,math from student where math > 20 order by math [desc降序||asc升序]
最后讲一下优先级的问题
首先执行:from 表名
然后:where条件过滤
然后:select选择
最后:order排序
错误典例:select id,math as math成绩 from 表名 where math成绩>20 会报错
这一篇文章就这些,下一期再说说关于分组和外键的问题。