0% found this document useful (0 votes)
6 views

Chapter-03

Chapter 3 of COMP255 covers the relational database model, including its logical structure, components, and key concepts like tables, keys, and integrity rules. It explains relational algebra and operators for data manipulation, as well as relationships between entities and data redundancy management. The chapter also discusses the importance of indexing for efficient data retrieval.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Chapter-03

Chapter 3 of COMP255 covers the relational database model, including its logical structure, components, and key concepts like tables, keys, and integrity rules. It explains relational algebra and operators for data manipulation, as well as relationships between entities and data redundancy management. The chapter also discusses the importance of indexing for efficient data retrieval.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

COMP255

Chapter 3
The Relational Database Model

1
Learning Objectives

Describe the relational database model’s logical structure

Identify the relational model’s basic components and explain the structure,
contents, and characteristics of a relational table

Use relational database operators to manipulate relational table contents

Explain the purpose and components of the data dictionary and system catalog

Identify appropriate entities and then the relationships among the entities in the
relational database model

Describe how data redundancy is handled in the relational database model

Explain the purpose of indexing in a relational database

2
Codd’s Relational Model

Based on Mathematics
– Predicate logic and set theory

Three well-defined components
– Logical data structure

Separate from physical needs
– Set of integrity rules

Ensures data is and remains consistent
– Set of operations

Defines how data is manipulated

3
Tables

Tables = relations
– Different words for the same object

4
Tables

5
Definitions

Key
– One or more attributes that determine other attributes

Determination
– State in which knowing the value of one attribute makes it possible to determine the value of another

Determinant
– Any attribute in a specific row whose value directly determines other values in that row

Dependent
– An attribute whose value is determined by another attribute

Functional dependence
– Within a relation R, an attribute B is functionally dependent on an attribute A if and only if a given value of
attribute A determines exactly one value of attribute B
– The relationship “B is dependent on A” is equivalent to “A determines B” and is written as A → B

6
Determination Examples

STU_NUM → STU_LNAME

STU_NUM → (STU_LNAME, STU_FNAME,
STU_GPA)

(STU_FNAME, STU_LNAME, STU_INIT,
STU_PHONE) → (STU_DOB, STU_HRS,
STU_GPA)

7
Tables

8
Types of Keys

9
Entity Integrity

Each row has a unique value in a primary key

The primary key is not NULL

NULL
– The absence of a value
– Different than an empty string (“”)

10
Referential Integrity

Foreign Key
– Primary key of table A that has been placed into
Table B to create a common attribute

Referential integrity
– Every reference to an entity instance by another
entity instance is valid

11
Referential Integrity

12
Integrity Summary

13
Relational Algebra

What is an algebra?
– A set of objects with operators

The algebra we are used to
– Real numbers, + - * / ^, etc.

There are many more
– Complex numbers, + - * / ^, etc.
– Matrices, multiplication, scalar multiplication, + , etc.

14
Relational Algebra

Closure Property
– Important property of a “good” algebra
– The result of an operation is member of the set

Relational algebra allows things to be proven
mathematically
– Minimal data redundancy
– Normalization

15
Relational Algebra Operators

SELECT (or RESTRICT) ●
DIFFERENCE
– Subset of rows – Remove common rows from first
table

PROJECT
– Subset of columns

PRODUCT

UNION
– All combinations of rows
– All rows,columns in two similar ●
DIVIDE
tables – Only those rows related to all

INTERSECT values in a column
– Common rows in two similar tables ●
JOIN
– Like product but using a common
attribute for combinations
16
SELECT

17
PROJECT

18
UNION and INTERSECT

19
DIFFERENCE

20
PRODUCT

21
DIVIDE

22
Types of Joins

Join
– Combines information from two or more tables

Natural join
– Links tables by selecting only the rows with common values in the common attributes

Equijoin
– Links tables on the basis of an equality condition that compares specified columns of
each table

Theta join
– Links tables using an inequality comparison operator

23
Natural Join

Uses the other relational operators

Steps in a natural join of two tables
– Create PRODUCT of the two tables
– Do a SELECT of the result where the common
attributes are the same
– DO a PROJECT to remove the duplicate columns

24
Step 1

25
Steps 2 and 3

26
Other Join Definitions

Inner join
– The previous joins
– Return only matched rows

Outer join
– Return matched rows and unmatched rows

Left outer join

Right outer join
– Return matched and unmatched rows from left/right table

27
Left Outer Join

28
Right Outer Join

29
Outer Joins

Outer joins are created using:
– JOIN
– DIFFERENCE
– UNION
– PRODUCT

30
Data Dictionary and System Catalog

Data dictionary
– Description of all tables in the database created by
the user and designer

System catalog
– System data dictionary that describes all objects
within the database

31
Data Dictionary and System Catalog

32
Relationships

One-to-Many (1:M)
– One occurrence of an entity can be related to many occurrences of
another
– Supported by relational databases

One-to-One (1:1)
– One instance of an entity can only be related to one occurrence of another
– Typically should not exist, but sometimes…
– Special case of 1:M

33
One-to-Many

34
One-to-One

35
Many-to-Many

Not supported in relational databases

Need to change to 2 1:M relationships
– Add bridge/composite entity

36
Composite Entity/Linking Table

37
Composite Entity/Linking Table

38
More on Data Redundancy

Relationships and foreign keys facilitate control
of redundancies

Is data redundant?
– Does the elimination of an attribute also eliminate
information?
– Yes – don’t remove, No – remove

39
Good Redundancy?

Yes, sometimes redundancy is OK
– Speed up processing
– Fully normalized databases can be slow
– Data warehouses

Sometimes redundancy is not really
redundancy

40
Indexes

Related to secondary keys
– Key used strictly for data retrieval purposes

Index
– An ordered array of index key values and row ID values
(pointers)
– Indexes are generally used to speed up and facilitate data
retrieval
– Also known as an index key

41
Indexes

42
Codd’s Relational Database Rules

43

You might also like