1.创建一存储过程,实现查找学生的姓名,选修的课程名和成绩,并调用该存储过程。 2.创建一存储过程,实现输入学生学号和姓名返回学生的基本信息,并调用该存储过程。 3.创建一存储过程,输入学生的学号,返回学生选修门数和平均分。 4.创建带两个参数(一个参数是页码page,一个参数是每页显示的行数pageSize)的分页存储存储过程pro_paging,并调用该存储过程。
时间: 2023-07-08 15:53:40 浏览: 509
1. 查找学生的姓名、选修的课程名和成绩的存储过程:
```
CREATE PROCEDURE sp_GetStudentGrades
@StudentID INT
AS
BEGIN
SELECT s.StudentName, c.CourseName, g.Grade
FROM Students s
JOIN Grades g ON s.StudentID = g.StudentID
JOIN Courses c ON g.CourseID = c.CourseID
WHERE s.StudentID = @StudentID
END
```
调用该存储过程:
```
EXEC sp_GetStudentGrades @StudentID = 12345
```
2. 根据学生学号和姓名返回学生基本信息的存储过程:
```
CREATE PROCEDURE sp_GetStudentInfo
@StudentID INT,
@StudentName VARCHAR(50)
AS
BEGIN
SELECT *
FROM Students
WHERE StudentID = @StudentID AND StudentName = @StudentName
END
```
调用该存储过程:
```
EXEC sp_GetStudentInfo @StudentID = 12345, @StudentName = '张三'
```
3. 根据学生学号返回学生选修门数和平均分的存储过程:
```
CREATE PROCEDURE sp_GetStudentAvgGrade
@StudentID INT
AS
BEGIN
SELECT COUNT(*) AS Courses, AVG(Grade) AS AvgGrade
FROM Grades
WHERE StudentID = @StudentID
END
```
调用该存储过程:
```
EXEC sp_GetStudentAvgGrade @StudentID = 12345
```
4. 带两个参数的分页存储过程:
```
CREATE PROCEDURE sp_paging
@page INT,
@pageSize INT
AS
BEGIN
SELECT *
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY StudentID) AS RowNum, *
FROM Students
) AS t
WHERE t.RowNum BETWEEN (@page - 1) * @pageSize + 1 AND @page * @pageSize
END
```
调用该存储过程:
```
EXEC sp_paging @page = 2, @pageSize = 10
```
阅读全文