--视图:视图就是一个虚拟的表
select *from view_1
--显示所有学生的sno、sname、cno、degree
select Student.Sno,sname,cno,degree from Student join Score on Student.Sno=Score.sno
--显示101学生的sno、sname、cno、degree
select Student.Sno,sname,cno,degree from Student join Score on Student.Sno=Score.sno where Student.Sno=101
create view view_2
as
select Student.Sno,sname,cno,degree from Student join Score on Student.Sno=Score.sno
go
--视图,相当于起了一个别名 用于简便方法
select*from view_2 where sno=101
--子查询,将子查询查询出的结果集当做虚拟的临时表来使用
select *from(select Student.Sno,sname,cno,degree from Student join Score on Student.Sno=Score.sno )as table2 where sno=101
--分页查询
--显示第三行第四行 ,后面not in屏蔽掉当前页的内容,前面top是取屏蔽之后的数据的一页显示条数,必须要用主键作为排除条件
select top 2*from student where sno not in(select top 2 sno from student )
--分页的存储过程
create proc fenye
@nowye int,--当前页
@numbers int --显示行数
as
--屏蔽数据,假设@nowye=1,@numbers=4 ,也就是说每1页有4条数据, 括号里面的是屏蔽的数据,若@nowye=1,@numbers=4,会屏蔽0条,也就是说会显示第一页的全部4条数据,以此类推
select top (@numbers) *from student where sno
not in(select top ((@nowye-1)*@numbers) sno from student )
go
exec fenye 2,2
--创建万能分页 (未完善)
create proc wannengfenye
@nowye int,--当前页
@numbers int, --显示行数
@tablename varchar(50),
@zhujian varchar(50)
as
select top (@numbers) *from @tablename where @zhujian
not in(select top ((@nowye-1)*@numbers) @zhujian from @tablename)
go
exec fenye 2,2