一、常见的7种约束
--主键约束(primary key):
--唯一约束(unique)
--检查约束(check)
--默认约束(default)-----for 字段名
--外键约束(foreign key)-------references 主键表名(主键字段)
--非空约束(not null)
--标识列(identity)
二、where条件表达式
--对查询记录的结果进行选择(筛选)和处理
--1、比较运算: > < >= <= <> !> !<
--2、范围运算:between...and..(在...之间包含) / not between...and...
--3、列表运算:in(项1,项2,……) / not in(项1,项2,……)
--4、空值判断: is not null / is null
--5、逻辑运算: and(与) or(或) not(非)
--6、模糊匹配: like / not like
-- 通配符:
-- %:包含零个或多个字符的任意字符串
-- _:任意的单个字符
-- []:指定范围([a-f]、[abcdef]、[1,2,5,8,9])的单个字符
-- [^]:不在指定范围(如:[^a-f])的单个字符
--查询年龄不是20岁的学生的所有记录
select * from stuinfo where stuage<>20
--查询年龄在18-20岁之间的学生信息
select * from stuinfo where stuage between 18 and 20
--查询学号为102,104,106的学生的所有信息
select * from stuinfo where stuid in(102,104,106)
--查询年龄为空的学生信息
select * from stuinfo where stuage is null
--查询年龄在18-20岁之间,并且学号为102,104,106的学生信息
select * from stuinfo
where stuage between 18 and 20
and
stuid in(102,104,106)
--查询姓张的同学的所有信息
select * from stuinfo where stuname like '张%'
--查询姓张的名字是两个字的同学的所有信息
select * from stuinfo where stuname like '张_'
--查询名字第二个字是三或者四的同学的所有信息
select * from stuinfo where stuname like '_[三,四]%'
select * from stuinfo where stuid like '10[^3,5]'