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

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)简单的数据检索

image

(2)检索出需要的列

image

(3)给列设别名

image

(4)按条件过滤

image

(5)数据汇总

image

(6)排序

image

3.高级数据过滤

(1)通配符过滤

A:单字符匹配

image

B:多字符匹配

image

C:集合匹配

image

D:使用否定匹配法

image

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

(2)空值检测

首先插入两条记录先

image

开始查询

image

(3)反义运算符

image

(4)多值检测

image

(5)范围检测

image

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

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

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

posted @ 2015-05-17 22:31  Kimisme  阅读(1616)  评论(0编辑  收藏  举报