数据库系统原理及应用教程(第3版)课后习题答案!

数据库系统原理及应用教程(第3版)课后习题答案!,第1张

习题5第5题p148

create database 职工_社团

use 职工_社团

create table 职工(

职工号 char(10) primary key,

姓名 char(8),

年龄 smallint default 20,

性别 char(20),

constraint C1 check (性别 in ('男','女')))

create table 社会团体(

编号 char(10) primary key,

名称 char(8),

负责人 char(10),

活动地点 char(20),

constraint C2 foreign key (负责人) references 职工 (职工号))

create table 参加(

职工号 char(10),

编号 char(10),

参加日期 smalldatetime,

constraint C3 primary key (职工号,编号),

constraint C4 foreign key (职工号) references 职工 (职工号),

constraint C5 foreign key (编号) references 社会团体 (编号))

(2)

create view 社团负责人(编号,名称,负责人职工号,负责人姓名,负责人性别)

as select 社会团体.编号,社会团体.名称,社会团体.负责人, 职工.职工号,职工.性别

from 职工,社会团体,参加

where 社会团体.编号=参加.编号 and 职工.职工号=参加.职工号

create view 参加人情况(职工号,姓名,社团编号,社团名称,参加日期)

as select 参加.职工号,姓名,社会团体.编号,名称,参加日期

from 职工,社会团体,参加

where 职工.职工号=参加.职工号 and 参加.编号=社会团体.编号

(3)

select distinct 职工.职工号,姓名

from 职工,社会团体,参加

where 职工.职工号=参加.职工号 and 参加.编号=社会团体.编号

and 社会团体.名称 in('歌唱队','篮球队')

(4)

select *

from 职工

where not exists (select *

from 参加

where 参加.职工号=职工.职工号)

(5)

select * from 职工

where not exists

(select *

from 社会团体

where not exists

(select *

from 参加

where 参加.职工号=职工.职工号 and 参加.编号=社会团体.编号))

(6)

select 职工号

from 职工

where not exists (select *

from 参加 参加1

where 参加1.职工号='001'and not exists

(select *

from 参加 参加2

where 参加2.编号=参加1.编号 and 参加2.职工号=职工.职工号))

(7)

select 编号,count(职工号) as 参加人数

from 参加

group by 编号

(8)

select TOP 1 名称,count(*) 参加人数

from 参加,社会团体

where 参加.编号=社会团体.编号

group by 名称

order by 参加人数 desc

(9)

select distinct 社会团体.名称,职工.姓名 as 负责人

from 职工,社会团体,参加

where 社会团体.编号=参加.编号

and 社会团体.负责人=职工.职工号

and 参加.编号 in(select 参加.编号

from 参加

group by 参加.编号 having count(参加.编号)>100)

(10)

grant select,insert,delete on 社会团体 to 李平

with grant option

grant select,insert,delete on 参加 to 李平

with grant option

习题6第9题p212

create database 学生选课

use 学生选课

create table 学生(

学号 char(10) primary key,

姓名 char(10),

性别 char(10),

constraint C1 check (性别 in ('男','女')),

年龄 smallint default 20,

所在系 char(20))

create table 课程(

课程号 char(10) primary key,

课程名 char(20),

先行课 char(20))

create table 选课(

学号 char(10),

课程号 char(10),

成绩 smallint,

constraint D1 primary key (学号,课程号),

constraint D2 foreign key (学号) references 学生(学号),

constraint D3 foreign key (课程号) references 课程(课程号))

create index student_ind on 学生(学号)

create index class_ind on 课程(课程号)

create index select_ind on 选课(学号,课程号)

create rule value_rule as @value in ('男','女')

go

exec sp_bindrule 'value_rule','学生.性别'

go

create default 性别缺省 as '男'

go

exec sp_bindefault '性别缺省','学生.性别'

go

create trigger 选课插入更新 on 选课

for insert,update

as if (select count(*)

from 学生,inserted,课程

where 学生.学号=inserted.学号 and 课程.课程号=inserted.课程号)=0

rollback transaction

go

create trigger delete_all on 学生

for delete

as delete 选课

from 选课,deleted

where 选课.学号=deleted.学号

go

select 所在系,count(学号)as 学生人数

from 学生

group by 所在系

order by 所在系

compute count(所在系),sum(count(学号))

select *

from 学生 inner join 选课 on 学生.学号=选课.学号

go

select *

from 学生 left outer join 选课 on 学生.学号=选课.学号

go

select *

from 学生 right outer join 选课 on 学生.学号=选课.学号

go

select 选课.学号,学生.姓名,

学习情况=case

when avg(成绩)>=85 then '好'

when avg(成绩)>=75 and avg(成绩)<85 then '较好'

when avg(成绩)>=60 and avg(成绩)<75 then '一般'

when avg(成绩)<60 then '较差'

end

from 学生,选课

where 学生.学号=选课.学号

group by 选课.学号,姓名

go

只有这些,不知道用得到吗

数据库系统基础教程答案 (第三版) 机械工业出版社 岳丽华 -

.

下载:

.

http://download.csdn.net/detail/zxzy17/4097265

.

如对你有帮助.请及时选为【满意回答】


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10810493.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存