The Relational Database Model
The Relational Database Model
Model
Relational Database
Designer focuses on logical representation
rather than physical
Use of table advantageous
Structural and data independence
Related records stored in independent tables
Logical simplicity
Allows for more effective design strategies
2
Entities and Attributes
Entity is a person, place, event, or thing about which data is
collected
Attributes are characteristics of the entity
Tables
Holds related entities or entity set
Also called relations
Comprised of rows and columns
3
• Two-dimensional structure with
rows and columns
• Rows (tuples) represent single
entity
• Columns represent attributes
• Row/column intersection
represents single value
• Tables must have an attribute to
uniquely identify each row
4
• Column values all have same data
format
• Each column has range of values
called attribute domain
• Order of the rows and columns is
immaterial to the DBMS
5
One or more attributes that
determine other attributes
Key attribute
Composite key
6
Figure 2.1 7
Figure 2.2 8
Superkey
Uniquely identifies each entity
Candidate key
Minimal superkey
Primary key
Candidate key to uniquely identify all other attributes in a given
row
Secondary key
Used only for data retrieval
Foreign key
Values must match primary key in another table
9
Entity integrity
Ensures all entities are unique
Each entity has unique key
Referential integrity
Foreign key must have null value or match
primary key values
Makes it impossible to delete row whose primary
key has mandatory matching foreign key values in
another table
10
Relational algebra determines
table manipulations
Key operators
SELECT
PROJECT
JOIN
Other operators
INTERSECT
UNION
DIFFERENCE
PRODUCT
DIVIDE
11
Combines all rows
Figure 2.5
12
Yields rows that appear in both tables
Figure 2.6
13
Yields rows not found in other tables
Figure 2.7
14
Yields all possible pairs from two tables
Figure 2.8
15
Yields a subset of rows based on specified criterion
16
Figure 2.9
Yields all values for selected attributes
Figure 2.10
17
Information from two or more tables is combined
Figure 2.11
18
Figure 2.14
Links tables by selecting rows with
common values in common attribute(s)
Three-stage process
Product creates one table
Select yields appropriate rows
Project yields single copy of each attribute
to eliminate duplicate columns
19
EquiJOIN
Links tables based on equality condition that compares specified
columns of tables
Does not eliminate duplicate columns
Join criteria must be explicitly defined
Theta JOIN
EquiJOIN that compares specified columns of each table using
operator other than equality one
Outer JOIN
Matched pairs are retained
Unmatched values in other tables left null
Right and left
20
Requires user of single-column table and two-column table
Figure 2.17
21
Data dictionary
Provides detailed account of all tables found within database
Metadata
Attribute names and characteristics
System catalog
Detailed data dictionary
System-created database
Stores database characteristics and contents
Tables can be queried just like any other tables
Automatically produces database documentation
22
Relationship classifications
1:1
1:M
M:N
E-R Model
ERD Maps E-R model
Chen
Crow’s Feet
23
• Rectangles represent entities
• Diamonds represent the relationship(s) between
the entities
• “1” side of relationship
– Number 1 in Chen Model
– Bar crossing line in Crow’s Feet Model
• “Many” relationships
– Letter “M” and “N” in Chen Model
– Three pronged “Crow’s foot” in Crow’s Feet Model
24
Figure 2.18 25
Figure 2.20 26
Figure 2.23
27
Figure 2.24
28
Figure 2.25
29
Figure 2.26
30
Figure 2.27
31
Figure 2.28
32
Foreign keys can reduce
redundancy
Some redundancy is desirable
Called controlled redundancy
Speed
Information requirements
33
Points to location
Makes retrieval of data faster
Figure 2.31
34