The Relational Database Model: Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel
The Relational Database Model: Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel
Chapter 2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 3
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 4
2
Table Characteristics
• 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
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 5
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 6
2
Keys
• One or more attributes that
determine other attributes
– Key attribute
– Composite key
• Full functional dependence
• Entity integrity
– Uniqueness
– No ‘null’ value in key
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 7
2
Example Tables
Figure 2.1
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 8
2
Figure 2.2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 9
2
Keys (con’t.)
• 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
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 10
2
Integrity Rules
• 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
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 11
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 12
2
Union
Combines all rows
Figure 2.5
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 13
2
Intersect
Yields rows that appear in both tables
Figure 2.6
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 14
2
Difference
Yields rows not found in other tables
Figure 2.7
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 15
2
Product
Yields all possible pairs from two tables
Figure 2.8
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 16
2
Select
Yields a subset of rows based on specified criterion
Figure 2.9
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 17
2
Project
Yields all values for selected attributes
Figure 2.10
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 18
2
Join
Information from two or more tables is combined
Figure 2.11
Figure 2.14
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 19
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 20
2
Other Joins
• 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
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 21
2
Divide
Requires user of single-column table and two-column table
Figure 2.17
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 22
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 23
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 24
2
ERD Symbols
• 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
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 25
2
Figure 2.18
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 26
2
Figure 2.20
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 27
2
Figure 2.23
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 28
2
Figure 2.24
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 29
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 30
2
Figure 2.26
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 31
2
Figure 2.27
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 32
2
Figure 2.28
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 33
2
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 34
2
Indexes
• Points to location
• Makes retrieval of data faster
Figure 2.31
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 35