
-- 职工(职工号,姓名,年龄,性别);
-- 社会团体(社团号,名称,负责人,活动地点)
--参加(职工号,社团号,参加日期)
---其中: (1)职工表的主码为职工号。
--(2)社会团体表的主码为社团号;外码为负责人,被参照表为职工表,对应属性为职工号。
--(3)参加表的职工号和社团号为外码;职工号为外码,其被参照表为职工表,对应属性为职工号;
--社团号为外码,其被参照表为社会团体表,对应属性为社团号。
--试用SQL语句表达下列 *** 作:
---1.定义职工表、社会团体表和参加表,并说明其主码和参照关系。
create table em
(
emid varchar(5) primary key,
emname nvarchar(5) not null,
age int,
sex nchar(1))
create table team
(
tid char(3) primary key,
tname nvarchar(10) not null,
leader varchar(5) foreign key references em(emid),
workstation nvarchar(20)
)
create table takepartin
(emid varchar(5) foreign key references em(emid),
tid char(3) foreign key references team(tid),
takedate smalldatetime,
primary key(emid,tid))
--- 2.建立下列两个视图: 社团负责人(社团号,名称,负责人职工号,负责人姓名,负责人性别);
create view leaders
as
select tid,tname,em.emid,emname,sex from team join emp on team.emid=team.leader
----参加人情况(职工号,姓名,社团号,社团名称,参加日期)。
create view takes
as
select A.emid,emname,c.tid,tname,takedate from emp A join takepartin B on a.emid=B.emid
join team C on B.tid=C.tid
--3.查找参加的职工号和姓名。
select emid,emname from takes where tname='唱歌队' or tname='篮球队'
---4.查找没有参加任何社会团体的职工情况。
select * from emp where emid not in(select emid from takepartin)
--5.查找参加了全部社会团体的职工情况。
1. select distinct a.工号, a.姓名 from 职工 a, 社团 b, 参加 cwhere a.工号=c.工号
and c.编号=b.编号
and b.名称 in ('体 *** 队','篮球队')
2. select distinct a.工号, a.姓名, a.年龄 from 职工 a
where a.性别='男' and exists
(select 1 from 参加 b where b.工号=a.工号)
3. select a.工号 from 职工 a
where a.工号 in
(select b.工号 from 参加 b group by b.工号 having count(*) >2)
4. select a.* from 职工 a
where not exists ( select * from 社团 b where not exists
(select * from 参加 c where c.工号=a.工号 and c.编号=b.编号)
)
对大学生社团管理系统进行数据库设计,要包括以下内容:分析大学生社团管理应包含的实体、实体包含的属性。分析实体之间的关系,如强制参与、可选参与等,实体数应不低于 6 个
对实体中相应的数据项给出详细的数据字典描述,语义要合理
以 PowerDesigner 为建模工具,对数据库进行逻辑设计,图中含实体、属性、多样性、实体联系、主键、外键等
设计的关系模式需进行规范化处理,每个关系模式应能达到 3NF
针对选定的系统设计不低于 20 个事务,涉及到检索和更新等,事务要合理
绘制事务图,使用路径指示 ER 模型支持的用户事务
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)