数据库原理与应用第三版何玉洁第十一章上机练习答案

数据库原理与应用第三版何玉洁第十一章上机练习答案_第1张图片
1-1
create proc P1_1
AS
select Student.Sno,Sum(Credit) from
Student join SC on Student.Sno = SC.Sno join Course on SC.Cno = Course.Cno
group by Student.Sno
1-2
create proc P1_2
@dept char(10)
AS
select Student.Sno,Sname,SC.Cno,Cname,Credit
from Student join SC on Student.Sno = SC.Sno join Course on SC.Cno = Course.Cno
where Sdept=@dept
1-3
create proc P1_3
@dept char(10),
@num int output
AS
select @num=Count() from Student
where Ssex = ‘男’ and Sdept=@dept
1-4
create proc P1_4
@g tinyint
AS
select Sno,AVG(Grade) from SC
group by Sno
having AVG(Grade)>=@g
1-5
create proc P1_5
@dept char(10),
@SCNum tinyint output,
@AVGrade tinyint output
AS
select top 1 @AVGrade = avg(Grade),@SCNum=count(
)
from SC
group by Sno
order by count()
1-6
create proc P1_6
@sno char(10),
@cno char(10)
AS
delete from SC where Sno=@sno and Cno=@cno
1-7
create proc P1_7
@semes tinyint=2,
@cno char(10)
AS
if
@semes between 1 and 8
update Course
set Semester = @semes
where Cno=@cno
2

3
alter proc P1_1
AS
select count(
),Sum(Credit),Avg(Grade)
from Student join SC on Student.Sno=SC.Sno join Course on SC.Cno=Course.Cno
4
4-1
create trigger T4_1
ON SC after update,insert
AS
if exists(select * from SC where Grade not between 0 and 100)
rollback
4-2
create trigger T4_2
ON Student after update,insert
AS
if exists(select * from Student where Sdept not in(‘计算机系’,‘信息系’,‘数学系’,‘物理系’))
rollback
4-3
create trigger T4_3
ON SC instead of insert
AS
if not exists(select * from SC group by Sno having count(*)>8)
insert into SC select * from inserted
4-4
create trigger T4_4
ON SC instead of delete
AS
if not exists(select * from SC where Grade >60)
delete SC select * from deleted
5
第五题要新建表,懒得建了就没做,跟第四题一个类型

你可能感兴趣的:(学习,数据库)