存储过程应用实例
在做机房收费系统的下机操作时,由于要查询学生上下机表的上机时间等,学生信息表的学生余额,和基本数据设定表的半小时收费情况等信息,如果一张表一张表的实现会比较麻烦,如图:
这时应用存储过程就会减少我们的工作量,提高效率!如图:
代码如下:
Create procedure [dbo].[pro_stuOffline] @card_no char(20)asbegin select t_student .studentname ,t_student .Card_no,t_student.money , t_basedate .rate ,t_online .Ontime ,t_student.department, t_student.sex ,t_student.Student_no ,t_online.Consume ,t_online .Leftmoney from t_student right join (t_basedate cross join t_online) on t_student .Card_no= t_online.card_no where t_student.Card_no =@card_no and t_online .offtime is null end对于D层来说:
左外连接包含left join左表所有行,如果左表中某行在右表没有匹配,则结果中对应行右表的部分全部为空(NULL).
2、右连接 right join 或 right outer join
SQL语句:select * from student right join course on student.ID=course.ID
执行结果:
右外连接包含right join右表所有行,如果左表中某行在右表没有匹配,则结果中对应左表的部分全部为空(NULL)。
3、完全外连接 full join 或 full outer join
SQL语句:select * from student full join course on student.ID=course.ID
执行结果:
完全外连接包含full join左右两表中所有的行,如果右表中某行在左表中没有匹配,则结果中对应行右表的部分全部为空(NULL),如果左表中某行在右表中没有匹配,则结果中对应行左表的部分全部为空(NULL)。
二、内连接 join 或 inner join
SQL语句:select * from student inner join course on student.ID=course.ID
执行结果:
inner join 是比较运算符,只返回符合条件的行。
此时相当于:select * from student,course where student.ID=course.ID