数据库系统基础教程课后答案第五章
数据库系统概论第一章第五章部分习题答案
第一章11 .试给出一个实际部门的 E 一R 图,要求有三个实体型,而且 3 个实体型之间有多对多联系。
3 个实体型之间的多对多联系和三个实体型两两之间的三个多对多联系等价吗?为什么?答:3 个实体型之间的多对多联系和 3 个实体型两两之间的 3 个多对多联系是不等价,因为它们拥有不同的语义。
3 个实体型两两之间的三个多对多联系如下图所示。
12 .学校中有若干系,每个系有若干班级和教研室,每个教研室有若干教员,其中有的教授和副教授每人各带若干研究生;每个班有若干学生,每个学生选修若干课程,每门课可由若干学生选修。
请用 E 一R 图画出此学校的概念模型。
答:13 .某工厂生产若干产品,每种产品由不同的零件组成,有的零件可用在不同的产品上。
这些零件由不同的原材料制成,不同零件所用的材料可以相同。
这些零件按所属的不同产品分别放在仓库中,原材料按照类别放在若干仓库中。
请用 E 一R 图画出此工厂产品、零件、材料、仓库的概念模型。
答:第五章6.假设有下面两个关系模式:职工(职工号,姓名,年龄,职务,工资,部门号),其中职工号为主码;部门(部门号,名称,经理名,电话),其中部门号为主码。
用sQL 语言定义这两个关系模式,要求在模式中完成以下完整性约束条件的定义:定义每个模式的主码;定义参照完整性;定义职工年龄不得超过60 岁。
答CREATE TABLE DEPT(Deptno NUMBER(2),Deptname VARCHAR(10),Manager VARCHAR(10),PhoneNumber Char(12)CONSTRAINT PK_SC PRIMARY KEY(Deptno));CREATE TABLE EMP(Empno NUMBER(4) PRIMARY KEY,Ename VARCHAR(10),Age NUMBER(2),CONSTRAINT C1 CHECK ( Aage<=60),Job VARCHAR(9),Sal NUMBER(7,2),Deptno NUMBER(2),CONSTRAINT FK_DEPTNOFOREIGN KEY(Deptno)REFFERENCES DEPT(Deptno));。
04735数据库系统原理(2021版)课后习题参考答案
04735数据库系统原理(2021版)课后习题参考答案答案仅供参考第一章数据库系统概述选择题B、B、A简答题1.请简述数据,数据库,数据库管理系统,数据库系统的概念。
P27数据是描绘事物的记录符号,是指用物理符号记录下来的,可以鉴别的信息。
数据库即存储数据的仓库,严格意义上是指长期存储在计算机中的有组织的、可共享的数据集合。
数据库管理系统是专门用于建立和管理数据库的一套软件,介于应用程序和操作系统之间。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高数据冗余小易于保证数据一致性数据独立性高可以施行统一管理与控制减少了应用程序开发与维护的工作量3.请简述数据库系统的三级形式和两层映像的含义。
P31答:数据库的三级形式是指数据库系统是由形式、外形式和内形式三级工程的,对应了数据的三级抽象。
两层映像是指三级形式之间的映像关系,即外形式/形式映像和形式/内形式映像。
4.请简述关系模型与网状模型、层次模型的区别。
P35使用二维表构造表示实体及实体间的联络建立在严格的数学概念的根底上概念单一,统一用关系表示实体和实体之间的联络,数据构造简单明晰,用户易懂易用存取途径对用户透明,具有更高的数据独立性、更好的平安保密性。
第二章关系数据库选择题C、C、D简答题1.请简述关系数据库的根本特征。
P48答:关系数据库的根本特征是使用关系数据模型组织数据。
2.请简述什么是参照完好性约束。
P55答:参照完好性约束是指:假设属性或属性组F是根本关系R的外码,与根本关系S的主码K相对应,那么对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系标准化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系形式,应采取将一个关系形式分解为多个关系形式的方法进展处理。
数据库系统第五版课后习题答案
第1章绪论1 .试述数据、数据库、数据库系统、数据库管理系统的概念。
答:( l )数据( Data ) :描述事物的符号记录称为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义是不可分的。
解析在现代计算机系统中数据的概念是广义的。
早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。
现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。
数据与其语义是不可分的。
500 这个数字可以表示一件物品的价格是 500 元,也可以表示一个学术会议参加的人数有 500 人,还可以表示一袋奶粉重 500 克。
( 2 )数据库( DataBase ,简称 DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按一定的数据模型组织、描述和储存,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。
( 3 )数据库系统( DataBas 。
Sytem ,简称 DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。
解析数据库系统和数据库是两个概念。
数据库系统是一个人一机系统,数据库是数据库系统的一个组成部分。
但是在日常工作中人们常常把数据库系统简称为数据库。
希望读者能够从人们讲话或文章的上下文中区分“数据库系统”和“数据库”,不要引起混淆。
( 4 )数据库管理系统( DataBase Management sytem ,简称 DBMs ) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。
DBMS 的主要功能包括数据定义功能、数据操纵功能、数据库的运行管理功能、数据库的建立和维护功能。
解析 DBMS 是一个大型的复杂的软件系统,是计算机中的基础软件。
目前,专门研制 DBMS 的厂商及其研制的 DBMS 产品很多。
数据库原理与应用教程第四版 第五章答案
免责声明:私人学习之余整理,如有错漏,概不负责1.视图的优点简化数据查询语句、使用户能从多角度看待同一数据、提高了数据的安全性、提供了一定程度的逻辑独立性2.使用视图可以加快数据的查询速度吗?为什么?不对。
其本质上还是执行视图内部的查询语句,通过视图查询数据时,都是转换为对基本表的查询,其简化了数据查询语句但是并不能加快数据查询速度。
3.写出创建满足以下要求的视图的SQL语句。
1)查询学生的学号、姓名、所在系、课程号、课程名、课程学分。
CREATE VIEW v1(Sno,Sname,Sdept,Cno,Cname,Credit)ASSELECT s.Sno,Sname,Sdept,o,Cname,CreditFROM Student s JOIN SC ON s.Sno = SC.Sno JOIN Course c ON o = o2)查询学生的学号、姓名、选修的课程名和考试成绩。
CREATE VIEW v2(Sno,Sname,Cname,Grade)ASSELECT s.Sno,Sname,Cname,GradeFROM Student s JOIN SC ON s.Sno = SC.Sno JOIN Course c ON o = o3)统计每个学生的选课门数,列出学生学号和选课门数。
CREATE VIEW v3(Sno,选课门数)ASSELECT s.Sno,COUNT(*)FROM Student s JOIN SC ON s.Sno = SC.SnoGROUP BY Sno4)统计每个学生的修课总学分,列出学生学号和总学分。
(成绩大于等于60)CREATE VIEW v4(Sno,总学分)ASSELECT s.Sno,SUM(Credit)FROM Student s JOIN SC ON s.Sno = SC.Sno JOIN Course c ON o = oWHERE Grade > 60GROUP BY Sno5)查询计算机系Java考试成绩最高的学生的学号、姓名和Java考试成绩。
数据库实用教程(第三版)董建全数据库第五章答案
数据库实用教程(第三版)董建全数据库第五章答案5.2..设关系模式R(ABC),如果规定.定,.关系中B值与D值之间是一对多联系,A值与C值之间是一对一联系。
试写出相应的函.数依赖。
答:从B值与D值之间是一对多联系,可写出函数依赖D→B,从A值与C值之间是一对一联系,可写出函数依赖A→C和C→A。
5.3设关系模式R(ABCD),F是R上成立的FD集,F|={A→B,C→B},则相对于F,试写出.关系模式R的关键码。
并说明理由。
答:R的关键码为ACD,因为从已知的F,只能推出ACD→ABCD5.4试解释数据库“丢失信息”与“未丢失信息”两个概念。
“丢失信息”与“丢失数据”有什么区别?5.5设关系模式R(WNO,WS,WG)的属性分别表示职工的工号、工资级别和工资数目。
F是R上成立的FD集,F={WNO→WS,WS→WG}。
将R分解成ρ={R1,R2},其中R1={WNO,WS},R2={WNO,WG}。
那么,丢失的FD是(WS→WG)。
5.6设关系模式R(ABC),F是R上成立的FD集,F={B→C,C→A},那么分解ρ={AB,BC}相对于F,是否无损分解和保持FD?说明理由。
5.7设关系模式R(ABCD),R上的FD集F={A→C,D→C,BD→A},试说明ρ={AB,ACD,BCD}相对于F是损失分解的理由。
答:据已知的F集,不可能把初始表格修改为有一个全a行的表格,因此ρ相对于F 是损失分解。
5.8设有关系模式R(职工名,项目名,工资,部门名,部门经理),如果规定每个职工可参加多个项目,各领一份工资;每个项目只属于一个部门管理;每个部门只有一个经理。
①试写出关系模式R的基本FD和关键码。
②说明R不是2NF模式的理由,并把R分解成2NF模式集。
③进而把R分解成3NF模式集,并说明理由。
答:⑴R的基本FD有三个:(职工名,项目名)→工资项目名→部门名部门名→部门经理关键码为(职工名,项目名)。
数据库系统概论第五章完整性
一、选择题1.实体完整性要求主属性不能取空值,这一点可通过( )来保证。
A .定义外部键B .定义主键C .用户定义的完整性D .由关系系统自动答案:B2. ( )定义了对参照关系的外部属性值域的约束。
A .实体完整性规则B .用户定义的完整性规则C .参照完整性规则D .以上均不是答案:C3.在如下2个数据库的表中,若雇员信息表EMP 的主键是雇员号,部门信息表DEPT 的主键是部门号。
若执行所列出的操作,哪个操作不能执行( )EMP DEPTA .从雇员信息表EMP 中删除行(’010’,’’王利,’01’,’1200’)B .在雇员信息表EMP 中插入行(’102’,’赵丽’,’01’,’1500’)C .将雇员信息表EMP 中雇员号=’010’的工资改为1600元D .将雇员信息表EMP 中雇员号=’101’的部门号改为’05’答案:D4.关系数据库中,实现主码标识元组的作用是通过( )A .实体完整性规则B .参照完整性规则C .用户自定义的完整性D .属性的值域答案:A5.在关系数据库中,实现“表中任意两行不能相同”的约束是靠( )A .外码B .主码C .属性D .列答案:B6.关系数据库中,实现表与表之间的联系是通过( )A .实体完整性规则B .参照完整性规则C .用户自定义的完整性D .值域答案:B雇员号 雇员名 部门号 工资001 张红 02 2000 010 王利 01 1200056 马明 02 1000101 赵丽 04 1500 部门号 部门名 主任 01 业务部 李林02 销售部 江平 03 服务部 周明 04 财务部 陈胜7.根据关系模式的完整性规则,一个关系中的“主键”()A.不能有两个B.不能成为另一个关系的外部键C.不允许为空D.可以取空值答案:C8.在关系模型中,实现“关系中不允许发现相同的元组”的约束是通过()A.候选键B.主键C.外键D.一般键答案:B二、填空题1.为了维护数据库中数据的完整性,在对关系数据库执行插入时首先应检查__________规则。
数据库系统原理及应用教程第四版课后答案苗雪兰第5章(ppt文档)
服务功能
数据库引擎:核心服务,是存储和处理关系的 数据或XML文档数据的服务,完成数据的存储、 处理和安全管理。例如,创建数据库、创建表、 创建视图、数据查询、访问数
Analysis Services:提供联机分析处理 (OLAP)和数据挖掘功能。
Reporting Services(报表服务):提供图形 工具和向导,用于创建和发布报表;管理报表 服务器;对对象模型进行编程和扩展的应用程 序编程接口(API)。
2008年,微软公司发布了SQL Server 2008,该版本为各类 用户提供完整的数据库解决方案,帮助用户建立自己的电 子商务体系,增强用户对外界变化的敏捷反应能力,提高 用户的市场竞争力。
5.1.1 N-Tier客户机∕服务器结构
1. 桌面型数据库系统和客户机/服务器型数据库系统
桌面型数据库系统:SQL Server和数据库都安装在客户端计 算机中。客户机/服务器型数据库系统:系统安装在网络服务 器中,数据库为网络中的客户机应用程序共享。
③事件探查器是SQL Server一种性能优化工具,用于监视 与分析SQL服务器活动、网络进出流量或事件等。 ④数据库引擎优化顾问是SQL Server系统优化工具,可以 帮助用户进行数据库引擎方面的优化服务。
SQL Server发展简史 SQL Server的第一个版本是由微软公司和Sybase公司在 1988年合作开发的。
从1992年到1998年,微软公司相继开发了SQL Server的 Windows NT平台版本的SQL Server 4.2版本、6.0版本、6.5 版本和7.0版本。
2000年,SQL Server 2000版本正式面世。该版本在数据库 性能、数据可靠性、易用性方面做了重大改进。
数据库系统概论(第五版)王珊第五章课后习题答案
数据库系统概论(第五版)王珊第五章课后习题答案1什么是数据库的完整性?答:数据库的完整性是指数据的正确性和相容性。
2 .数据库的完整性概念与数据库的安全性概念有什么区别和联系?答:数据的完整性和安全性是两个不同的概念,但是有⼀定的联系。
前者是为了防⽌数据库中存在不符合语义的数据,防⽌错误信息的输⼊和输出,即所谓垃圾进垃圾出( Garba : e In Garba : e out )所造成的⽆效操作和错误结果。
后者是保护数据库防⽌恶意的破坏和⾮法的存取。
也就是说,安全性措施的防范对象是⾮法⽤户和⾮法操作,完整性措施的防范对象是不合语义的数据。
3 .什么是数据库的完整性约束条件?可分为哪⼏类?答完整性约束条件是指数据库中的数据应该满⾜的语义约束条件。
⼀般可以分为六类:静态列级约束、静态元组约束、静态关系约束、动态列级约束、动态元组约束、动态关系约束。
静态列级约束是对⼀个列的取值域的说明,包括以下⼏个⽅⾯: ( l )对数据类型的约束,包括数据的类型、长度、单位、精度等; ( 2 )对数据格式的约束; ( 3 )对取值范围或取值集合的约束; ( 4 )对空值的约束; ( 5 )其他约束。
静态元组约束就是规定组成⼀个元组的各个列之间的约束关系,静态元组约束只局限在单个元组上。
静态关系约束是在⼀个关系的各个元组之间或者若⼲关系之间常常存在各种联系或约束。
常见的静态关系约束有: ( l )实体完整性约束; ( 2 )参照完整性约束; ( 3 )函数依赖约束。
动态列级约束是修改列定义或列值时应满⾜的约束条件,包括下⾯两⽅⾯: ( l )修改列定义时的约束; ( 2 )修改列值时的约束。
动态元组约束是指修改某个元组的值时需要参照其旧值,并且新旧值之间需要满⾜某种约束条件。
动态关系约束是加在关系变化前后状态上的限制条件,例如事务⼀致性、原⼦性等约束条件。
4 . DBMS 的完整性控制机制应具有哪些功能?答:DBMS 的完整性控制机制应具有三个⽅⾯的功能: ( l )定义功能,即提供定义完整性约束条件的机制; ( 2 )检查功能,即检查⽤户发出的操作请求是否违背了完整性约束条件;( 3 )违约反应:如果发现⽤户的操作请求使数据违背了完整性约束条件,则采取⼀定的动作来保证数据的完整性。
数据库系统原理课后答案 第五章
5.1 名词解释(1)SQL模式:SQL模式是表和授权的静态定义。
一个SQL模式定义为基本表的集合。
一个由模式名和模式拥有者的用户名或账号来确定,并包含模式中每一个元素(基本表、视图、索引等)的定义。
(2)SQL数据库:SQL(Structured Query Language),即‘结构式查询语言’,采用英语单词表示和结构式的语法规则。
一个SQL数据库是表的汇集,它用一个或多个SQL模式定义。
(3)基本表:在SQL中,把传统的关系模型中的关系模式称为基本表(Base Table)。
基本表是实际存储在数据库中的表,对应一个关系。
(4)存储文件:在SQL中,把传统的关系模型中的存储模式称为存储文件(Stored File)。
每个存储文件与外部存储器上一个物理文件对应。
(5)视图:在SQL中,把传统的关系模型中的子模式称为视图(View),视图是从若干基本表和(或)其他视图构造出来的表。
(6)行:在SQL中,把传统的关系模型中的元组称为行(row)。
(7)列:在SQL中,把传统的关系模型中的属性称为列(coloumn)。
(8)实表:基本表被称为“实表”,它是实际存放在数据库中的表。
(9)虚表:视图被称为“虚表”,创建一个视图时,只把视图的定义存储在数据词典中,而不存储视图所对应的数据。
(10)相关子查询:在嵌套查询中出现的符合以下特征的子查询:子查询中查询条件依赖于外层查询中的某个值,所以子查询的处理不只一次,要反复求值,以供外层查询使用。
(11)联接查询:查询时先对表进行笛卡尔积操作,然后再做等值联接、选择、投影等操作。
联接查询的效率比嵌套查询低。
(12)交互式SQL:在终端交互方式下使用的SQL语言称为交互式SQL。
(13)嵌入式SQL:嵌入在高级语言的程序中使用的SQL语言称为嵌入式SQL。
(14)共享变量:SQL和宿主语言的接口。
共享变量有宿主语言程序定义,再用SQL 的DECLARE语句说明, SQL语句就可引用这些变量传递数据库信息。
《数据库系统原理》04735课后习题答案(2018版)
答案仅供参考第一章数据库系统概述选择题B、B、A简答题1.请简述数据,数据库,数据库管理系统,数据库系统的概念。
P27数据是描述事物的记录符号,是指用物理符号记录下来的,可以鉴别的信息。
数据库即存储数据的仓库,严格意义上是指长期存储在计算机中的有组织的、可共享的数据集合。
数据库管理系统是专门用于建立和管理数据库的一套软件,介于应用程序和操作系统之间。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高数据冗余小易于保证数据一致性数据独立性高可以实施统一管理与控制减少了应用程序开发与维护的工作量3.请简述数据库系统的三级模式和两层映像的含义。
P31答:数据库的三级模式是指数据库系统是由模式、外模式和内模式三级工程的,对应了数据的三级抽象。
两层映像是指三级模式之间的映像关系,即外模式/模式映像和模式/内模式映像。
4.请简述关系模型与网状模型、层次模型的区别。
P35使用二维表结构表示实体及实体间的联系建立在严格的数学概念的基础上概念单一,统一用关系表示实体和实体之间的联系,数据结构简单清晰,用户易懂易用存取路径对用户透明,具有更高的数据独立性、更好的安全保密性。
第二章关系数据库选择题C、C、D简答题1.请简述关系数据库的基本特征。
P48答:关系数据库的基本特征是使用关系数据模型组织数据。
2.请简述什么是参照完整性约束。
P55答:参照完整性约束是指:若属性或属性组F是基本关系R的外码,与基本关系S的主码K 相对应,则对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系规范化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。
一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。
(完整版)数据库系统基础教程第五章答案
Exercise 5.1.1 As a set:speed2.662.101.422.803.202.202.001.863.06 Average = 2.37 As a bag:speed2.662.101.422.803.203.202.202.202.002.801.862.803.06 Average = 2.48 Exercise 5.1.2 As a set:hd25080320200300160 Average = 218 As a bag:hd2502508025025032020025025030016016080 Average = 215 Exercise 5.1.3a As a set:bore15161418As a bag:bore1516141615151418Exercise 5.1.3bπbore(Ships Classes)Exercise 5.1.4aFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the union of bags R and S will have tuple t appear n + m times. The further union of bag T with the tuple t appearing o times will have tuple t appear n + m + o times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the union of bags R and S will have tuple t appear m + o times. The further union of bag R with the tuple t appearing n times will have tuple t appear m + o + n times in the final result.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result. Since we cannot have duplicates, the result only has at most one copy of the tuple t.Exercise 5.1.4bFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the intersectionof bags R and S will have tuple t appear min( n, m ) times. The further intersection of bag T with the tuple t appearing o times will produce tuple t min( o, min( n, m ) ) times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the intersection of bags R and S will have tuple t appear min( m, o ) times. The further intersection of bag R with the tuple t appearing n times will produce tuple t min( n, min( m, o ) ) times in thefinal result.The intersection of bags R,S and T will yield a result where tuple t appears min( n,m,o ) times. For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result.Exercise 5.1.4cFor bags:On the left-hand side:Given that tuple r in R, which appears m times, can successfully join with tuple s in S,which appears n times, we expect the result to contain mn copies. Also given that tuple tin T, which appears o times, can successfully join with the joined tuples of r and s, weexpect the final result to have mno copies.On the right-hand side:Given that tuple s in S, which appears n times, can successfully join with tuple t in T,which appears o times, we expect the result to contain no copies. Also given that tuple rin R, which appears m times, can successfully join with the joined tuples of s and t, weexpect the final result to have nom copies.The order in which we perform the natural join does not matter for bags.For sets:This is a similar case when dealing with bags except the joined tuples can only appear at most once in each result. If there are tuples r,s,t in relations R,S,T that can successfully join, then the result will contain a tuple with the schema of their joined attributes.Exercise 5.1.4dFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two bags R ⋃ S, tuple t would appear n + m times. Likewise, in the union of these two bags S ⋃ R, tuple t would appear m + n times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in both sets R and S will the union R ⋃ S have the tuple t. The same reasoning holds when we take the union S ⋃ R.Therefore the commutative law for union holds.Exercise 5.1.4eFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these two bags R ∩ S, tuple t would appear min( n,m ) times. Likewise in the intersection of these two bags S ∩ R, tuple t would appear min( m,n ) times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in at least one of the sets R and S will the intersection R ∩ S have the tuple t. The same reasoning holds when we take the intersection S ∩R.Therefore the commutative law for intersection holds.Exercise 5.1.4fFor bags:Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that the two tuples t,u can successfully join. Then in the natural join of these two bags R S, the joined tuple would appear nm times. Likewise in the natural join of these two bags S R, the joined tuple would appear mn times. Both sides of the relation yield the same result.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuples u,v might appear respectively in sets R and S one or zero times. The combinations of number of occurrences for tuples u,v in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple u exists in Rand tuple v exists in S will the natural join R S have the joined tuple. The same reasoning holds when we take the natural join S R.Therefore the commutative law for natural join holds.Exercise 5.1.4gFor bags:Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L will yield a resulting relation where the projected attributes from tuple t appear m + n times. If we take the projection of the attributes in list L first, then the projected attributes from tuple t would appear m times from R and n times from S. The union of these resulting relations would have the projected attributes of tuple t appear m + n times.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t exists in R or S (or both R and S) will the projected attributes of tuple t appear in the result.Therefore the law holds.Exercise 5.1.4hFor bags:Suppose tuple t appears u times in R, v times in S and w times in T. On the left hand side, the intersection of S and T would produce a result where tuple t would appear min(v , w) times. With the addition of the union of R, the overall result would have u + min(v , w) copies of tuple t. On the right hand side, we would get a result of min(u + v, u + w) copies of tuple t. The expressions on both the left and right sides are equivalent.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R,S and T one or zero times. The combinations of number of occurrences for tuple t in R, S and T respectively are (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Only when tuple t appears in R or in both S and T will the result have tuple t.Therefore the distributive law of union over intersection holds.Exercise 5.1.4iSuppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose also that w tuples satisfy both conditions C and D where w≤ min(v , w). Then the left hand side will return those w tuples. On the right hand side, σC(R) produces u tuples and σD(R) produces v tuples. However, we know the intersection will produce the same w tuples in the result.When considering bags and sets, the only difference is bags allow duplicate tuples while sets only allow one copy of the tuple. The example above applies to both cases.Therefore the law holds.Exercise 5.1.5aFor sets, an arbitrary tuple t appears on the left hand side if it appears in both R,S and not in T. The same is true for the right hand side.As an example for bags, suppose that tuple t appears one time each in both R,T and two times in S. The result of the left hand side would have zero copies of tuple t while the right hand side would have one copy of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5bFor sets, an arbitrary tuple t appears on the left hand side if it appears in R and either S or T. This is equivalent to saying tuple t only appears when it is in at least R and S or in R and T. The equivalence is exactly the right side’s expression.As an example for bags, suppose that tuple t appears one time in R and two times each in S and T. Then the left hand side would have one copy of tuple t in the result while the right hand side would have two copies of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5cFor sets, an arbitrary tuple t appears on the left hand side if it satisfies condition C, condition D or both condition C and D. On the right hand side, σC(R) selects those tuples that satisfy condition C while σD(R) selects those tuples that satisfy condition D. However, the union operator will eliminate duplicate tuples, namely those tuples that satisfy both condition C and D. Thus we are ensured that both sides are equivalent.As an example for bags, we only need to look at the union operator. If there are indeed tuples that satisfy both conditions C and D, then the right hand side will contain duplicate copies of those tuples. The left hand side, however, will only have one copy for each tuple of the original set of tuples.A+B A2B210154910164167916 Exercise 5.2.1bB+1C-1103334431143 Exercise 5.2.1cA B0101232434 Exercise 5.2.1dB C010224253434A B01232434 Exercise 5.2.1fB C0124253402 Exercise 5.2.1gA SUM(B)022734 Exercise 5.2.1hB AVG(C)0 1.52 4.534 Exercise 5.2.1iA23Exercise 5.2.1jA MAX(C)24 Exercise 5.2.1kA B C23423401┴01┴24┴34┴Exercise 5.2.1lA B C234234┴01┴24┴25┴02 Exercise 5.2.1mA B C23423401┴01┴24┴34┴┴01┴24┴25┴02Exercise 5.2.1nA R.B S.B C0124012501340134012401250134013423┴┴24┴┴34┴┴┴┴01┴┴02Exercise 5.2.2aApplying the δ operator on a relation with no duplicates will yield the same relation. Thus δ is idempotent.Exercise 5.2.2bThe result of πL is a relation over the list of attributes L. Performing the projection again will return the same relation because the relation only contains the list of attributes L. Thus πL is idempotent.Exercise 5.2.2cThe result of σC is a relation where condition C is satisfied by every tuple. Performing the selection again will return the same relation because the relation only contains tuples that satisfy the condition C. Thus σC is idempotent.Exercise 5.2.2dThe result of γL is a relation whose schema consists of the grouping attributes and the aggregated attributes. If we perform the same grouping operation, there is no guarantee that the expression would make sense. The grouping attributes will still appear in the new result. However, the aggregated attributes may or may not appear correctly. If the aggregated attribute is given a different name than the original attribute, then performing γL would not make sense because it contains an aggregation for an attribute name that does not exist. In this case, the resultingrelation would, according to the definition, only contain the grouping attributes. Thus, γL is not idempotent.Exercise 5.2.2eThe result of τ is a sorted list of tuples based on some attributes L. If L is not the entire schema of relation R, then there are attributes that are not sorted on. If in relation R there are two tuples that agree in all attributes L and disagree in some of the remaining attributes not in L, then it is arbitrary as to which order these two tuples appear in the result. Thus, performing the operation τmultiple times can yield a different relation where these two tuples are swapped. Thus, τ is not idempotent.Exercise 5.2.3If we only consider sets, then it is possible. We can take πA(R) and do a product with itself. From this product, we take the tuples where the two columns are equal to each other.If we consider bags as well, then it is not possible. Take the case where we have the two tuples (1,0) and (1,0). We wish to produce a relation that contains tuples (1,1) and (1,1). If we use the classical operations of relational algebra, we can either get a result where there are no tuples or four copies of the tuple (1,1). It is not possible to get the desired relation because no operation can distinguish between the original tuples and the duplicated tuples. Thus it is not possible to get the relation with the two tuples (1,1) and (1,1).Exercise 5.3.1a)Answer(model) ← PC(model,speed,_,_,_) AND speed ≥ 3.00b)Answer(maker) ← Laptop(model,_,_,hd,_,_) AND Product(maker,model,_) AND hd ≥100c)Answer(model,price) ← PC(model,_,_,_,price) AND Product(maker,model,_) ANDmaker=’B’Answer(model,price) ← Laptop(model,_,_,_,_,price) AND Product(maker,model,_)AND maker=’B’Answer(model,price) ← Printer(model,_,_,price) AND Product(maker,model,_) ANDmaker=’B’d)Answer(model) ← Printer(model,color,type,_) AND color=’true’ AND type=’laser’e)PCMaker(maker) ← Product(maker,_,type) AND type=’pc’LaptopMaker(maker) ← Product(maker,_,type) AND type=’laptop’Answer(maker) ← LaptopMaker(maker) AND NOT PCMaker(maker)f)Answer(hd) ← PC(model1,_,_,hd,_) AND PC(model2,_,_,hd,_) AND model1 <>model2g)Answer(model1,model2) ← PC(model1,speed, ram,_,_) ANDPC(model2,_speed,ram,_,_) AND model1 < model2h)FastComputer(model) ← PC(model,speed,_,_,_) AND speed ≥ 2.80FastComputer(model) ← Laptop(model,speed,_,_,_,_) AND speed ≥ 2.80Answer(maker) ← Product(maker,model1,_) AND Product(maker,model2,_) ANDFastComputer(model1) AND FastComputer(model2) AND model1 <> model2i)Computers(model,speed) ← PC(model,speed,_,_,_)Computers(model,speed) ← Laptop(model,speed,_,_,_,_)SlowComputers(model) ← Computers(model,speed) AND Computers(model1,speed1) AND speed < speed1FastestComputers(model) ← Computers(model,_) AND NOT SlowComputers(model)Answer(maker) ← FastestComputers(model) AND Product(maker,model,_) j)PCs(maker,speed) ← PC(model,speed,_,_,_) AND Product(maker,model,_) Answer(maker) ← PCs(maker,speed) AND PCs(maker,speed1) ANDPCs(maker,speed2) AND speed <> speed1 AND speed <> speed2 AND speed1 <>speed2k)PCs(maker,model) ← Product(maker,model,type) AND type=’pc’Answer(maker) ← PCs(maker,model) AND PCs(maker,model1) ANDPCs(maker,model2) AND PCs(maker,model3) AND model <> model1 AND model <> model2 AND model1 <> model2 AND (model3 = model OR model3 = model1 ORmodel3 = model2)Exercise 5.3.2a)Answer(class,country) ← Classes(class,_,country,_,bore,_) AND bore ≥ 16b)Answer(name) ← Ships(name,_,launched) AND launched < 1921c)Answer(ship) ← Outcomes(ship,battle,result) AND battle=’Denmark Strait’ AND result= ‘sunk’d)Answer(name) ← Classes(class,_,_,_,_,displacement) AND Ships(name,class,launched)AND displacement > 35000 AND launched > 1921e)Answer(name,displacement,numGuns) ← Classes(class,_,_,numGuns,_,displacement)AND Ships(name,class,_) AND Outcomes (ship,battle,_) AND battle=’Guadalcanal’AND ship=namef)Answer(name) ← Ships(name,_,_)Answer(name) ← Outcomes(name,_,_) AND NOT Answer(name)g)MoreThanOne(class) ← Ships(name,class,_) AND Ships(name1,class,_) AND name <>name1Answer(class) ← Classes(class,_,_,_,_,_) AND NOT MoreThanOne(class)h)Battleship(country) ← Classes(_,type,country,_,_,_) AND type=’bb’Battlecruiser(country) ← Classes(_,type,country,_,_,_) AND type=’bc’Answer(country) ← Battleship(country) AND Battlecruiser(country)i)Results(ship,result,date) ← Battles(name,date) AND Outcomes(ship,battle,result) ANDbattle=nameAnswer(ship) ← Results(ship,result,date) AND Results(ship,_,date1) ANDresult=’damaged’ AND date < date1Exercise 5.3.3Answer(x,y) ← R(x,y) AND z = zExercise 5.4.1aAnswer(a,b,c) ← R(a,b,c)Answer(a,b,c) ← S(a,b,c)Exercise 5.4.1bAnswer(a,b,c) ← R(a,b,c) AND S(a,b,c)Exercise 5.4.1cAnswer(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)Exercise 5.4.1dUnion(a,b,c) ← R(a,b,c)Union(a,b,c) ← S(a,b,c)Answer(a,b,c) ← Union(a,b,c) AND NOT T(a,b,c)Exercise 5.4.1eJ(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)K(a,b,c) ← R(,a,b,c) AND NOT T(a,b,c)Answer(a,b,c) ← J(a,b,c) AND K(a,b,c)Exercise 5.4.1fAnswer(a,b) ← R(a,b,_)Exercise 5.4.1gJ(a,b) ← R(a,b,_)K(a,b) ← S(_,a,b)Answer(a,b) ← J(a,b) AND K(a,b)Exercise 5.4.2aAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2bAnswer(x,y,z) ← R(x,y,z) AND x < y AND y < z Exercise 5.4.2cAnswer(x,y,z) ← R(x,y,z) AND x < yAnswer(x,y,z) ← R(x,y,z) AND y < zExercise 5.4.2dChange:NOT(x < y OR x > y)To:x ≥ y AND x ≤ yThe above simplifies to x = yAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2eChange:NOT((x < y OR x > y) AND y < z)NOT(x < y OR x > y) OR y ≥ z(x ≥ y AND x ≤ y) OR y ≥ zTo:x = y OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x = yAnswer(x,y,z) ← R(x,y,z) AND y ≥ zExercise 5.4.2fChange:NOT((x < y OR x < z) AND y < z)NOT(x < y OR x < z) OR y ≥ z To:(x ≥ y AND x ≥ z) OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x ≥ y AND x ≥ zAnswer(x,y,z) ← R(x,y,z) AND y ≥zExercise 5.4.3aAnswer(a,b,c,d) ← R(a,b,c) AND S(b,c,d)Exercise 5.4.3bAnswer(b,c,d,e) ← S(b,c,d) AND T(d,e)Exercise 5.4.3cAnswer(a,b,c,d,e) ← R(a,b,c) AND S(b,c,d) AND T(d,e)Exercise 5.4.4a)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syb)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < sy AND ry < szc)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry < szd)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = sye)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szf)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx ≥ sy AND rx ≥ szAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szExercise 5.4.5aR1 := πx,y(Q R)Exercise 5.4.5bR1 := ρR1(x,z)(Q)R2 := ρR2(z,y)(Q)R3 := πx,y(R1 (R1.z = R2.z) R2)Exercise 5.4.5cR1 := πx,y(Q R)R2 := σx < y(R1)。
mysql数据库武洪萍版第五章习题与答案
第五章一.选择题1.下列关于SQL语言索引(Index)的叙述中,哪一条是不正确的(C)。
A.索引是外模式B.一个基本表上可以创建多个索引C.索引可以加快查询的执行速度D.系统在存取数据时会自动选择合适的索引作为存取路径2.为了提高特定查询的速度,对SC(S#,C#,DEGREE)关系创建唯一性索引,应该创建在哪一个属性(组)上?(A)A.(S#,C#)B. (S#,DEGREE)C. (C#,DEGREE)D. DEGREE3.设S_AVG(SNO,AVG_GRADE)是一个基于关系SC 定义的学号和他的平均成绩的视图。
下面对该视图的操作语句中,(A)是不能正确执行的。
Ⅰ. UODATE S_AVG SET AVG_GRADE=90 WHERE SNO='2004010601'Ⅱ. SELECT SNO,AVG_GRADE FROM S_AVG WHERE SNO='2004010601'A . 仅Ⅰ B. 仅Ⅱ C. 都能 D.都不能4.在视图上不能完成的操作是(C)。
A.更新视图B. 查询C. 在视图上定义新的基本表D. 在视图上定义新视图5.在SQL语言中,删除一个视图的命令是(B)。
A.DELECTB. DROPC. CLEARD. UNION6.为了使索引建的值在基本表中唯一,在创建索引的语句中应使用保留字()。
A.UNIQUEB. COUNTC. DISTINCTD.UNION7.创建索引是为了(A)。
A.提高存取速度B. 减少I/OC. 节约空间D. 减少缓冲区个数8.在关系数据库中,视图(View )是三级模式结构中的(D)。
A.内模式B. 模式C. 存取模式D. 外模式9.视图是一个“虚表”,视图的构造基于(A)。
Ⅰ.基本表Ⅱ. 视图Ⅲ. 索引10.已知关系:STUDENT(Sno,Sname,Grade),以下关于命令”CREATE INDEX S index ON STUDENT(Grade)”的描述中,正确的是(B)。
数据库第五章课后习题答案
数据库第五章课后习题答案关系规范化理论题⽬4.20 设关系模式R(ABC),F是R上成⽴的FD集,F={B→A,C→A },ρ={AB,BC }是R上的⼀个分解,那么分解ρ是否保持FD集F?并说明理由。
答:已知F={ B→A,C→A },⽽πAB(F)={ B→A },πBC(F)=φ,显然,分解ρ丢失了FD C→A。
4.21 设关系模式R(ABC),F是R上成⽴的FD集,F={B→C,C→A },那么分解ρ={AB,AC }相对于F,是否⽆损分解和保持FD?并说明理由。
答:①已知F={ B→C,C→A },⽽πAB(F)=φ,πAC(F)={ C→A }显然,这个分解丢失了FD B→C②⽤测试过程可以知道,ρ相对于F是损失分解。
4.22 设关系模式R(ABCD),F是R上成⽴的FD集,F={A→B,B→C,A→D,D→C },ρ={AB,AC,BD }是R的⼀个分解。
①相对于F,ρ是⽆损分解吗?为什么?②试求F在ρ的每个模式上的投影。
③ρ保持F吗?为什么?答:①⽤测试过程可以知道,ρ相对于F是损失分解。
②πAB(F)={ A→B },πAC(F)={ A→C },πBD(F)=φ。
③显然,分解ρ不保持FD集F,丢失了B→C、A→D和D→C等三个FD。
4.23设关系模式R(ABCD),R上的FD集F={A→C,D→C,BD→A},试说明ρ={AB,ACD,BCD }相对于F是损失分解的理由。
答:据已知的F集,不可能把初始表格修改为有⼀个全a⾏的表格,因此ρ相对于F是损失分解。
4.24 设关系模式R(ABCD)上FD集为F,并且F={A→B,B→C,D→B}。
① R分解成ρ={ACD,BD},试求F在ACD和BD上的投影。
② ACD和BD是BCNF吗?如不是,望分解成BCNF。
解:① F在模式ACD上的投影为{A→C,D→C},F在模式BD上的投影为{D→B}。
②由于模式ACD的关键码是AD,因此显然模式ACD不是BCNF。
数据库系统概论第五版课后答案
数据库系统概论第五版课后答案目录第一章基础 (2)第二章关系数据库 (16)第三章关系数据库语言SQL (18)第四章数据库安全性 (26)第 5 章数据库完整性 (34)第 6 章关系数据库理论 (39)第七章数据库设计 (44)第一章基础1 . 试述数据、数据库、数据库系统、数据库管理系统的概念。
答:( l ) 数据( Data ) :描述事物的符号记录称为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义是不可分的。
解析在现代计算机系统中数据的概念是广义的。
早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。
现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。
数据与其语义是不可分的。
500 这个数字可以表示一件物品的价格是500 元,也可以表示一个学术会议参加的人数有500 人,还可以表示一袋奶粉重500 克。
( 2 ) 数据库( DataBase ,简称DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按一定的数据模型组织、描述和储存,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。
( 3 ) 数据库系统( DataBas 。
Sytem ,简称DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具) 、应用系统、数据库管理员构成。
解析数据库系统和数据库是两个概念。
数据库系统是一个人一机系统,数据库是数据库系统的一个组成部分。
但是在日常工作中人们常常把数据库系统简称为数据库。
希望读者能够从人们讲话或文章的上下文中区分“数据库系统”和“数据库”,不要引起混淆。
( 4 ) 数据库管理系统( DataBase Managementsytem ,简称DBMs) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。
数据库设计第五章(高教版)含课后答案
数据库设计第五章(⾼教版)含课后答案第5章数据库设计与ER模型5.1 基本内容分析5.1.1 本章重要概念(1)DBS⽣存期及其7个阶段的任务和⼯作,DBD过程的输⼊和输出。
(2)概念设计的重要性、主要步骤。
逻辑设计阶段的主要步骤。
(3)ER模型的基本元素,属性的分类,联系的元数、连通词、基数。
采⽤ER⽅法的概念设计步骤。
(4)ER模型到关系模型的转换规则。
采⽤ER⽅法的逻辑设计步骤。
(5)ER模型的扩充:弱实体,超类和⼦类。
5.1.2 本章的重点篇幅(1)教材中P193-194的转换规则和实例。
(2)教材中P196-200的四个ER模型实例。
5.1.3 对ER模型的理解ER模型是⼈们认识客观世界的⼀种⽅法、⼯具。
ER模型具有客观性和主观性两重含义。
ER模型是在客观事物或系统的基础上形成的,在某种程度上反映了客观现实,反映了⽤户的需求,因此ER模型具有客观性。
但ER模型⼜不等同于客观事物的本⾝,它往往反映事物的某⼀⽅⾯,⾄于选取哪个⽅⾯或哪些属性,如何表达则决定于观察者本⾝的⽬的与状态,从这个意义上说,ER模型⼜具有主观性。
ER模型的设计过程,基本上是两⼤步:·先设计实体类型(此时不要涉及到“联系”);·再设计联系类型(考虑实体间的联系)。
具体设计时,有时“实体”与“联系”两者之间的界线是模糊的。
数据库设计者的任务就是要把现实世界中的数据以及数据间的联系抽象出来,⽤“实体”与“联系”来表⽰。
另外,设计者应注意,ER模型应该充分反映⽤户需求,ER模型要得到⽤户的认可才能确定下来。
5.2 教材中习题5的解答5.1名词解释(1)·软件⼯程:研究如何⽤科学知识、⼯程⽅⾯的纪律指导软件开发的过程,以提⾼软件质量和开发效率,降低开发成本,这样的⼀门学科称为“软件⼯程”。
·软件⽣存期:软件⽣存期是指从软件的规划、研制、实现、投⼊运⾏后的维护,直到它被新的软件所取代⽽停⽌使⽤的整个期间。
数据库原理及应用第5章课后习题答案
习题51、 理解并给出下列术语的定义:1)设R(U)是一个属性集U 上的关系模式,X 和Y 是U 的子集。
若对于R(U)的任意一个可能的关系r ,r 中不可能存在两个元组在X 上的属性值相等, 而在Y 上的属性值不等, 则称 X 函数确定Y 或 Y 函数依赖于X ,记作X →Y 。
2) 完全函数依赖在R(U)中,如果X →Y ,并且对于X 的任何一个真子集X ’,都有Y 不函数依赖于X ’ ,则称Y 对X 完全函数依赖,记作Y X F −→−3) 部分函数依赖若X →Y ,但Y 不完全函数依赖于X ,则称Y 对X 部分函数依赖,记作Y X p −→−4) 传递函数依赖在R(U)中,如果X →Y ,(Y ⊆X) , Y →X ,Y →Z , 则称Z 对X 传递函数依赖。
记为:Z X T−→−注: 如果Y →X , 即X ←→Y ,则Z 直接依赖于X 。
5)候选码设K 为R (U,F )的属性或属性组合。
若U K F →, 则K 称为R 的侯选码。
6)主码:若候选码多于一个,则选定其中的一个作为主码。
7)外码:关系模式 R 中属性或属性组X 并非 R 的码,但 X 是另一个关系模式的码,则称 X 是R 的外部码(Foreign key )也称外码8)如果一个关系模式R 的所有属性都是不可分的基本数据项,则R ∈1NF.9)若R ∈1NF ,且每一个非主属性完全函数依赖于码,则R ∈2NF 。
10)如果R(U,F )∈2NF ,并且所有非主属性都不传递依赖于主码,则R(U,F )∈3NF 。
11)关系模式R (U ,F )∈1NF ,若X →Y 且Y ⊆ X 时X 必含有码,则R (U ,F ) ∈BCNF 。
12)关系模式R<U ,F>∈1NF ,如果对于R 的每个非平凡多值依赖X →→Y (Y ⊆ X ),X 都含有码,则R ∈4NF 。
2、 关系规范化的操作异常有哪些?1) 数据冗余大2) 插入异常3) 删除异常4) 更新异常3、 第一范式、第二范式和第三范式关系的关系是什么?4、 已知关系模式R(A,B,C,D,E)及其上的函数依赖集合F={A->D,B->C,E-> A},该关系模式的候选码是什么?候选码为:(E,B)5、 已知学生表(学号,姓名,性别,年龄,系编号,系名称),存在的函数依赖集合是{学号->姓名,学号->性别,学号->年龄,学号->系编号,系编号->系名称},判断其满足第几范式。
第五章王珊,萨师煊版《数据库系统概论》讲义及课后习题答案
完整性约束条件分类
六类完整性约束条件
•
静态列级约束 静态元组约束 静态关系约束 动态列级约束 动态元组约束 动态关系约束
• • • • •
完整性约束条件(续)
对象状态 动态 动态列级约束 ④ 静态列级约束 ① 动态元组约束 ⑤ 动态关系约束 ⑥
静态
静态元组约束 静态关系约束 ② ③
列
元组
关系
对象粒度
4. 修改被参照关系中主码的问题
• 两种策略 (1)不允许修改主码 (2)允许修改主码
允许修改主码策略
• 违约操作 ♦要修改被参照关系中某些元组的主码值, 而参照关系中有些元组的外码值正好等 于被参照关系要修改的主码值 ♦要修改参照关系中某些元组的主码值, 而被参照关系中没有任何元组的外码值 等于被参照关系修改后的主码值
允许修改主码策略
例:将Student关系中Sno=950001的元组中Sno 值改为960123。而SC关系中有 4个元组的 Sno=950001 – 级联修改:将SC关系中4个Sno=950001元组 中的Sno值也改为960123。如果参照关系同时 又是另一个关系的被参照关系,则这种修改操 作会继续级联下去。
一般是拒绝执行
• 违反参照完整性的操作:
– 拒绝执行 – 接受这个操作,同时执行一些附加的操作,以保证 数据库的状态正确
三、参照完整性的实现
例:职工-部门数据库包含职工表EMP和部门表DEPT
1 DEPT关系的主码为部门号Deptno 2 EMP关系的主码为职工号Empno, 外码为部门号Deptno 称DEPT为被参照关系或目标关系,EMP为参照关系
3.在参照关系中插入元组时的问题
• 受限插入 – 仅当被参照关系中存在相应的元组,其主码值 与参照关系插入元组的外码值相同时,系统才 执行插入操作,否则拒绝此操作。 • 递归插入 – 首先向被参照关系中插入相应的元组,其主码 值等于参照关系插入元组的外码值,然后向参 照关系插入元组。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Exercise 5.1.1 As a set:Average = 2.37 As a bag:Average = 2.48 Exercise 5.1.2 As a set:Average = 218 As a bag:Average = 215 Exercise 5.1.3a As a set:As a bag:Exercise 5.1.3bπbore(Ships Classes)Exercise 5.1.4aFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the union of bags R and S will have tuple t appear n + m times. The further union of bag T with the tuple t appearing o times will have tuple t appear n + m + o times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the union of bags R and S will have tuple t appear m + o times. The further union of bag R with the tuple t appearing n times will have tuple t appear m + o + n times in the final result.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result. Since we cannot have duplicates, the result only has at most one copy of the tuple t.Exercise 5.1.4bFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the intersectionof bags R and S will have tuple t appear min( n, m ) times. The further intersection of bag T with the tuple t appearing o times will produce tuple t min( o, min( n, m ) ) times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the intersection of bags R and S will have tuple t appear min( m, o ) times. The further intersection of bag R with the tuple t appearing n times will produce tuple t min( n, min( m, o ) ) times in thefinal result.The intersection of bags R,S and T will yield a result where tuple t appears min( n,m,o ) times. For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result.Exercise 5.1.4cFor bags:On the left-hand side:Given that tuple r in R, which appears m times, can successfully join with tuple s in S,which appears n times, we expect the result to contain mn copies. Also given that tuple tin T, which appears o times, can successfully join with the joined tuples of r and s, weexpect the final result to have mno copies.On the right-hand side:Given that tuple s in S, which appears n times, can successfully join with tuple t in T,which appears o times, we expect the result to contain no copies. Also given that tuple rin R, which appears m times, can successfully join with the joined tuples of s and t, weexpect the final result to have nom copies.The order in which we perform the natural join does not matter for bags.For sets:This is a similar case when dealing with bags except the joined tuples can only appear at most once in each result. If there are tuples r,s,t in relations R,S,T that can successfully join, then the result will contain a tuple with the schema of their joined attributes.Exercise 5.1.4dFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two bags R ⋃ S, tuple t would appear n + m times. Likewise, in the union of these two bags S ⋃ R, tuple t would appear m + n times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in both sets R and S will the union R ⋃ S have the tuple t. The same reasoning holds when we take the union S ⋃ R.Therefore the commutative law for union holds.Exercise 5.1.4eFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these two bags R ∩ S, tuple t would appear min( n,m ) times. Likewise in the intersection of these two bags S ∩ R, tuple t would appear min( m,n ) times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in at least one of the sets R and S will the intersection R ∩ S have the tuple t. The same reasoning holds when we take the intersection S ∩ R.Therefore the commutative law for intersection holds.Exercise 5.1.4fFor bags:Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that the two tuples t,u can successfully join. Then in the natural join of these two bags R S, the joined tuple would appear nm times. Likewise in the natural join of these two bags S R, the joined tuple would appear mn times. Both sides of the relation yield the same result.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuples u,v might appear respectively in sets R and S one or zero times. The combinations of number of occurrences for tuples u,v in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple u exists in Rand tuple v exists in S will the natural join R S have the joined tuple. The same reasoning holds when we take the natural join S R.Therefore the commutative law for natural join holds.Exercise 5.1.4gFor bags:Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L will yield a resulting relation where the projected attributes from tuple t appear m + n times. If we take the projection of the attributes in list L first, then the projected attributes from tuple t would appear m times from R and n times from S. The union of these resulting relations would have the projected attributes of tuple t appear m + n times.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t exists in R or S (or both R and S) will the projected attributes of tuple t appear in the result.Therefore the law holds.Exercise 5.1.4hFor bags:Suppose tuple t appears u times in R, v times in S and w times in T. On the left hand side, the intersection of S and T would produce a result where tuple t would appear min(v , w) times. With the addition of the union of R, the overall result would have u + min(v , w) copies of tuple t. On the right hand side, we would get a result of min(u + v, u + w) copies of tuple t. The expressions on both the left and right sides are equivalent.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R,S and T one or zero times. The combinations of number of occurrences for tuple t in R, S and T respectively are (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Only when tuple t appears in R or in both S and T will the result have tuple t.Therefore the distributive law of union over intersection holds.Exercise 5.1.4iSuppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose also that w tuples satisfy both conditions C and D where w≤ min(v , w). Then the left hand side will return those w tuples. On the right hand side, σC(R) produces u tuples and σD(R) produces v tuples. However, we know the intersection will produce the same w tuples in the result.When considering bags and sets, the only difference is bags allow duplicate tuples while sets only allow one copy of the tuple. The example above applies to both cases.Therefore the law holds.Exercise 5.1.5aFor sets, an arbitrary tuple t appears on the left hand side if it appears in both R,S and not in T. The same is true for the right hand side.As an example for bags, suppose that tuple t appears one time each in both R,T and two times in S. The result of the left hand side would have zero copies of tuple t while the right hand side would have one copy of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5bFor sets, an arbitrary tuple t appears on the left hand side if it appears in R and either S or T. This is equivalent to saying tuple t only appears when it is in at least R and S or in R and T. The equivalence is exactly the right side’s expression.As an example for bags, suppose that tuple t appears one time in R and two times each in S and T. Then the left hand side would have one copy of tuple t in the result while the right hand side would have two copies of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5cFor sets, an arbitrary tuple t appears on the left hand side if it satisfies condition C, condition Dor both condition C and D. On the right hand side, σC(R) selects those tuples that satisfy condition C while σD(R) selects those tuples that satisfy condition D. However, the union operator will eliminate duplicate tuples, namely those tuples that satisfy both condition C and D. Thus we are ensured that both sides are equivalent.As an example for bags, we only need to look at the union operator. If there are indeed tuples that satisfy both conditions C and D, then the right hand side will contain duplicate copies of those tuples. The left hand side, however, will only have one copy for each tuple of the original set of tuples.Exercise 5.2.1bExercise 5.2.1cExercise 5.2.1dExercise 5.2.1fExercise 5.2.1gExercise 5.2.1hExercise 5.2.1iExercise 5.2.1jExercise 5.2.1kExercise 5.2.1lExercise 5.2.1mExercise 5.2.1nExercise 5.2.2aApplying the δ operator on a relation with no duplicates will yield the same relation. Thus δ is idempotent.Exercise 5.2.2bThe result of πL is a relation over the list of attributes L. Performing the projection again will return the same relation because the relation only contains the list of attributes L. Thus πL is idempotent.Exercise 5.2.2cThe result of σC is a relation where condition C is satisfied by every tuple. Performing the selection again will return the same relation because the relation only contains tuples that satisfy the condition C. Thus σC is idempotent.Exercise 5.2.2dThe result of γL is a relation whose schema consists of the grouping attributes and the aggregated attributes. If we perform the same grouping operation, there is no guarantee that the expression would make sense. The grouping attributes will still appear in the new result. However, the aggregated attributes may or may not appear correctly. If the aggregated attribute is given a different name than the original attribute, then performing γL would not make sense because it contains an aggregation for an attribute name that does not exist. In this case, the resultingrelation would, according to the definition, only contain the grouping attributes. Thus, γL is not idempotent.Exercise 5.2.2eThe result of τ is a sorted list of tuples based on some attributes L. If L is not the entire schema of relation R, then there are attributes that are not sorted on. If in relation R there are two tuples that agree in all attributes L and disagree in some of the remaining attributes not in L, then it is arbitrary as to which order these two tuples appear in the result. Thus, performing the operation τ multiple times can yield a different relation where these two tuples are swapped. Thus, τ is not idempotent.Exercise 5.2.3If we only consider sets, then it is possible. We can take πA(R) and do a product with itself. From this product, we take the tuples where the two columns are equal to each other.If we consider bags as well, then it is not possible. Take the case where we have the two tuples (1,0) and (1,0). We wish to produce a relation that contains tuples (1,1) and (1,1). If we use the classical operations of relational algebra, we can either get a result where there are no tuples or four copies of the tuple (1,1). It is not possible to get the desired relation because no operation can distinguish between the original tuples and the duplicated tuples. Thus it is not possible to get the relation with the two tuples (1,1) and (1,1).Exercise 5.3.1a)Answer(model) ← PC(model,speed,_,_,_) AND speed ≥ 3.00b)Answer(maker) ← Laptop(model,_,_,hd,_,_) AND Product(maker,model,_) AND hd ≥100c)Answer(model,price) ← PC(model,_,_,_,price) AND Product(maker,model,_) ANDmaker=’B’Answer(model,price) ← Laptop(mode l,_,_,_,_,price) AND Product(maker,model,_)AND maker=’B’Answer(model,price) ← Printer(model,_,_,price) AND Product(maker,model,_) ANDmaker=’B’d)Answer(model) ← Printer(model,color,type,_) AND color=’true’ AND type=’laser’e)PCMaker(maker) ← Product(maker,_,type) AND type=’pc’LaptopMaker(maker) ← Product(maker,_,type) AND type=’laptop’Answer(maker) ← LaptopMaker(maker) AND NOT PCMaker(maker)f)Answer(hd) ← PC(model1,_,_,hd,_) AND PC(model2,_,_,hd,_) AND model1 <>model2g)Answer(model1,model2) ← PC(model1,speed, ram,_,_) ANDPC(model2,_speed,ram,_,_) AND model1 < model2h)FastComputer(model) ← PC(model,speed,_,_,_) AND speed ≥ 2.80FastComputer(model) ← Laptop(model,speed,_,_,_,_) AND speed ≥ 2.80Answer(maker) ← Product(maker,model1,_) AND Product(maker,mod el2,_) ANDFastComputer(model1) AND FastComputer(model2) AND model1 <> model2i)Computers(model,speed) ← PC(model,speed,_,_,_)Computers(model,speed) ← Laptop(model,speed,_,_,_,_)SlowComputers(model) ← Computers(model,speed) AND Computers(model1,speed1)AND speed < speed1FastestComputers(model) ← Computers(model,_) AND NOT SlowComputers(model)Answer(maker) ← Fast estComputers(model) AND Product(maker,model,_)j)PCs(maker,speed) ← PC(model,speed,_,_,_) AND Product(maker,model,_) Answer(maker) ← PCs(maker,spe ed) AND PCs(maker,speed1) AND PCs(maker,speed2) AND speed <> speed1 AND speed <> speed2 AND speed1 <> speed2k)PCs(maker,model) ← Product(maker,model,type) AND type=’pc’Answer(maker) ← PCs(maker,model) AND PCs(maker,model1) ANDPCs(maker,model2) AND PCs(maker,model3) AND model <> model1 AND model <>model2 AND model1 <> model2 AND (model3 = model OR model3 = model1 ORmodel3 = model2)Exercise 5.3.2a)Answer(class,country) ← Classes(class,_,country,_,bore,_) AND bore ≥ 16b)Answer(name) ← Ships(name,_,launch ed) AND launched < 1921c)Answer(ship) ← Outcomes(ship,battle,result) AND battle=’Denmark Strait’ AND result= ‘sunk’d)Answer(name) ← Classes(class,_,_,_,_,displacement) AND Ships(name,class,launched)AND displacement > 35000 AND launched > 1921e)Answer(nam e,displacement,numGuns) ← Classes(class,_,_,numGuns,_,displacement)AND Ships(name,class,_) AND Outcomes (ship,battle,_) AND battle=’Guadalcanal’AND ship=namef)Answer(name) ← Ships(name,_,_)Answer(name) ← Outcomes(name,_,_) AND NOT Answer(name)g)MoreThan One(class) ← Ships(name,class,_) AND Ships(name1,class,_) AND name <>name1Answer(class) ← Classes(class,_,_,_,_,_) AND NOT MoreThanOne(class)h)Battleship(country) ← Classes(_,type,country,_,_,_) AND type=’bb’Battlecruiser(country) ← Classes(_,type,country,_,_,_) AND type=’bc’Answer(country) ← Battleship(country) AND Battlecruiser(country)i)Results(ship,result,date) ← Battles(name,date) AND Outcomes(ship,battle,result) ANDbattle=nameAnswer(ship) ← Results(ship,result,date) AND Results(ship,_,date1) ANDresult=’damaged’ AND date < date1Exercise 5.3.3A nswer(x,y) ← R(x,y) AND z = zExercise 5.4.1aAnswer(a,b,c) ← R(a,b,c)Answer(a,b,c) ← S(a,b,c)Exercise 5.4.1bAnswer(a,b,c) ← R(a,b,c) AND S(a,b,c)Exercise 5.4.1cAnswer(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)Exercise 5.4.1dUnion(a,b,c) ← R(a,b,c)Union(a,b,c) ← S(a,b,c)Answer(a,b,c) ← Union(a,b,c) AND NOT T(a,b,c)Exercise 5.4.1eJ(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)K(a,b,c) ← R(,a,b,c) AND NOT T(a,b,c)Answer(a,b,c) ← J(a,b,c) AND K(a,b,c)Exercise 5.4.1fAnswer(a,b) ← R(a,b,_)Exercise 5.4.1gJ(a,b) ← R(a,b,_)K(a,b) ← S(_,a,b)Answer(a,b) ← J(a,b) AND K(a,b)Exercise 5.4.2aAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2bAnswer(x,y,z) ← R(x,y,z) AND x < y AND y < z Exercise 5.4.2cAnswer(x,y,z) ← R(x,y,z) AND x < yAnswer(x,y,z) ← R(x,y,z) AND y < zExercise 5.4.2dChange: NOT(x < y OR x > y)To: x ≥ y AND x ≤ yThe above simplifies to x = yAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2eChange: NOT((x < y OR x > y) AND y < z)NOT(x < y OR x > y) OR y ≥ z(x ≥ y AND x ≤ y) OR y ≥ zTo: x = y OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x = yAnswer(x,y,z) ← R(x,y,z) AND y ≥ zExercise 5.4.2fChange: NOT((x < y OR x < z) AND y < z)NOT(x < y OR x < z) OR y ≥ z To: (x ≥ y AND x ≥ z) OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x ≥ y AND x ≥ zAnswer(x,y,z) ← R(x,y,z) AND y ≥zExercise 5.4.3aAnswer(a,b,c,d) ← R(a,b,c) AND S(b,c,d)Exercise 5.4.3bAnswer(b,c,d,e) ← S(b,c,d) AND T(d,e)Exercise 5.4.3cAnswer(a,b,c,d,e) ← R(a,b,c) AND S(b,c,d) AND T(d,e)Exercise 5.4.4a)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syb)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < sy AND ry < szc)Answer(rx,ry,rz,sx,sy,s z) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry < szd)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = sye)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syAnswe r(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szf)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx ≥ sy AND rx ≥ szAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szExercise 5.4.5aR1 := πx,y(Q R)Exercise 5.4.5bR1 := ρR1(x,z)(Q)R2 := ρR2(z,y)(Q)R3 := πx,y(R1 (R1.z = R2.z) R2)Exercise 5.4.5cR1 := πx,y(Q R)R2 := σx < y(R1)。