所用到的表:
create table Students
(
SNO varchar(20),
SNAME varchar(6),
SEX varchar(2),
BDATE date,
HEIGHT int,
DEPARTMENT varchar(12),
primary key(SNO)
);
create table Courses
(
CNO varchar(12),
CNAME varchar(12),
LHOUR int,
CREDIT int,
SEMESTER varchar(8),
primary key(CNO)
);
create table SC
(
SNO varchar(20),
CNO varchar(12),
GRADE int,
primary key(SNO,CNO),
foreign key(SNO) references Students,
foreign key(CNO) references Courses
);
create table credits
(
sno varchar(20),
sumcredit int,
nopass int,
primary key(sno)
);
要求:
当在SC表中插入一条选课成绩,自动触发Upd_Credit,完成在Credits表中修改该学生的合计学分数和不及格的课程数。
代码如下:
create trigger upd_credit after insert on sc
for each row
declare
temp courses.grade%type;
begin
select credit into temp
from courses
where :new.cno=cno;
update credits
set sumcredit=sumcredit+temp
where :new.sno=sno;
if :new.grade<60 then
update credits
set nopass=nopass+1
where :new.sno=sno;
end if;
end;
--提示创建的触发器带有编译错误。
刚上手,不知道怎个写法。还有就是,分号是在什么情况下,添加在哪里的。求指导。
------解决方案--------------------------------------------------------
courses表有grade字段??