日期:2014-05-17 浏览次数:20437 次
CREATE TRIGGER insert_course ON Course
FOR INSERT
AS
DECLARE @Cno INT --@Cno用于接收插入的课程号
DECLARE @Cflag BIT --@flag用于接收课程的是否选修
DECLARE @Sno INT --@Sno用于接收学生学号
SELECT @Cno = Cno
FROM inserted
SELECT @Cflag = Cflag
FROM inserted
DECLARE my_cursor CURSOR
FOR
SELECT Sno
FROM Student --声明游标
OPEN my_cursor --打开游标
FETCH NEXT FROM my_cursor INTO @Sno --通过游标逐个读取学生学号赋给变量
IF ( @Cflag = 1 )
BEGIN
WHILE ( @@fetch_status = 0 )
BEGIN
INSERT INTO Greade
( sno, cno )
VALUES ( @Sno, @cno )
&nb