《SQL - Server - 2000 - 实验指导》课后作业 联系客服

发布时间 : 星期日 文章《SQL - Server - 2000 - 实验指导》课后作业更新完毕开始阅读

- 36 -

5、创建一个角色newstudent,使其具有对数据库jiaoxuedb进行任何操作的权限。并将上面创建的用户:newuser、sqladmin、sqlteacher添加到此用户中。

- 37 -

- 38 -

实验13:习题

1、编写一个事务:对于考试违纪的学生,对其采取考试成绩降一个档次的处罚。考试成绩分为5档次:优、良、中、及格、不及格。 begin transaction use jiaoxuedb go

select sno,cno,grade=

case when score<60 then '不及格'

when score<70 and score>=60 then '及格' when score<80 and score>=70 then '中等' when score<90 and score>=80 then '良好' when score>=90 and score<=100 then '优秀' end

from sc where flag=0 union

select sno,cno,grade=

case when score-10<60 then '不及格'

when score-10<70 and score>=60 then '及格' when score-10<80 and score>=70 then '中等' when score-10<90 and score>=80 then '良好' end

from sc where flag=1 commit

2.对于发生教学事故的教师要进行罚款处理,假如用x表示罚款数额。编写一个罚款事务,要求:从被罚款的教师工资中扣除罚款额x,若工资额大于等于罚款额x,则提交罚款,否则,扣除工资的一半作为罚款额,剩余罚款额以后再扣除,并修改显示剩余的罚款额x。 begin transaction use jiaoxuedb declare @pay int,@name char(10),@sal int set @pay=1000 set @name='李英' select @sal=sal from teacher where tn=@name if @sal>@pay begin update teacher set sal=sal-@pay where tn=@name select @sal=sal from teacher where tn=@name print @name+'经过处罚后还剩余的工资为:'+str(@sal) commit end else begin update teacher set sal=sal-sal/2 where tn=@name - 39 -

select @pay=@pay-sal from teacher where tn=@name print @name+'还欠款'+str(@pay) end go 3.完成下面事务设计:某高校嘉奖优秀教师:增加津贴500元;若此教师为助教,则可破格将其晋升为讲师。获得优秀教师的条件是:至少任两门课课程,并且每门课程的及格率100%,优秀率33%。 4.设计一个事务,给所有在册的非新生学生增加1岁,要求,50人作为一个事务提交一次。

- 40 -