学籍管理系统(PowerDesigner+ER图+系统模块图+物理模型图) 第8页
表5.2 课程信息的录入
5.3 触发器与存储过程设计
1.StudentInfo 表上的出发器触发器:对于学生基本信息表,当学生信息修改时,其它表中若有对应的该信息时,应该对其进行修改;当学生信息删除时,对应的如SC表中的对应学生成绩信息也应该自动修改:
① Supdata:
CREATE TRIGGER
FOR UPDATE
AS
update SC
set 学号 = ( select 学号 from inserted)
where SC.学号=(select 学号 from deleted) ;
② Sdelete:
CREATE TRIGGER
FOR DELETE
AS
DELETE
FROM SC
WHERE SC.学号=(select 学号 from deleted) ;
2. Course表上的触发器:其功能是当一个课程的信息改变时,或当一个课程的信息被删除时,相应的在SC和TC表中的相应信息修改或删除。
① Cupdata:
CREATE TRIGGER
FOR UPDATE
AS
update SC
set 课程号 = ( select 课程号 from inserted)
where SC.课程号=(select 课程号 from deleted)
update TC
set TC.课程号 = ( select 课程号 from inserted)
where TC.课程号=(select 课程号 from deleted) ;
② Cdelete:
CREATE TRIGGER
FOR DELETE
AS
DELETE
FROM SC
WHERE SC.课程号=(select 课程号 from deleted)
DELETE
FROM TC
3.Department表上的触发器:当院系的代号改变时,对应的学生所在院系以及教师所在院系都应当做相应的更改。
Dupdata:
CREATE TRIGGER
FOR UPDATE
AS
update StudentsInfo
set StudentsInfo.专业号 = ( select专业号from inserted)
where StudentsInfo.专业号=(select 专业号 from deleted)
update Major
set Major.专业号 = ( select专业号from inserted)
where Major.专业号=(select 专业号 from deleted)
update Teacher
set Teacher.专业号 = ( select专业号from inserted)
where Teacher.专业号=(select 专业号 from deleted);
4.Teacher 表上的触发器:当教师号改变或教师离任时,TC表上的信息应相应的得到改变。
① Tupdata:
CREATE TRIGGER
FOR UPDATE
AS
② Sdelete:
CREATE TRIGGER
FOR DELETE
AS
DELETE
FROM TC
WHERE TC.教师号=(select 教师号 from deleted)
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页