数据库系统概念原书第六版第八章

合集下载

数据库系统概论目录

数据库系统概论目录

第一篇基础篇第一章绪论1.1数据库系统概述1.1.1 四个基本概念1.1.2 数据管理技术的产生和发展1.1.3 数据库系统的特点1.2数据模型1.2.1 两大类数据模型1.2.2 数据模型的组成要素1.2.3 概念模型1.2.4 最常用的数据模型1.2.5 层次模型1.2.6 网状模型1.2.7 关系模型1.3数据库系统结构1.3.1 数据库系统模式的概念1.3.2 数据库系统的三级模式结构1.3.3 数据库的二级映像功能与数据独立性1.4数据库系统的组成1.5小结第二章关系数据库2.1关系数据结构及形式化定义2.1.1 关系2.1.2 关系模式2.1.3 关系数据库2.2关系操作2.2.1基本关系操作2.2.2 关系数据库语言的分类2.3关系的完整性2.3.1 关系的三类完整性约束2.3.2 实体完整性2.3.3 参照完整性2.3.4 用户定义的完整性2.4关系代数2.4.1传统的集合运算2.4.2专门的关系运算2.5关系演算2.6小结第三章关系数据库标准语言SQL3.1SQL概述3.1.1 SQL 的产生与发展3.1.2 SQL的特点3.1.3 SQL的基本概念3.2学生-课程数据库3.3数据定义3.3.1 模式的定义与删除3.3.2 基本表的定义、删除与修改3.3.3 索引的建立与删除3.4数据查询3.4.1 单表查询3.4.2 连接查询3.4.3 嵌套查询3.4.4 集合查询3.4.5 Select语句的一般形式3.5数据更新3.5.1 插入数据3.5.2 修改数据3.5.3 删除数据3.6视图3.6.1 定义视图3.6.2 查询视图3.6.3 更新视图3.6.4 视图的作用3.7小结第四章数据库安全性4.1计算机安全性概述4.1.1 计算机系统的三类安全性问题4.1.2 安全标准简介4.2数据库安全性控制4.2.1 用户标识与鉴别4.2.2 存取控制4.2.3 自主存取控制方法4.2.4 授权与回收4.2.5 数据库角色4.2.6 强制存取控制方法4.3视图机制4.4审计(Audit)4.5数据加密4.6统计数据库安全性4.7小结第五章数据库完整性5.1实体完整性5.1.1 实体完整性定义5.1.2 实体完整性检查和违约处理5.2参照完整性5.2.1 参照完整性定义5.2.2 参照完整性检查和违约处理5.3用户定义的完整性5.3.1 属性上的约束条件的定义5.3.2 属性上的约束条件检查和违约处理5.3.3 元组上的约束条件的定义5.3.4元组上的约束条件检查和违约处理5.4完整性约束命名子句*5.5域中的完整性限制5.6触发器5.6.1 定义触发器5.6.2 激活触发器5.6.3 删除触发器5.7小结第二篇设计与应用开发篇第六章关系数据理论6.1问题的提出6.2规范化6.2.1 函数依赖6.2.2 码6.2.3 范式6.2.4 2NF6.2.5 3NF6.2.6 BCNF6.2.7 多值依赖6.2.8 4NF6.2.9 规范化小结6.3数据依赖的公理系统*6.4模式的分解6.5小结第七章数据库设计7.1数据库设计概述7.1.1 数据库设计的特点7.1.2 数据库设计方法7.1.3 数据库设计的基本步骤7.1.4 数据库设计过程中的各级模式7.2需求分析7.2.1 需求分析的任务7.2.2 需求分析的方法7.2.3 数据字典7.3概念结构设计7.3.1 概念结构7.3.2 概念结构设计的方法与步骤7.3.3 数据抽象与局部视图设计7.3.4 视图的集成7.4逻辑结构设计7.4.1 E-R图向关系模型的转换7.4.2 数据模型的优化7.4.3 设计用户子模式7.5数据库的物理设计7.5.1 数据库物理设计的内容和方法7.5.2 关系模式存取方法选择7.5.3 确定数据库的存储结构7.5.4 评价物理结构7.6数据库的实施和维护7.6.1 数据的载入和应用程序的调试7.6.2 数据库的试运行7.6.3 数据库的运行和维护7.7小结第八章数据库编程8.1 嵌入式SQL8.1.1 嵌入式SQL的处理过程8.1.2 嵌入式SQL语句与主语言之间的通信8.1.3 不使用游标的SQL语句8.1.4 使用游标的SQL语句8.1.5 动态SQL8.1.6 小结8.2 存储过程8.2.1 PL/SQL的块结构8.2.2 变量常量的定义8.2.3 控制结构8.2.4 存储过程8.2.5 小结8.3 ODBC编程8.3.1 数据库互连概述8.3.2 ODBC工作原理概述8.3.3 ODBC API 基础8.3.4 ODBC的工作流程8.3.5 小结第三篇系统篇第九章关系查询处理和查询优化9.1 关系数据库系统的查询处理9.1.1 查询处理步骤9.1.2 实现查询操作的算法示例9.2 关系数据库系统的查询优化9.2.1 查询优化概述9.2.2 一个实例9.3 代数优化9.3.1 关系代数表达式等价变换规则9.3.2 查询树的启发式优化9.4 物理优化9.4.1 基于启发式规则的存取路径选择优化9.4.2 基于代价的优化9.5 小结第十章数据库恢复技术10.1 事务的基本概念10.2 数据库恢复概述10.3 故障的种类10.4 恢复的实现技术10.4.1 数据转储10.4.2 登记日志文件10.5 恢复策略10.5.1 事务故障的恢复10.5.2 系统故障的恢复10.5.3 介质故障的恢复10.6 具有检查点的恢复技术10.7 数据库镜像10.8 小结第十一章并发控制11.1 并发控制概述11.2 封锁11.3 活锁和死锁11.3.1 活锁11.3.2 死锁11.4 并发调度的可串行性11.4.1 可串行化调度11.4.2 冲突可串行化调度11.5 两段锁协议11.6 封锁的粒度11.6.1 多粒度封锁11.6.2 意向锁11.7 小结*第十二章数据库管理系统第四篇新技术篇第十三章数据库技术新发展*第十四章分布式数据库系统第十五章对象关系数据库系统第十六章XML数据库第十七章数据仓库与联机分析处理技术。

ch8数据库系统概念(第6版)第八章关系数据库设计

ch8数据库系统概念(第6版)第八章关系数据库设计

11
目标
决定特定的关系 R 是否有一个 “良好” 形式. 如果 R 不具有 “良好” 形式, 将其分解为关系集 {R1, R2, ..., Rn}, 满足 每个关系都有良好形式 该分解是无损连接分解 理论基于数据依赖: 函数依赖 多值依赖 连接依赖
数据依赖
属性之间的联系是属性间的相互依赖又相互制约的 关系, 这种关系称为数据依赖。 数据依赖:
中:
R = R1 R2
无损连接分解 对模式R上的所有可能的关系r r = R1 (r) R2 (r)
10
关系数据库设计中易犯的错误
关系数据库设计要求找到一个合理关系模式集合 . 一个不合理模式可能导致
信息的重复 某些信息不能表示
设计目标:
避免冗余数据 确保属性间联系得以表示 方便检查更新是否破坏了数据库完整性约束
building, room_number)
不会产生重复
有损分解
分解R = (A, B) R1 = (A)
A B A
R2 = (B)
B 1 2 B(r)

r
1 2 1

A(r) A B 1 2 1 2
A (r)
B (r)

7
有损分解 例
假设我们从 inst_dept 着手. 如何将它分开 (分解) 成为 instructor 和 department? 定一个规则 “如果存在模式 (dept_name, building, budget), 则 dept_name 会成为候选码” 表示为 函数依赖: dept_name building, budget 在 inst_dept 中, 由于 dept_name 不是候选码, 故一个部 门的大楼和预算可能会出现重复. 由此说明需要分解 inst_dept 不是怎样分解都合适. 假设我们把 employee(ID, name, street, city, salary) 分解为 employee1 (ID, name) employee2 (name, street, city, salary) 下个幻灯片会说明这将丢失信息 -- 无法重构原始的 employee 关系 -- 故这是一个 有损分解.

数据库系统概念英文精编版第六版教学设计

数据库系统概念英文精编版第六版教学设计

数据库系统概念英文精编版第六版教学设计介绍在本教学设计中,我们将介绍《Database System Concepts》(数据库系统概念)英文精编版第六版,旨在帮助学生掌握数据库系统的关键概念、基本结构以及数据库的设计和实现。

此教学设计将涵盖以下主题:•数据库基础知识•数据模型和ER图•SQL语言•数据库设计•事务管理和并发控制•数据库安全本教学设计旨在为初学者提供一个实践性的课程,旨在帮助学生掌握现代数据库系统的基础知识,并增强他们在实际生活和职业中利用数据库系统进行数据管理的能力。

教学内容数据库基础知识本节将首先介绍数据库系统的一些基础概念,如数据、数据库、数据库管理系统和关系数据库等。

学习者将学会如何使用SQL语句来完成基本的数据检索和修改。

数据模型和ER图本章将介绍抽象概念对于数据库设计的重要性。

学生们将学会如何使用实体关系(ER)图来表达数据库中各个实体之间的关系,从而方便设计和管理数据库。

SQL语言SQL是处理和查询关系数据的标准语言。

在本节中,我们将介绍SQL语言的不同方面,如数据定义、数据操作和嵌套查询等。

数据库设计数据库设计是一项关键性的工作,我们需要通过设计来确保数据库可以支持我们所需要的数据存储和管理。

本节将介绍关于设计和开发数据库的一些基本技术,如关系模式、规范化和冗余等。

事务管理和并发控制并发控制是数据库系统设计中最具挑战性的问题之一。

在本节中,我们将介绍什么是事务,事务管理和并发控制如何确保数据库在多个用户同时访问时仍然保持正确性。

数据库安全数据安全是建立在数据库的完整性和可用性之上的。

在本节中,我们将介绍一些关于数据库安全的基本概念,如授权和认证、数据加密等。

教学方法本教学设计采用电子教学的方式,其中,我们将提供录制的视频课程、示例问题、以及针对每个主题的在线测验。

本课程将使用不同的教学方法:•通过开放式问题和讨论区域,用以解释不同的概念。

•提供示例代码来增强实践性学习。

数据库系统概论第六版 教学大纲

数据库系统概论第六版 教学大纲

数据库系统概论第六版教学大纲
数据库系统概论第六版的教学大纲主要包括以下几个部分:
1. 数据库系统的基本概念:介绍数据库系统的定义、发展历程和基本原理,以及数据库系统的组成和体系结构。

2. 数据模型:介绍常见的数据模型,如层次模型、网状模型和关系模型,以及面向对象数据模型和XML数据模型等。

3. 数据库设计和规范化:介绍数据库设计的基本概念和原理,以及数据库设计和规范化的方法和步骤,包括需求分析、概念设计、逻辑设计、物理设计等。

4. 数据库管理系统:介绍数据库管理系统的基本功能和组成,以及数据库管理系统的工作原理和实现技术,包括存储管理、事务管理、并发控制、数据备份和恢复等。

5. 数据库系统应用:介绍数据库系统的应用领域和案例,包括企业级应用、电子商务、电子政务、物联网等。

6. 数据库系统性能优化:介绍数据库系统性能优化的方法和技巧,包括查询优化、索引优化、系统配置优化等。

7. 数据库安全和隐私保护:介绍数据库安全和隐私保护的基本概念和原理,以及数据库安全和隐私保护的技术和方法,包括访问控制、加密技术、审计等。

8. 数据库系统的未来发展:介绍数据库系统的未来发展趋势和方向,包括大数据处理、云计算、人工智能等。

以上是数据库系统概论第六版教学大纲的简要介绍,具体的教学内容和教学方法可以根据实际情况进行调整和补充。

数据库系统概念第六版课程设计

数据库系统概念第六版课程设计

数据库系统概念第六版课程设计一、选题背景随着信息技术的发展,数据的数量和类型变得越来越复杂和庞大,需要有效地管理和处理。

数据库系统作为数据管理的关键技术之一,应用广泛。

通过学习数据库系统的概念、原理和实现方法,可以帮助学生深入理解数据管理、数据结构和数据操作等基本概念,并掌握常用数据库系统的设计和开发方法。

本课程设计旨在通过对数据库系统概念第六版的学习和实践,帮助学生全面了解数据库系统的基础知识,提高数据管理和处理能力。

二、选题内容本课程设计主要包括以下几个部分:1.数据库设计与实现:根据给出的实际场景,设计一个关系型数据库,并使用MySQL实现。

包括数据模型设计、表结构设计、数据类型定义、SQL语句编写等内容。

2.数据库应用开发:基于Java语言和JDBC技术,开发一个简单的图书管理系统,实现图书的查询、添加、修改和删除等功能。

包括前端UI设计、后端业务逻辑实现和数据库操作等内容。

3.数据库性能调优:分析数据库在不同负载条件下的性能表现,设计和实施调优策略。

包括SQL语句优化、索引优化、缓存策略、服务器参数优化等内容。

4.数据库备份与恢复:制定数据库备份和恢复策略,实现对数据库的定时备份和快速恢复。

包括备份方案设计、恢复操作测试、恢复时间评估等内容。

三、选题目的通过此次课程设计,旨在达到以下目标:1.学生能够全面了解数据库系统的原理、架构和应用场景,掌握常用的关系型数据库系统的设计和开发方法。

2.学生能够运用Java语言和JDBC技术,开发一个简单的图书管理系统,掌握前后端交互和数据库操作等基本技能。

3.学生能够分析数据库在不同负载条件下的性能表现,能够设计和实施调优策略,提高数据库系统的运行效率。

4.学生能够制定数据库备份和恢复策略,实现对数据库的高效备份和快速恢复,提高数据安全性和可靠性。

四、选题材料本课程设计所需的主要材料包括:1.《数据库系统概念第六版》一书作为课程教材。

2.Java语言和JDBC技术相关的书籍和资料,如《Java核心技术》、《Java编程思想》等。

数据库系统概论教案

数据库系统概论教案

数据库系统概论教案第一章:数据库基础知识1.1 数据库概念介绍数据库的定义、发展历程和分类解释数据、信息、知识与数据之间的关系1.2 数据模型介绍实体-联系模型、关系模型、层次模型和网状模型等解释数据模型的概念和作用1.3 数据库系统的结构介绍数据库系统的三级模式结构:外模式、模式和内模式解释数据库管理系统(DBMS)的概念和功能第二章:关系数据库理论2.1 关系模型介绍关系模型的基本概念:关系、属性、元组和域解释关系代数和元组关系演算的概念2.2 关系的完整性约束介绍实体完整性、参照完整性和用户定义完整性解释完整性约束的作用和意义2.3 数据库设计介绍需求分析、概念设计、逻辑设计和物理设计等阶段解释数据库设计的方法和步骤第三章:SQL语言3.1 SQL概述介绍SQL语言的概念、特点和应用范围解释SQL语言的基本语法和操作3.2 数据定义语言介绍创建表、修改表和删除表的SQL语句解释数据类型、主键、外键和索引的概念3.3 数据操纵语言介绍插入、删除、更新和查询数据的SQL语句解释聚合函数、分组和排序等概念第四章:数据库查询优化4.1 查询优化概述介绍查询优化的目的和重要性解释查询优化的方法和策略4.2 查询优化技术介绍基于规则的优化和基于成本的优化等方法解释查询优化中的代价估算和执行计划等概念4.3 索引和查询优化介绍索引的概念、分类和作用解释索引的创建、维护和优化策略第五章:事务管理5.1 事务概念介绍事务的定义、属性(ACID)和类型解释事务的作用和意义5.2 事务管理机制介绍并发控制和一致性维护的机制解释锁定、死锁和事务隔离级别等概念5.3 事务编程介绍使用编程语言实现事务的方法解释事务的提交、回滚和恢复等操作第六章:数据库安全与保护6.1 数据库安全概述介绍数据库安全的重要性解释数据库安全策略和威胁类型6.2 访问控制介绍自主访问控制(DAC)和强制访问控制(MAC)解释角色Based 访问控制(RBAC)和属性基访问控制(ABAC)6.3 加密技术介绍对称加密和非对称加密的概念解释哈希函数和数字签名在数据库安全中的应用第七章:数据库备份与恢复7.1 备份策略介绍完全备份、差异备份和增量备份等备份策略解释备份的频率和时间点选择7.2 恢复机制介绍恢复基点和恢复策略解释使用备份文件进行数据恢复的步骤和注意事项7.3 灾难恢复介绍灾难恢复计划和数据中心的地理位置选择解释镜像站点和负载均衡在灾难恢复中的应用第八章:数据库性能调优8.1 性能调优概述介绍性能调优的目标和重要性解释性能调优的方法和策略8.2 查询优化介绍查询优化的方法和工具解释如何使用查询分析器分析查询执行计划8.3 系统参数调优介绍数据库系统参数的概念和作用解释如何调整系统参数以提高数据库性能第九章:分布式数据库系统9.1 分布式数据库概念介绍分布式数据库的定义和特点解释分布式数据库系统的架构和组件9.2 数据分布策略介绍垂直分区和水平分区的概念解释数据本地化和数据复制在分布式数据库中的应用9.3 分布式查询处理介绍分布式查询处理的挑战和解决方案解释分布式查询优化和数据一致性维护的策略第十章:数据库新技术与发展趋势10.1 云计算与数据库介绍云计算的概念和数据库在云计算中的应用解释云数据库服务的特点和优势10.2 大数据与数据库介绍大数据的概念和数据库在大数据处理中的应用解释NoSQL数据库和NewSQL数据库的特点和优势10.3 与数据库介绍的概念和数据库在中的应用解释数据库智能化和自动化查询推荐的概念重点和难点解析重点环节一:关系模型的基本概念和关系代数、元组关系演算补充和说明:关系模型是数据库理论的核心,掌握关系模型的基本概念是理解数据库操作的基础。

数据库系统概论第八章PPT学习教案

数据库系统概论第八章PPT学习教案
B=A+1=3
W rite(B) commit unlock(B)
是否为正确的 调度?即是否 为可串行化调 度?说明理由
第27页/共54页
8.2 并发控制概述(续)
T1 SlockA)
A=B+1=3 W rite(A) commit unlock(x)
只能再对A加S锁,而不能加X锁,直到T释放A上的S
锁,保证了其他事务可以读A,但是不能对A进行任
何修改。
第17页/共54页
8.2 并发控制概述(续)
第18页/共54页
8.2 并发控制概述(续)
T1 Xlock(x)
read(x) x:=x+1 write(x) commit unlock(x)
T2
基本的封锁类型:
写锁(排它锁,即X锁):若事务T对数据对象A加 上X锁,则只允许T读取和修改A,其他任何事务都 不能再对A加任何类型的锁,直至T释放A上的锁, 保证了其他事务在T释放A上的锁之前不能再读取和 修改A。
读锁(共享锁,即S锁):若事务T对数据对象A加
上S锁,则事务T可以读A,但不能修改A,其他事务
BEGIN
END ELSE
PRINT '帐 户 不 存 在 !'
IF(SELE CT [M ONEY ] FRO M BAN K WHE RE UI D='A ')>10 00 BEGI N
END ELSE
PRINT 'A帐 户 余 额 不 足! '
UPDATE BANK SET [MONE Y]=[M ONEY] -1000 WHER E UID ='A' SELECT * FRO M BA NK IF EXIS TS(SE LECT * FR OM BA NK WH ERE U ID=' B')

《数据库系统概念》内容

《数据库系统概念》内容

《数据库系统概念》内容标题:深入理解《数据库系统概念》《数据库系统概念》是一本全面且深入阐述数据库系统理论与实践的权威著作。

以下我们将逐步解析其核心内容,以帮助读者更深入地理解和掌握数据库系统的本质和应用。

一、数据库系统的基本概念数据库系统是用于存储、管理和检索数据的软件系统。

它主要包括数据库、数据库管理系统(DBMS)、数据库用户和应用程序四部分。

数据库是数据的集合,按照一定的数据模型组织和存储;DBMS是管理数据库的软件,负责数据的定义、操作、保护和恢复等;数据库用户包括终端用户和应用程序员,通过DBMS访问和处理数据;应用程序则是用户与数据库交互的工具。

二、数据模型数据模型是数据库系统的核心概念,它是对现实世界的一种抽象和简化,用于描述数据的结构、操作和约束。

常见的数据模型有层次模型、网状模型、关系模型、对象模型和面向对象模型等。

关系模型是目前最常用的数据模型,它将数据表示为二维表格形式,通过SQL语言进行操作。

关系模型包括关系数据结构、关系操作和关系完整性约束三个部分。

三、数据库设计数据库设计是数据库系统开发的关键阶段,主要包括需求分析、概念设计、逻辑设计和物理设计四个步骤。

需求分析是理解用户需求,明确数据范围和处理要求的过程。

概念设计是将需求转化为独立于具体DBMS的概念模型,通常使用实体-联系模型(E-R模型)进行描述。

逻辑设计是将概念模型转化为特定DBMS支持的关系模型,确定表结构和关系。

物理设计是考虑硬件、软件和数据存储等因素,优化数据库的物理结构,提高数据访问效率。

四、数据库管理系统数据库管理系统是数据库系统的核心组件,它提供数据定义、数据操作、数据控制和数据服务等功能。

数据定义功能包括定义数据的结构、类型、约束和权限等。

数据操作功能包括查询、插入、删除和更新数据等。

数据控制功能包括事务管理、并发控制、恢复管理和安全性管理等。

数据服务功能包括备份和恢复、性能优化、数据字典和用户接口等。

数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章

数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章

C H A P T E R8Relational Database DesignExercises8.1Suppose that we decompose the schema R=(A,B,C,D,E)into(A,B,C)(A,D,E).Show that this decomposition is a lossless-join decomposition if thefollowing set F of functional dependencies holds:A→BCCD→EB→DE→AAnswer:A decomposition{R1,R2}is a lossless-join decomposition ifR1∩R2→R1or R1∩R2→R2.Let R1=(A,B,C),R2=(A,D,E),and R1∩R2= A.Since A is a candidate key(see PracticeExercise8.6),Therefore R1∩R2→R1.8.2List all functional dependencies satis?ed by the relation of Figure8.17.Answer:The nontrivial functional dependencies are:A→B andC→B,and a dependency they logically imply:AC→ B.There are19trivial functional dependencies of the form?→?,where???.Cdoes not functionally determine A because the?rst and third tuples havethe same C but different A values.The same tuples also show B does notfunctionally determine A.Likewise,A does not functionally determineC because the?rst two tuples have the same A value and different Cvalues.The same tuples also show B does not functionally determine C.8.3Explain how functional dependencies can be used to indicate the fol-lowing:910Chapter8Relational Database DesignA one-to-one relationship set exists between entity sets student andinstructor.A many-to-one relationship set exists between entity sets studentand instructor.Answer:Let Pk(r)denote the primary key attribute of relation r.The functional dependencies Pk(student)→Pk(instructor)andPk(instructor)→Pk(student)indicate a one-to-one relationshipbecause any two tuples with the same value for student must havethe same value for instructor,and any two tuples agreeing oninstructor must have the same value for student.The functional dependency Pk(student)→Pk(instructor)indicates amany-to-one relationship since any student value which is repeatedwill have the same instructor value,but many student values mayhave the same instructor value.8.4Use Armstrong’sa xioms to prove the soundness of the union rule.(Hint:Use the augmentation rule to show that,if?→?,then?→??.Apply theaugmentation rule again,using?→?,and then apply the transitivityrule.)Answer:To prove that:if?→?and?→?then?→??Following the hint,we derive:→?given→??augmentation rule→??union of identical sets→?given→??augmentation rule→??transitivity rule and set union commutativity8.5Use Armstrong’sa xioms to prove the soundness of the pseudotransitiv-ity rule.a xioms of the Pseudotransitivity Rule:Answer:Proof using Armstrong’sif?→?and??→?,then??→?.→?given→??augmentation rule and set union commutativity ?→?given→?transitivity rule8.6Compute the closure of the following set F of functional dependenciesfor relation schema R=(A,B,C,D,E).Exercises11A→BCCD→EB→DE→AList the candidate keys for R.Answer:Note:It is not reasonable to expect students to enumerate all of F+.Some shorthand representation of the result should be acceptable as long as the nontrivial members of F+are found.Starting with A→BC,we can conclude:A→B and A→ C.Since A→B and B→D,A→D(decomposition,transitive) Since A→C D and C D→E,A→E(union,decom-position,transi-tive)Since A→A,we have(re?exive)A→ABC DE from the above steps(union)Since E→A,E→ABC DE(transitive)Since C D→E,C D→ABC DE(transitive)Since B→D and BC→C D,BC→ABC DE (augmentative, transitive)Also,C→C,D→D,B D→D,etc.Therefore,any functional dependency with A,E,BC,or C D on the left hand side of the arrow is in F+,no matter which other attributes appear in the FD.Allow*to represent any set of attributes in R,then F+isB D→B,B D→D,C→C,D→D,B D→B D,B→D,B→B,B→B D,and all FDs of the form A?→?,BC?→?,C D?→?,E?→?where?is any subset of{A,B,C,D,E}.Thecandidate keys are A,BC,C D,and E.8.7Using the functional dependencies of Practice Exercise8.6,compute thecanonicalcover F c.Answer:The given set of FDs F is:-A→BCCD→EB→DE→AThe left side of each FD in F is unique.Also none of the attributes in the left side or right side of any of the FDs is extraneous.Therefore the canonical cover F c is equal to F.12Chapter8Relational Database Design8.8Consider the algorithm in Figure8.18to compute?+.Show that thisalgorithm is more ef?cient than the one presented in Figure8.8(Sec-tion8.4.2)and that it computes?+correctly.Answer:The algorithm is correct because:If A is added to result then there is a proof that?→ A.To see this,observe that?→?trivially so?is correctly part of result.IfA∈?is added to result there must be some FD?→?such thatA∈?and?is already a subset of result.(Otherwise f dcountwould be nonzero and the if condition would be false.)A full proofcan be given by induction on the depth of recursion for an executionof addin,but such a proof can be expected only from students witha good mathematical background.If A∈?+,then A is eventually added to result.We prove this byinduction on the length of the proof of?→A using Armstrong’saxioms.First observe that if procedure addin is called with someargument?,all the attributes in?will be added to result.Also if aparticular FD’sfdcount becomes0,all the attributes in its tail willde?nitely be added to result.The base case of the proof,A∈??A∈?+,is obviously true because the?rst call to addinhas the argument?.The inductive hypotheses is that if?→A canbe proved in n steps or less then A∈result.If there is a proof inn+1steps that?→A,then the last step was an application ofeither re?exivity,augmentation or transitivity on a fact?→?proved in n or fewer steps.If re?exivity or augmentation was usedin the(n+1)st step,A must have been in result by the end of the n thstep itself.Otherwise,by the inductive hypothesis??result.Therefore the dependency used in proving?→?,A∈?willhave f dcount set to0by the end of the n th step.Hence A will beadded to result.To see that this algorithm is more ef?cient than the one presented inthe chapter note that we scan each FD once in the main program.Theresulting array appears has size proportional to the size of the givenFDs.The recursive calls to addin result in processing linear in the sizeof appears.Hence the algorithm has time complexity which is linear inthe size of the given FDs.On the other hand,the algorithm given in thetext has quadratic time complexity,as it may perform the loop as manytimes as the number of FDs,in each loop scanning all of them once.8.9Given the database schema R(a,b,c),and a relation r on the schema R,write an SQL query to test whether the functional dependency b→cholds on relation r.Also write an SQL assertion that enforces the func-tional dependency.Assume that no null values are present.(Althoughpart of the SQL standard,such assertions are not supported by anydatabase implementation currently.)Answer:Exercises13a.The query is given below.Its result is non-empty if and only ifb→c does not hold on r.select bfrom rgroup by bhaving count(distinct c)>1b.create assertion b to c check(not exists(select bfrom rgroup by bhaving count(distinct c)>1))8.10Our discussion of lossless-join decomposition implicitly assumed thatattributes on the left-hand side of a functional dependency cannot take on null values.What could go wrong on decomposition,if this property is violated?Answer:The natural join operator is de?ned in terms of the cartesian product and the selection operator.The selection operator,gives unknown for any query on a null value.Thus,the natural join excludes all tuples with null values on the common attributes from the?nal result.Thus, the decomposition would be lossy(in a manner different from the usual case of lossy decomposition),if null values occur in the left-hand side of the functional dependency used to decompose the relation.(Null values in attributes that occur only in the right-hand side of the functionaldependency do not cause any problems.)8.11In the BCNF decomposition algorithm,suppose you use a functional de-pendency?→?to decompose a relation schema r(?,?,?)into r1(?,?) and r2(?,?).a.What primary and foreign-key constraint do you expect to holdon the decomposed relations?b.Give an example of an inconsistency that can arise due to anerroneous update,if the foreign-key constraint were not enforcedon the decomposed relations above.c.When a relation is decomposed into3NF using the algorithm inSection8.5.2,what primary and foreign key dependencies wouldyou expect will hold on the decomposed schema?14Chapter8Relational Database DesignAnswer:a.?should be a primary key for r1,and?should be the foreign keyfrom r2,referencing r1.b.If the foreign key constraint is not enforced,then a deletion of atuple from r1would not have a corresponding deletion from thereferencing tuples in r2.Instead of deleting a tuple from r,thiswould amount to simply setting the value of?to null in sometuples.c.For every schema r i(??)added to the schema because of a rule→?,?should be made the primary key.Also,a candidate key?for the original relation is located in some newly created relationr k,and is a primary key for that relation.Foreign key constraints are created as follows:for each relationr i created above,if the primary key attributes of r i also occur inany other relation r j,then a foreign key constraint is created fromthose attributes in r j,referencing(the primary key of)r i.8.12Let R1,R2,...,R n be a decomposition of schema U.Let u(U)be a rela-(u).Show thattion,and let r i=RIu?r11r21···1r nAnswer:Consider some tuple t in u.(u)implies that t[R i]∈r i,1≤i≤n.Thus,Note that r i=Rit[R1]1t[R2]1...1t[R n]∈r11r21...1r nBy the de?nition of natural join,t[R1]1t[R2]1...1t[R n]=(??(t[R1]×t[R2]×...×t[R n])) where the condition?is satis?ed if values of attributes with the samename in a tuple are equal and where?=U.The cartesian productof single tuples generates one tuple.The selection process is satis?edbecause all attributes with the same name must have the same valuesince they are projections from the same tuple.Finally,the projectionclause removes duplicate attribute names.By the de?nition of decomposition,U=R1∪R2∪...∪R n,which meansthat all attributes of t are in t[R1]1t[R2]1...1t[R n].That is,t is equalto the result of this join.Since t is any arbitrary tuple in u,u?r11r21...1r n8.13Show that the decomposition in Practice Exercise8.1is not a dependency-preserving decomposition.Answer:The dependency B→D is not preserved.F1,the restrictionof F to(A,B,C)is A→ABC,A→AB,A→AC,A→BC,Exercises15 A→B,A→C,A→A,B→B,C→C,AB→AC,AB→ABC,AB→BC,AB→AB,AB→A,AB→B,AB→C,AC(same as AB),BC(same as AB),ABC(same as AB).F2,the restriction of F to (C,D,E)is A→ADE,A→AD,A→AE,A→DE,A→A, A→D,A→E,D→D,E(same as A),AD,AE,DE,ADE(same as A).(F1∪F2)+is easily seen not to contain B→D since the only FD in F1∪F2with B as the left side is B→B,a trivial FD.We shall see in Practice Exercise8.15that B→D is indeed in F+.Thus B→D is not preserved.Note that C D→ABC DE is also not preserved.A simpler argument is as follows:F1contains no dependencies with D on the right side of the arrow.F2contains no dependencies withB on the left side of the arrow.Therefore for B→D to be preserved there mustbe an FD B→?in F+1and?→D in F+2(so B→D would followby transitivity).Since the intersection of the two schemes is A,?= A.Observe that B→A is not in F+1since B+=B D.8.14Show that it is possible to ensure that a dependency-preserving decom-position into3NF is a lossless-join decomposition by guaranteeing that at least one schema contains a candidate key for the schema being decom-posed.(Hint:Show that the join of all the projections onto the schemas of the decomposition cannot have more tuples than the original relation.)Answer:Let F be a set of functional dependencies that hold on a schema R.Let?={R1,R2,...,R n}be a dependency-preserving3NF decompo-sition of R.Let X be a candidate key for R.Consider a legal instance r of R.Let j=X(r)1R1(r)1R2(r) (1)R n(r).We want to prove that r=j.We claim that if t1and t2are two tuples in j such that t1[X]=t2[X],then t1=t2.To prove this claim,we use the following inductive argument–Let F′=F1∪F2∪...∪F n,where each F i is the restriction of F to the schema R i in?.Consider the use of the algorithm given in Figure8.8to compute the closure of X under F′.We use induction on the number of times that the f or loop in this algorithm is executed.Basis:In the?rst step of the algorithm,result is assigned to X,and hence given that t1[X]=t2[X],we know that t1[result]=t2[result] is true.Induction Step:Let t1[result]=t2[result]be true at the end of thek th execution of the f or loop.Suppose the functional dependency considered in the k+1thexecution of the f or loop is?→?,and that??result.??result implies that t1[?]=t2[?]is true.The facts that?→?holds forsome attribute set R i in?,and that t1[R i]and t2[R i]are in R i(r)imply that t1[?]=t2[?]is also true.Since?is now added to result by the algorithm,we know that t1[result]=t2[result]is true at the end of the k+1th execution of the f or loop.16Chapter8Relational Database DesignSince?is dependency-preserving and X is a key for R,all attributes in Rare in result when the algorithm terminates.Thus,t1[R]=t2[R]is true,that is,t1=t2–as claimed earlier.Our claim implies that the size of X(j)is equal to the size of j.Notealso that X(j)=X(r)=r(since X is a key for R).Thus we haveproved that the size of j equals that of ing the result of PracticeExercise8.12,we know that r?j.Hence we conclude that r=j.Note that since X is trivially in3NF,?∪{X}is a dependency-preservinglossless-join decomposition into3NF.8.15Give an example of a relation schema R′and set F′of functional depen-dencies such that there are at least three distinct lossless-join decompo-sitions of R′into BCNF.Answer:Given the relation R′=(A,B,C,D)the set of functionaldependencies F′=A→B,C→D,B→C allows three distinctBCNF decompositions.R1={(A,B),(C,D),(B,C)}is in BCNF as isR2={(A,B),(C,D),(A,C)}R2={(A,B),(C,D),(A,C)}R3={(B,C),(A,D),(A,B)}8.16Let a prime attribute be one that appears in at least one candidate key.Let?and?be sets of attributes such that?→?holds,but?→?does not hold.Let A be an attribute that is not in?,is not in?,and forwhich?→A holds.We say that A is transitively dependent on?.Wecan restate our de?nition of3NF as follows:A relation schema R is in3NF with respect to a set F of functional dependencies if there are nononprime attributes A in R for which A is transitively dependent on akey for R.Show that this new de?nition is equivalent to the original one.Answer:Suppose R is in3NF according to the textbook de?nition.Weshow that it is in3NF according to the de?nition in the exercise.Let A bea nonprime attribute in R that is transitively dependent on a key?forR.Then there exists??R such that?→A,?→?,A∈?,A∈,and?→?does not hold.But then?→A violates the textbookde?nition of3NF sinceA∈?implies?→A is nontrivialSince?→?does not hold,?is not a superkeyA is not any candidate key,since A is nonprimeExercises17Now we show that if R is in3NF according to the exercise de?nition,it is in3NF according to the textbook de?nition.Suppose R is not in3NF according the the textbook de?nition.Then there is an FD?→?that fails all three conditions.Thus?→?is nontrivial.?is not a superkey for R.Some A in?-?is not in any candidate key.This implies that A is nonprime and?→ A.Let?be a candidate key for R.Then?→?,?→?does not hold(since?is not a superkey), A∈?,and A∈?(since A is nonprime).Thus A is transitivelydependent on?,violating the exercise de?nition.8.17A functional dependency?→?is called a partial dependency if thereis a proper subset?of?such that?→?.We say that?is partially dependent on?.A relation schema R is in second normal form(2NF)if each attribute A in R meets one of the following criteria:It appears in a candidate key.It is not partially dependent on a candidate key.Show that every3NF schema is in2NF.(Hint:Show that every partial dependency is a transitive dependency.)Answer:Referring to the de?nitions in Practice Exercise8.16,a relation schema R is said to be in3NF if there is no non-prime attribute A in R for which A is transitively dependent on a key for R.We can also rewrite the de?nition of2NF given here as:“Arelation schema R is in2NF if no non-prime attribute A is partiallydependent on any candidate key for R.”To prove that every3NF schema is in2NF,it suf?ces to show that if a non-prime attribute A is partially dependent on a candidate key?,thenA is also transitively dependent on the key?.Let A be a non-prime attribute in R.Let?be a candidate key for R.Suppose A is partially dependent on?.From the de?nition of a partial dependency,we know that for someproper subset?of?,?→ A.Since???,?→?.Also,?→?does not hold,since?is acandidate key.Finally,since A is non-prime,it cannot be in either?or?.Thus we conclude that?→A is a transitive dependency.Hence we have proved that every3NF schema is also in2NF.8.18Give an example of a relation schema R and a set of dependencies suchthat R is in BCNF but is not in4NF.18Chapter8Relational Database DesignAnswer:R(A,B,C)A→→BExercises19result:=?;/*fdcount is an array whose ith element contains the number of attributes on the left side of the ith FD that arenot yet known to be in?+*/for i:=1to|F|dobeginlet?→?denote the ith FD;fdcount[i]:=|?|;end/*appears is an array with one entry for each attribute.The entry for attribute A is a list of integers.Each integeri on the list indicates that A appears on the left sideof the i th FD*/for each attribute A dobeginappears[A]:=NI L;for i:=1to|F|dobeginlet?→?denote the ith FD;if A∈?then add i to appears[A];endendaddin(?);return(result);procedure addin(?);for each attribute A in?dobeginif A∈result thenbeginresult:=result∪{A};for each element i of appears[A]dobeginfdcount[i]:=fdcount[i]-1;if fdcount[i]:=0thenbeginlet?→?denote the ith FD;addin(?);endendendendFigure8.18.An algorithm to compute?+.。

数据库系统概念(英文精编版.第六版)

数据库系统概念(英文精编版.第六版)

Attributes
Attribute Domain

The set of allowed values for each attribute is called the domain of the attribute
The special value null is a member of every domain
Instructor_schema = (ID, name, dept_name, salary)
r(R) is a relation on the relation schema R
We use lowercase names for relations.
Example: instructor (Instructor _schema)
2.5 Relational Query Languages
2.6 Relational Operations
Chapter 2: Relational Model
教学目的:

熟悉关系数据模型
教学重点:

简单属性、多值属性、复合属性
关系、关系模式、码等概念 关系模式图 关系代数的操作
?简单属性多值属性复合属性?关系关系模式码等概念?关系模式图?关系代数的操作?教学难点
Chapter 2: Relational Model
2.1 Structure of Relational Databases 2.2 Database Schema 2.3 Keys 2.4 Schema Diagrams
referenced relation
Exercise: 找出左图里面
存在的其他外码、参照关 系和被参照关系

数据库系统概论参考文献

数据库系统概论参考文献

数据库系统概论参考文献数据库系统概论是计算机科学与技术、软件工程等专业的重要课程之一,涉及数据库的基本概念、数据模型、数据管理和数据库设计等内容。

以下是一些与数据库系统概论相关的参考文献:1. 《数据库系统概论》(第五版)-王珊、萨师煊这本书是国内数据库系统概论领域的经典教材,它全面介绍了数据库的基本概念、数据模型、数据管理和数据库设计等内容。

书中包含了许多实例和案例,使读者更容易理解和掌握数据库的相关知识。

此外,该书还包括了大量的习题,帮助读者加深对所学知识的理解。

2. 《数据库系统概念》(第六版)- Abraham Silberschatz、Henry F. Korth、S. Sudarshan该书是数据库领域的另一本经典教材,被广泛应用于全球许多高校的数据库课程中。

它详细介绍了数据库系统的概念、架构、设计和实现等内容,并以实例和案例加深理解。

此外,该书还涉及了一些新的研究方向,如并行数据库、分布式数据库和数据仓库等。

3. 《数据库系统导论》(第三版)- Hector Garcia-Molina、Jeffrey D. Ullman、Jennifer Widom这本书是数据库领域的一本经典导论教材,介绍了数据库系统的基本概念和原理,包括数据库设计、关系数据模型、查询语言和数据库管理等内容。

书中的许多例子和习题可以帮助读者更好地理解和掌握数据库系统的知识。

4. 《数据库系统概论与SQL语言》(第二版)-朱晓华、杨东波该书是国内的一本数据库系统概论教材,内容涵盖了数据库的基本概念、数据模型和查询语言等。

与其他教材不同的是,该书特别侧重于SQL语言的学习和应用。

它详细介绍了SQL的基本语法、查询和更新操作、事务管理和安全性等方面。

5. 《数据库系统概论》(第四版)-李东风这本书是以先进的数据库技术为基础,详细介绍了数据库系统的设计和实现等内容。

它包含了关系数据库模型、数据库设计方法和数据库管理技术等方面,结合实际案例和实验,让读者能够更好地理解和应用数据库系统的知识。

数据库系统概论第六版课后答案

数据库系统概论第六版课后答案

数据库系统概论第六版课后答案第1章数据库系统概述一、填空题1. 在关系数据库中,一个元组对应表中。

解: 一个记录 (一行)2. 常用的数据模型有:、、和面向对象模型。

解: 关系模型,层次模型,网状模型3. 用二维表来表示实体及实体之间联系的数据模型是。

解: 关系模型4. 关系模型数据库中最常用的三种关系运算是、、。

解: 选择运算,投影运算,连接运算5. 在数据库系统中,数据的最小访问单位是。

解: 字段(数据项)6. 对表进行水平方向的分割用的运算是。

解: 选择运算7. 数据结构、和称为数据模型的三要素。

解: 数据操作,数据约束条件8. 关系的完整性约束条件包括完整性、完整性和完整性三种。

解: 用户定义,实体,参照二、单项选择题1. 对数据库进行规划、设计、协调、维护和管理的人员,通常被称为(D )。

A. 工程师B. 用户C. 程序员D. 数据库管理员2. 下面关于数据(Data)、数据库(DB)、数据库管理系统(DBMS)与数据库系统(DBS)之间关系的描述正确的是( B )。

A. DB包含DBMS和DBSB. DBMS包含DB和DBSC. DBS包含DB和DBMSD. 以上都不对3. 数据库系统的特点包括( D )。

A. 实现数据共享,减少数据冗余B. 具有较高的数据独立性、具有统一的数据控制功能C. 采用特定的数据模型D. 以上特点都包括4. 下列各项中,对数据库特征的描述不准确的是( D )。

A. 数据具有独立性B. 数据结构化C. 数据集中控制D. 没有冗余5. 在数据的组织模型中,用树形结构来表示实体之间联系的模型称为 ( D )。

A. 关系模型B. 层次模型C. 网状模型D. 数据模型6. 在数据库中,数据模型描述的是 ( C ) 的集合。

A. 文件B. 数据C. 记录D. 记录及其联系7. 在关系数据库中,关系就是一个由行和列构成的二维表,其中行对应( B )。

A. 属性B. 记录C. 关系D. 主键8. 关系数据库管理系统所管理的关系是( C )。

数据库系统概念6版引言讲义.

数据库系统概念6版引言讲义.
实体集由关系(表)表示, 实体之间的联系也通过关系表示。
例:实体学生、课程及之间的联系的表示
学生=(学号,姓名,性别,年龄,系别) 课程=(课程号,课程名,学分) 选课=(学号,课程号,成绩) 例:求选修了且仅选修数据库和数据结构的学生姓名 38

(2)找出周四5、6节能容纳150以上、具有投 影仪和空调且使用状态正常的空教室,给出教
室号、管理员姓名、管理员电话
31
数据模型
三、逻辑数据模型 1.层次模型 实体用结点表示,实体之间的联系用树表示。
系号 系名 地址
教研室号 教研室名
学号
姓名
年级
职工号
姓名
职称 32
数据模型
D02 计算机 R1101
25
数据库系统的基本概念
6.应用系统(database application)
软件界面,应用程序。
7.管理信息系统(Management Information
Systems 简称MIS)
办公系统、决策系统、生产系统和信息系 统面向数量的执行系统、面向价值的核算系 统、报告监控系统,分析信息系统、规划决 策系统。

7
1978-2008,不断增加的课程
1978:离散数学、计算机原理、编译原理、 数据库原理、操作系统原理、数据结构、程序 设计(Fortran),四年20小时上机 1988:…,局域网,多媒体技术,Pascal, 200小时上机 1998:…,…,软件工程,因特网,Web技 术,Java,500小时上机 2008:…,…,…,嵌入式系统,动漫软件, 信息安全,1000小时

现在常见的计算机专业的课程设置,一方面用了不少学时 在与这些无关的内容上,另一方面也欠缺不少必要的知识 17

ch1 数据库系统概念(第6版)第一章介绍

ch1 数据库系统概念(第6版)第一章介绍
数据库系统
上海交通大学计算机系 张忠能
zhang-zn@
1
数据库系统
教材:
Abraham Silberschatz 等著,杨冬青等译《数据库系统概念》,机械工业出版 社 (VER 5.0以上 不是本科版) Hector Garcia-Molina Jeffrey D.Ullman Jennifer Widom著 《数据库系统全书》 ,机械工业出版社,北京,2003 王珊、陈红 编著 《数据库系统原理教程》,清华大学出版社,北京,1998
关系模型 实体-联系数据模型(主要用于数据库设计) 面向对象的数据模型(面向对象和对象关系) 半结构化数据模型(XML) 其他旧式模型
网络模型 层次模型
关系模型
关系模型(第2章) 范例:用关系模型表示的表格数据


关系数据库示例
数据操纵语言(DML)
用于访问和操纵由适当的数据模式组织起 来的数据
数据库设计?
这种设计有问题么?
设计方法
规范化理论(第8章)
形式化哪些设计是不好的,并且对他们进行测 试
实体联系模型(第7章)
将企业模型化为实体和联系的集合
实体:在企业当中可区别于其他对象的“事情”或 者“物体”
用一系列属性来描述
联系:几个实体之间的关联
通过实体-联系图解法来表示
实体-联系模型
应用程序通常通过以下途径之一来访问数据库
数据库设计
设计一般结构的数据库的过程: 逻辑设计 - 取决于数据库模式。数据库设 计需要找到关系模式的一个“良好”集合 。
商业决策 - 数据库中应该记录什么属性? 计算机科学决策 - 应该采用何种关系模式?在 多种关系模式中如何分配属性?

数据库系统概念(英文精编版.第六版)

数据库系统概念(英文精编版.第六版)
2015年第1学期 数据库系统
公共360云盘 /

Id: scau_db_2015
password: scau_db_2015
边山老师联系方式

bianshan@ 数学与信息学院611
平时成绩占总评成绩的50%

考勤 作业和测验成绩 实验成绩
Object-based data models Semistructured data model (XML)
Other older models:
Network
model model
Hierarchical
Exercises
A data model consists of A. schema C. set of constraints
Computer users use this level.
Examples of Logical Level Data
Examples of View Level Data
A view that shows the instructor names of the Computer Science department

Security problems
Hard
to provide user access to some, but not all, data
Database systems offer solutions to all the above problems
Exercises
The various copies of the same data may no longer agree. This
Exercises

数据库系统原理课后习题参考答案

数据库系统原理课后习题参考答案

~第一章数据库系统概述选择题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.请简述关系规范化过程。

答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。

一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。

(完整版)数据库系统基础教程第八章答案

(完整版)数据库系统基础教程第八章答案

Section 1Exercise 8.1.1a)CREATE VIEW RichExec ASSELECT * FROM MovieExec WHERE netWorth >= 10000000;b)CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#;c)CREATE VIEW ExecutiveStar (name, address, gender, birthdate, cert#, netWorth) AS SELECT , star.address, star.gender, star.birthdate, exec.cert#, WorthFROM MovieStar star, MovieExec exec WHERE = ANDstar.address = exec.address;Exercise 8.1.2a)SELECT name from ExecutiveStar WHERE gender = ‘f’;b)SELECT from RichExec, StudioPres where = ; c)SELECT from ExecutiveStar, StudioPresWHERE Worth >= 50000000 ANDStudioPres.cert# = RichExec.cert#;Section 2Exercise 8.2.1The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio);Exercise 8.2.2a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInsertINSTEAD OF INSERT ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWINSERT INTO Movies(title, year, length, studioName, genre)VALUES(NewRow.title, NewRow.year, NewYear.length, ‘Disney’, ‘comedy’);c)CREATE TRIGGER DisneyComedyUpdateINSTEAD OF UPDATE ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE Movies SET length NewRow.lengthWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = ‘Disney’ AND genre = ‘comedy’;Exercise 8.2.3a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VALUES(NewRow.maker, NewRow.model, ‘pc’))(INSERT INTO PC VALUES(NewRow.model, NewRow.speed, NewRow.ram, NewRow.hd, NewRow.price));c)CREATE TRIGGER NewPCUpdateINSTEAD OF UPDATE ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE PC SET price = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPCDeleteINSTEAD OF DELETE ON NeePCREFERENCING OLD ROW AS OldRowFOR EACH ROW(DELETE FROM Product WHERE model = OldRow.model)(DELETE FROM PC where model = OldRow.model);Section 3Exercise 8.3.1a)CREATE INDEX NameIndex on Studio(name);b)CREATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies(genre, length);Section 4Exercise 8.4.1Action No Index Star Index Movie Index Both Indexes Q110041004Q210010044I2446 Average 2 + 98p1 + 98p2 4 + 96 p2 4 + 96 p1 6 – 2 p1 – 2 p2 Exercise 8.4.2Q1 = SELECT * FROM Ships WHERE name = n;Q2 = SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexes Actions None Name Class Launched Name &ClassName &LaunchedClass &LaunchedThreeIndexesQ1502505022502 Q21121212 2 Q35050502650262626 I24446668Average 2 +48p1 -p2 +48p34 +46 p3- 2 p1- 3 p24 +46p1 -2p2 +46p34 + 46p1- 3p2 +22p36 - 4p1- 4p2 +44p36 - 4p1 -5p2 + 20p36 - 44p1 -4p2 + 20p38 - 6p1 -6p2 + 18p3The best choice of indexes (name and launched) has an average cost of 6 - 4p1 - 5p2 + 20p3 per operation.Section 5Exercise 8.5.1Updates to movies that involves title or yearUPDATE MovieProd SET title = ‘newTitle’ where title=’oldTitle’ AND year = oldYear; UPDATE MovieProd SET year = newYear where title=’oldYitle’ AND year = oldYear; Update to MovieExec involving cert#DELETE FROM MovieProdWHERE (title, year) IN (SELECT title, yearFROM Movies, MovieExecWHERE cert# = oldCert# AND cert# = producerC#);INSERT INTO MovieProdSELECT title, year, nameFROM Movies, MovieExecWHERE cert# = newCert# AND cert# = producerC#;Exercise 8.5.2Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view.Insertions into Product with type equal to ‘pc’:INSERT INTO NewPCSELECT maker, model, speed, ram, hd, price FROM Product, PC WHEREProduct.model = newModel and Product.model = PC.model;Insertions into PC:INSERT INTO NewPCSELECT maker, ‘newModel’, ‘newSpeed’, ‘newRam’, ‘newHd’, ‘newPrice’FROM Product WHERE model = ‘newModel’;Deletions from Product with type equal to ‘pc’:DELETE FROM NewPC WHERE maker = ‘deletedMaker’ ANDmodel=’deletedModel’;Deletions from PC:DELETE FROM NewPC WHERE model = ‘deletedModel’;Updates to PC:Update NewPC SET speed=PC.speed, ram=PC.ram, hd=PC.hd, price=PC.price FROM PC where model=pc.model;Update to the attribute ‘model’ needs to be treated as a delete and an insert. Updates to Product:Any changes to a Product tuple whose type is ‘pc’ need to be treated as a delete or an insert, or both.Exercise 8.5.3Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from class, updates to a Class’ displacement. Deletions from Ship:UPDATE ShipStats SETdisplacement=((displacement * count) –(SELECT displacementFROM ClasssesWHERE class = ‘DeletedShipClass’)) / (count – 1),count = count – 1WHEREcountry = (SELECT country FROM Classes WHERE class=’DeletedShipClass’); Insertions into Ship:Update ShipStat SETdisplacement=((displacement*count) +(SELECT displacement FROM ClassesWHERE class=’InsertedShipClass’)) / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=’InsertedShipClass); Deletes from Classes:NumRowsDeleted = SELECT count(*) FROM ships WHERE class = ‘DeletedClass’; UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement *NumRowsDeleted)) / (count – NumRowsDeleted),count = count – NumRowsDeletedWHERE country = ‘DeletedClassCountry’;Update to a Class’ displacement:N = SELECT count(*) FROM Ships where class = ‘UpdatedClass’;UPDATE ShipsStat SETdisplacement = ((displacement * count) + ((oldDisplacement – newDisplacement) * N))/countWHEREcountry = ‘UpdatedClassCountry’;Exercise 8.5.4Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producerSELECT starNameFROM StarsIn, Movies, MovieExecWHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = ‘Max Bialystock’;Movies produced by a certain producerSELECT title, yearFROM Movies, MovieExecWhere producerC# = cert# AND name = ‘George Lucas’;Names of producers that a certain star has worked withSELECT nameFROM Movies, MovieExec, StarsInWhere producerC#=cert# AND title=movieTitle AND year=movieYear AND starName=’Carrie Fisher’;The number of movies produced by given producerSELECT count(*)FROM Movies, MovieExecWHERE producerC#=cert# AND name = ‘George Lucas‘;Names of producers who also starred in their own moviesSELECT nameFROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND = starName;The number of stars that have starred in movies produced by a certain producer SELECT count(DISTINCT starName)FROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND name ‘George Lucas’;The number of movies produced by each producerSELECT name, count(*)FROM Movies, MovieExecWHERE producerC#=cert# GROUP BY name。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

8.5.1 BCNF分解

Database System Concepts - 5th Edition, July 28, 2005.
7.2
©Silberschatz, Korth and Sudarshan
Database System Concepts - 5th Edition, July 28, 2005.
/*删NF· 算法通过为正则覆盖中的每个依赖显式地构造一个模式确保依赖的保持。 该算法通过保证至少有一个模式包含被分解模式的候选码,确保该分解是一个 无损分解。
Database System Concepts - 5th Edition, July 28, 2005.
7.9
©Silberschatz, Korth and Sudarshan
8.6.3

4NF 分解算法
Database System Concepts - 5th Edition, July 28, 2005.
7.10
©Silberschatz, Korth and Sudarshan
第八章 关系数据库设计
8.5 分解算法4
8.6 使用多值依赖的分解
8.7 更多的范式
8.8 数据库设计过程 8.9 时态数据建模
Database System Concepts - 5th Edition, July 28, 2005.
7.1
©Silberschatz, Korth and Sudarshan
7.3
©Silberschatz, Korth and Sudarshan
Database System Concepts - 5th Edition, July 28, 2005.
7.4
©Silberschatz, Korth and Sudarshan
8.5.1.2 BCNF分解算法
result := {R }; done := false; 计算F +; while (not done) do if (result中存在模式Ri,不属于BCNF) then begin 令 为一个在Ri上成立的非平凡函数依赖,满足 Ri 不属于F +,并且 = ; result := (result – Ri ) (Ri – ) (, ); end else done := true;
这个算法产生的分解不仅是一个BCNF分解,而且是一 个无损分解。
Database System Concepts - 5th Edition, July 28, 2005.
7.5
©Silberschatz, Korth and Sudarshan
8.5.2 3NF 分解算法
令Fc为F的正则覆盖; i := 0; for each Fc中的函数依赖 i:=i+1; Ri:= ; if 模式RJ,j=1,2,3…,i都不包含R的候选码 then i:=i+1; Ri:=R的任意候选码; repeat /*(可选)移除冗余关系*/
7.7
©Silberschatz, Korth and Sudarshan
8.5.4 BCNF和3NF的比较
BCNF: 分解是无损的 保持依赖 不得不用控制表示数据项间的某些可能有意义的联系,并 且存在信息重复的问题 BCNF是在3NF基础上的改进式,BCNF比3NF更为严格。 3NF: 分解是无损的 可能无法保持依赖
Database System Concepts - 5th Edition, July 28, 2005.
7.8
©Silberschatz, Korth and Sudarshan
8.6 使用多值依赖的分解
Database System Concepts - 5th Edition, July 28, 2005.
if模式Rj包含于另一个模式Rk中
then Rj:=Ri; i:=i-1; Until 不再有可以删除的RJ return (R1, R2, ..., Ri)
Database System Concepts - 5th Edition, July 28, 2005. 7.6 ©Silberschatz, Korth and Sudarshan
相关文档
最新文档