编写存储过程p_getbycname :根据给定的课程名(假定课程名唯一),得到选课人数和考试人数,并调用该存储过程。
时间: 2023-07-07 14:26:25 浏览: 95
”存储过程与触发器“操作题.docx
好的,以下是存储过程p_getbycname的代码:
```
CREATE PROCEDURE p_getbycname
@courseName NVARCHAR(50)
AS
BEGIN
DECLARE @enrollment INT, @exam INT;
SELECT @enrollment = COUNT(*) FROM enrollment WHERE courseName = @courseName;
SELECT @exam = COUNT(*) FROM exam WHERE courseName = @courseName;
SELECT @enrollment AS enrollment, @exam AS exam;
END
```
使用该存储过程时,只需要传入课程名即可,如下所示:
```
EXEC p_getbycname '计算机基础'
```
该存储过程会返回计算机基础这门课的选课人数和考试人数。注意,这里假设课程名唯一,如果有多个课程名相同的课程,则需要进行额外的处理。
阅读全文