学生管理系统sql sever 有关存储过程 触发器的代码
时间: 2024-05-05 15:20:44 浏览: 99
以下是一个简单的学生管理系统的 SQL Server 存储过程和触发器示例:
存储过程:
```sql
CREATE PROCEDURE sp_AddStudent
@StudentID INT,
@FirstName VARCHAR(50),
@LastName VARCHAR(50),
@BirthDate DATE,
@Gender VARCHAR(10)
AS
BEGIN
INSERT INTO Students (StudentID, FirstName, LastName, BirthDate, Gender)
VALUES (@StudentID, @FirstName, @LastName, @BirthDate, @Gender)
END
```
触发器:
```sql
CREATE TRIGGER tr_EnrollStudent
ON Enrollments
AFTER INSERT
AS
BEGIN
DECLARE @StudentID INT
DECLARE @CourseID INT
SELECT @StudentID = StudentID, @CourseID = CourseID FROM inserted
UPDATE Students
SET TotalCredits = TotalCredits + (SELECT Credits FROM Courses WHERE CourseID = @CourseID)
WHERE StudentID = @StudentID
END
```
以上代码仅供参考,实际情况下可能需要根据具体需求进行修改和优化。
阅读全文