Create procedure CancelCourse
(
 @StudentID int,
 @CourseID int,
 @ElectiveID int output 
)
as
select 
@ElectiveID=ElectiveID
from
Elective
where
@StudentID=StudentID
and
@CourseID=CourseID
delete from
Elective
where
(
 @StudentID=StudentID
and
 @CourseID=CourseID
)
GO
尽量解释清楚点 我刚学的

解决方案 »

  1.   

    Create procedure CancelCourse
    --创建存储过程名称为CancelCourse
    (
     @StudentID int,
     @CourseID int,
     @ElectiveID int output 
    --定义三个变量,其中两了是输入的,一个是输出的
    )
    as
    --存储过程代码
    select 
    @ElectiveID=ElectiveID
    from
    Elective
    where
    @StudentID=StudentID
    and
    @CourseID=CourseID
    delete from
    Elective
    where
    (
     @StudentID=StudentID
    and
     @CourseID=CourseID
    )
    GO--执行
      

  2.   

    通过@ElectiveID返回Elective表中,被删除的CourseID=@CourseID,StudentID=@StudentID的记录的ElectiveID值
      

  3.   

    应楼主要求结合gaojier1000(高捷)的讲解
    我补充一下
    该过程就是选修课退选过程
     select 
    @ElectiveID=ElectiveID
    from
    Elective
    where
    @StudentID=StudentID
    and
    @CourseID=CourseID
    以上是从Elective表中找出符合输入的StudentID和CourseID的条目然后将相应条目的Elective字段值赋予@ElectiveIDdelete from
    Elective
    where
    (
     @StudentID=StudentID
    and
     @CourseID=CourseID
    )
    从Elective表中删除对应StudentID和CourseID的记录
    选修课就被取消了