数据库代码不清楚,高手求解

创建触发器,当输入某个同学选课成绩时,如果他是少数民族,其成绩自动加5分

Create trigger ScoreInc
On Score
For insert
As
If exists(select *from inserted,Student where inserted.studentNo=Student.studentNo and student.nation<>’汉族’)
Update Score setScore.score=Score.score+5 from inserted,Student
Where inserted.studentNo=Student.studentNo and student.nation<>’汉族’ and inserted.studentNo=Score.studentNo andinserted.courseNo=Score.courseNo

为什么要选Score当基础表 而不是Student当基础表 怎么分析
Update Score setScore.score=Score.score+5 from inserted,Student 这句话 from之后怎么不是Score

student.nation<>’汉族’ 这个是说其它都是少数民族

首先,第一点
当输入某个同学选课成绩时 这句也就确定了是要在Score当基础表
举个例子,如果这表以student表为基础,那么就跟成绩表一点关系都不发生,student表里也只能判断出这个学生的民族,而做不了任何其他操作,
除非是这种情况,当把某个学生的民族由汉族改为其他民族时,将score表里的这个学生的成绩加5分,这个时候student表才是主表,

你先看看你理解不理解我上边这几句话的意思,有疑问的话继续追问
温馨提示:答案为网友推荐,仅供参考
相似回答