Sei sulla pagina 1di 11

The Relational Database Model

Supplement for non-ISM students


8/3/2010

By Tony WONG

A Logical View of Data


 Relational database model’s structural and
data independence enables us to view data
logically rather than physically.
 The logical view allows a simpler file
concept of data storage.
storage
 The use of logically
g y independent
p tables is
easier to understand.
 Logical
L i l simplicity
i li i yields
i ld simpler
i l andd more
effective database design methodologies.
A Logical View of Data
 Entities and Attributes
 An entity is a person, place, event, or thing for which we intend
to collect data.
 University -- Students,
St dents Fac
Faculty
lt Members
Members, Courses
Co rses
 Airlines -- Pilots, Aircraft, Routes, Suppliers

 Each entity has certain characteristics known as attributes.


 Student -- Student Number, Name, GPA, Date of Enrollment,
Data of Birth,
Birth Home Address,
Address Phone Number
Number, Major
 Aircraft -- Aircraft Number, Date of Last Maintenance, Total
Hours Flown, Hours Flown since Last Maintenance

A Logical View of Data

 Entities and Attributes


 A grouping of related entities becomes an entity set.
 The STUDENT entity set contains all student
entities.
 The FACULTY entity set contains all faculty
entities.
 The AIRCRAFT entity set contains all aircraft
entities.
A Logical View of Data
 Tables and Their Characteristics
 A table contains a group of related entities -- i.e. an
entity set.
set
 The terms entity set and table are often used
i t h
interchangeably.
bl
 A table is also called a relation.

Summary of the Characteristics of a Relational Table


A Listing of the STUDENT Table Attribute Values

Keys
 Primary
y Keyy contains attribute(s)
( ) that can
uniquely identify one row in a table.

 The primary key of one table appears again as the


link in another table is called foreign key
key.
 Controlled redundancy (shared common
attributes) makes the relational database work.
Figure 2.2 An Example of a Simple Relational Database

The Relational Schema for the CH2_SALE_CO Database


Relational Database Keys

Relational Database Operators


 Relational algebra
g defines the theoretical
way of manipulating table contents using the
eight
g relational functions: SELECT,,
PROJECT, JOIN, INTERSECT, UNION,
DIFFERENCE,, and PRODUCT.
Relational Database Operators
 UNION combines all rows from two tables. The
two tables must be union compatible.

Relational Database Operators


 INTERSECT p produces a listingg that contains onlyy
the rows that appear in both tables. The two tables
must be union compatible.
Relational Database Operators
 DIFFERENCE yields all rows in one table that are not
found in the other table; i.e., it subtracts one table from the
other. The tables must be union compatible.

Relational Database Operators


 PRODUCT p produces a list of all possible
p pairs
p of
rows from two tables.
Relational Database Operators
 SELECT yields values for all attributes found in a table. It
yields a horizontal subset of a table.
y

Relational Database Operators


 PROJECT produces a list of all values for selected
attributes. It yyields a vertical subset of a table.
Relational Database Operators
 JOIN allows us to combine information from two
or more tables. JOIN is the real power behind the
relational database,, allowingg the use of
independent tables linked by common attributes.

Relational Database Operators


 Natural JOIN links tables by selecting only the rows
with common values in their common attribute(s). It
is the result of a three-stage process:
A PRODUCT of the tables is created. (Figure
2.12)
A SELECT is performed on the output of the first
step to yield only the rows for which the common
attribute values match.
match (Figure 2.13)
2 13)
A PROJECT is performed to yield a single copy
of each attribute
attribute, thereby eliminating the
duplicate column. (Figure 2.14)
Natural Join, Step 1: PRODUCT

Figure 2.13 Natural Join, Step 2: SELECT

Figure 2.14 Natural Join, Step 3: PROJECT

Potrebbero piacerti anche