1.准备学习的数据库

--创建学生表
create table T_Student
(
    --identity表示主键自增长,从1开始,且每次加1
    SId int primary key identity(1,1),
    SName nvarchar(10),
    SGender varchar(2) default(''),
    SAge int
)
--插入数据
--全部列名与值一一对应
insert into T_Student(SName,SGender,SAge) values('李三','',13)
--全部列名都赋值,则values前边值可省
insert into T_Student values('李四','',14)
--因为SGender有默认值,所以写也有有值
insert into T_Student(SName,SAge) values('王五',15)
insert into T_Student values('赵六','',16)
insert into T_Student values('Kim','',17)
insert into T_Student values('Lily','',18)
insert into T_Student values('Jerry','',19)

2.select基本用法

(1)简单的数据检索

数据库系列学习(四)-数据的过滤

(2)检索出需要的列

数据库系列学习(四)-数据的过滤

(3)给列设别名

数据库系列学习(四)-数据的过滤

(4)按条件过滤

数据库系列学习(四)-数据的过滤

(5)数据汇总

数据库系列学习(四)-数据的过滤

(6)排序

数据库系列学习(四)-数据的过滤

3.高级数据过滤

(1)通配符过滤

A:单字符匹配

数据库系列学习(四)-数据的过滤

B:多字符匹配

数据库系列学习(四)-数据的过滤

C:集合匹配

数据库系列学习(四)-数据的过滤

D:使用否定匹配法

数据库系列学习(四)-数据的过滤

E:使用通配符过滤虽然方便,但是会对数据库进行全表扫描,所以执行速度非常慢

(2)空值检测

首先插入两条记录先

数据库系列学习(四)-数据的过滤

开始查询

数据库系列学习(四)-数据的过滤

(3)反义运算符

数据库系列学习(四)-数据的过滤

(4)多值检测

数据库系列学习(四)-数据的过滤

(5)范围检测

数据库系列学习(四)-数据的过滤

(6)低效的“where 1 = 1”

在动态组装sql语句时会用到

缺点:使用“1=1”的过滤条件以后数据库系统就无法使用检索等查询优化策略,数据库系统就会被迫对每行数据进行扫描,即全表扫描

相关文章:

  • 2021-04-02
  • 2022-01-07
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-12-07
  • 2021-11-03
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2021-04-06
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案