存储过程
存储过程时事先经过编译并保存在数据库中的一段SQL语句集合,使用时调用即可
存储过程的基本框架
create proc 存储名
as
begin
end
调用存储过程的方法
-- 调用存储过程
exec 存储名
创建存储过程
/* 返回学号 2020005 学生的成绩情况 存储名p1 */
-- 第一种方法
select * from sc where sno='2020005'
-- 第二种方法 创建存储过程
create proc p1
as
begin
select * from sc where sno='2020005'
end
exec p1
修改存储过程
-- 修改存储过程
/* 查询某学生指定课程号的成绩和学分 alter 存储名p1 */
alter proc p1
@sno varchar(20),
@cno varchar(10)
as
begin
select sc.*,cou.ccredit from sc,cou where sno=@sno and sc.cno=@cno and sc.cno=cou.cno
end
exec p1 '2020004','20203'
删除存储过程
/* 删除p1 */
drop proc p1