1) 1) 每个职工的数据是职工号、姓名、地址和他所在的商品部。
2) 2) 每一商品部的数据有:它的职工,经理和它经销的商品。
3) 3) 每种经销的商品数有:商品名、生产厂家、价格、型号(厂家定的)和内部商品代号(商店规定的)。
4) 4) 关于每个生产厂家的数据有:厂名、地址、向商店提供的商品价格。
请设计该百货商店的概念模型,再将概念模型转换为关系模型。注意某些信息可用属性表示,其他信息可用联系表示。
习题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
只有这些,不知道用得到吗
b
3、b
4、c
5、b
6、c
8、数据的完整性是指数据库中数据的正确性、有效性和一致性。
9、c
10、b
12、acd
13、abc
14、bc
16、对
17、对
18、错
19、错
20、错
SELECT 课程号 FROM S,SC WHERE S学号=SC学号 AND 姓名='李林'AND 课程号 NOT IN (SELECT 课程号 FROM S,SC WHERE S学号=SC学号 AND 姓名='王明')
13B
14B
D
4C
5B
6C
8D
11A
12B
13B
bcccabbbdb
1传递依赖 部分依赖
2插入异常,删除异常,修改异常
3A中不存在任何一个真子集Ai,使得Ai->Y。
4Y不能依赖于X,Z不依赖于Y
5能惟一标识元组的属性集且不含有多余属性
6主属性,非主属性
7有效的 完备的
82NF BCNF
91NF
10低级范式 高级范式
只会这么多了!
到地球村网申请个号,填写完善公司资料,选择自己行业的相关或是自己喜欢的模板,只要会上传,会打字,20几分钟自己公司网站,就做好了,当天做好,基本上第二天,就能在百度谷歌搜到自己的公司名,公司产品了。
安全稳定简单易用 最关键的是完全免费
oyximid404
以上就是关于数据库课后习题答案 这是题目 请帮忙解答全部的内容,包括:数据库课后习题答案 这是题目 请帮忙解答、数据库系统原理及应用教程(第3版)课后习题答案!、数据库原理,求高手解答答案,要60分以上才给分哦!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)