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

  • 格式:pdf
  • 大小:3.07 MB
  • 文档页数:38

下载文档原格式

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

2.2 Databases Schema
Relation Schema
R = (A1, A2, …, An ) is a relation schema
We use names beginning with an uppercase letter for relation schemas. Example:
2.4 Schema Diagrams
Schema Diagram
画图时要注意规范
Relation: appears as a box, with the relation name
Biblioteka Baidu
at the top in blue
Primary key attributes: are shown underlined Foreign key dependencies: appear as arrows from

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
Attribute values are (normally) required to be atomic(原子性); that
is, indivisible

multivalued attribute values are not atomic
E.g.
Supervisor John
……
Student Turner, Adams, Hayes
……
× √
Supervisor John
Student Turner
John
John
instructor (ID, name, dept_name, salary)
Relation Instance
What are the relation schemas of Fig. 2.5, Fig. 2.6 and Fig. 2.7, respectively?
2.3 Keys
Keys
requests information from the database.
Procedural vs.non-procedural, or declarative “Pure” languages:

Relational algebra


Tuple relational calculus
referenced relation
Exercise: 找出左图里面
存在的其他外码、参照关 系和被参照关系
Exercises
A foreign key can make reference to
A. an attribute that is a primary key of another table.
{student_id}
{course_id}
not a key
not a key
dept_name is a foreign
key from student, referencing department
student is called the
referencing relation
department is called the
Exercises

_________ is a minimal set of attributes for which it holds that: no two distinct tuples in the relation can have the same values for the attributes in this set. A. Candidate key C. Foreign key B. Superkey D. Primary key
关系代数的几种操作
2.1 Structure of Relational Databases
Example of a Relation
The instructor relation
attributes (or columns)
tuples (or rows)
Attributes
Attribute Domain
Definition: a relation r is a subset of D1 x D2 x … x Dn 设集合 Color = { 红,绿,黄 } 设集合 Fruit = { 苹果,香蕉,雪梨} 这两个集合的笛卡尔积 Color x Fruit 是这样的一个集合:

{(红,苹果)、(红,香蕉)、(红,雪梨)、
Relational Model

table, relation row, record, tuple column, attribute, field
为什么把“表”称为“关系”?
“关系”的数学定义
Definition: Cartesian-Product of Sets

D1 x D2 x … x Dn = { (a1, a2, …, an) | ai Di }
(绿,苹果)、(绿,香蕉)、(绿,雪梨)、 (黄,苹果)、(黄,香蕉)、(黄,雪梨)}
集合Color x Fruit的任意子集,叫做“关系”,例如:

R={(红,苹果)、 (绿,苹果)、(黄,香蕉)、(黄, 雪梨)}

R 是 Color x Fruit 的子集
Color
红 绿 黄 黄
Fruit

Exercises
record_id
1 2 3
…….
student_id
2010007 2010123 2010007
…….
course_id
CS-100 CS-100 CS-200
…….
What are the key types of the following attribute sets? {record_id, student_id, course_id} {record_id, student_id} {record_id, course_id} {student_id, course_id} {record_id} superkey superkey superkey superkey, candidate key superkey, candidate key
2.6 Relational Operations
Chapter 2: Relational Model
教学目的:

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

简单属性、多值属性、复合属性
关系、关系模式、码等概念 关系模式图 关系代数的操作
教学难点:

超码、候选码、主码、外码等概念
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)
……
Adams
Hayes
……

composite attribute values are not atomic
E.g.
Name John
……
Address Main street, Princeton
……
× √
Name
John
……
Street
……
City
……
Main street Princeton
Chapter 2: Relational Model
2.1 Structure of Relational Databases 2.2 Database Schema 2.3 Keys 2.4 Schema Diagrams
2.5 Relational Query Languages
the foreign key attributes of the referencing relation to the primary key of the reference relation.
2.24
2.5 Relational Query Languages
A query language is a language in which a user
A key is a set of one or more attributes that suffice to uniquely
distinguish each entity
Let K R, where R is a relation schema (set of attributes)

K is a superkey of R if values for K are sufficient to identify a unique tuple K is a candidate key if superkey K is minimal Primary Key is the candidate key chosen by the database designer. We should choose the attribute set whose value rarely change.
苹果 苹果 香蕉 雪梨 The Color_Fruit relation/table
2.10
Relation
Example: Suppose there exists three sets
dept_name = {Biology, History, Physics ……} building = {Watson, Taylor, Painter ……} budget = {10000, 20000, 30000……}
Relation and Table are equivalent
department = { (Biology, Watson, 90000),
(Finance, Painter, 120000), (History, Painter, 50000) }
Notice: Relations and Tables are Sets, Relations are Unordered, Order of tuples is irrelevant
Exercises
Which attribute is characterized in relational database
system?
A. Simple attribute C. Multi-valued attribute B. Composite attribute D. Derived attribute
Domain relational calculus
2.25
2.6 Relational Operations
2.26
2.6 Relational Operations Selection of tuples
B. an attribute that is a primary key of the same table. C. both A and B D. neither A nor B
A relation has only one _________
A. superkey
B. candidate key C. primary key
D. foreign key
A set of attributes that, taken collectively, allow us to identify
uniquely a tuple in the relation is called ______. A. super key B. primary key C. candidate key D. foreign key
The set department = { (Biology, Watson, 90000),
(Finance, Painter, 120000), (History, Painter, 50000) } is a relation over
dept_name x building x customer_budget