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

ILS3A01 Week 3

The document covers the relational database model, focusing on relational algebra and its operators, which include SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE, PRODUCT, and DIVIDE. It also discusses relationships within databases, such as one-to-many, one-to-one, and many-to-many, and emphasizes the importance of data redundancy control and the use of indexes. Additionally, it outlines Dr. Codd's 12 relational database rules that define the characteristics and requirements of relational databases.

Uploaded by

mk365org
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

ILS3A01 Week 3

The document covers the relational database model, focusing on relational algebra and its operators, which include SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE, PRODUCT, and DIVIDE. It also discusses relationships within databases, such as one-to-many, one-to-one, and many-to-many, and emphasizes the importance of data redundancy control and the use of indexes. Additionally, it outlines Dr. Codd's 12 relational database rules that define the characteristics and requirements of relational databases.

Uploaded by

mk365org
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

INFORMATION SYSTEMS 3A

PRESENTED BY PROF TANIA PRINSLOO

WEEK 3
Database Systems:
Design,
Implementation, and
Management, 14e
Module 3: The Relational
Database Model

Footnote Coronel, Carlos and Morris, Steven, Database Systems: Design, Implementation, and Management, 14 Edition. © 2023 Cengage. All Rights 2
Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. 2
Relational Algebra

Relational algebra is a set of mathematical principles that form the


basis for manipulating relational table contents

The following are the eight main SELECT, PROJECT, JOIN, INTERSECT,
UNION, DIFFERENCE, PRODUCT, and
functions: DIVIDE

Footnote 3
Formal Definitions and Terminology

A relation is the data that you see in your tables

It is a container (variable) for holding a


A relvar is a variable that holds a relation data, not the relation itself
relation The term is short for relation variable

The heading contains the names of the


A relvar has the following two attributes
parts: The body contains the relation

Footnote 4
Relational Set Operators

Select (restrict): operator that yields a horizontal subset of a table.

Project: operator that yields a vertical subset of a table.

Combines all rows from two tables, excluding duplicate rows.


Union: Union-compatible: tables share the same number of columns,
and their corresponding columns share compatible domains.

Yields only the rows that appear in both tables.


Intersect: Tables must be union-compatible to yield valid results.

Footnote 5
Relational Set Operators (1 of 7)

• Figure 3.4 SELECT

• SELECT is an operator used to select a subset of rows

• Also known as RESTRICT

• Figure 3.5 PROJECT

• PROJECT is an operator used to select a subset of columns

Footnote 6
Relational Set Operators (2 of 7)

• Figure 3.6 UNION

• UNION is an operator used to merge two tables


into a new table, dropping duplicate rows

• The tables must be union-compatible

• Figure 3.7 INTERSECT

• INTERSECT is an operator used to yield only the


rows that are common to two union-compatible
tables

Footnote 7
Relational Set Operators

• Yields all rows in one table that are not found in the other table

Difference
• Tables must be union-compatible to yield valid results
• Union-compatible essentially implies that the tables being
“unioned” should have the same attributes in the same
sequence.”

Product • Yields all possible pairs of rows from two tables

Footnote 8
Relational Set Operators (3 of 7)

• Figure 3.8 DIFFERENCE

• DIFFERENCE is an operator used to yield all


rows from one table that are not found in
another union-compatible table

• Figure 3.9 PRODUCT

• PRODUCT is an operator used to yield all


possible pairs of rows from two tables

• Also known as the Cartesian product

Footnote 9
Relational Set Operators (4 of 7)

• Figure 3.10 Two Tables that Will be Used in JOIN


Illustrations

• JOIN allows information to be intelligently


combined from two or more tables

• Figure 3.11 Natural JOIN, Step 1: PRODUCT

• A natural join links tables by selecting only the


rows with common values in their common
attribute(s)

Footnote 10
Relational Set Operators (5 of 7)

• Figure 3.12 Natural JOIN, Step 2: SELECT

• A SELECT is performed on the output of Step 1 to


yield only the rows for which the AGENT_CODE
values are equal

• Figure 3.13 Natural JOIN, Step 3: PROJECT

• A PROJECT is performed on the results of Step 2


to yield a single copy of each attribute

Footnote 11
Relational Set Operators (6 of 7)

• Other forms of JOIN include the following:


• 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

• Inner join – only returns matched records from the tables that are being joined

• Outer join – matched pairs are retained and unmatched values in the other table are left null

• Left outer join: yields all of the rows in the first table, including those that do not have a matching
value in the second table

• Right outer join: yields all of the rows in the second table, including those that do not have matching
values in the first table

Footnote 12
Relational Set Operators (7 of 7)

• Figure 3.16 DIVIDE

• The DIVIDE operator is used to


answer questions about one set
of data being associated with all
values of data in another set of
data

1. It uses one double-column table as the dividend and one single-column


table as the divisor.
2. Output is a single column that contains all values from the second column of
the dividend that are associated with every row in the divisor.

Footnote 13
Combining data from more than one table

Footnote 14
NATURAL JOIN (relates directly to Inner Join)

Natural join: links tables by


selecting only the rows with
common values in their
common attribute

Inner join: only returns


matched records from the
tables that are being joined

Footnote 15
OUTER JOIN
Outer join - Matched pairs are retained, and any unmatched values in other table
are left null

R L RIGHT OUTER JOIN


Right = reference

LEFT OUTER JOIN NB Referential integrity problem here


Left = reference
Footnote 16
OUTER JOIN

Footnote 17
SQL JOINS

Footnote 18
Be careful: The difference between Union and Inner / Outer Join?

Joins and Unions can be used to combine data from one or more
tables. The difference lies in how the data is combined.

Joins combine data into new Unions combine data into new
columns. If two tables are rows. If two tables are “unioned”
joined together, then the data together, then the data from the first
from the first table is shown in table is in one set of rows, and the
one set of column alongside the data from the second table in
second table’s column in the another set. The rows are in the
same row. same result.
Footnote 19
The Data Dictionary and the System Catalog

The data dictionary provides a detailed It is sometimes described as “the database


designer’s database” because it records the
description of all tables in the database design decisions about tables and their
created by the user and designer structures

The system catalog is a detailed system data dictionary that describes all
objects within the database

Homonym – same name is used to label


Homonyms and synonyms must be different attributes
avoided to lessen confusion Synonym – different names are used to
describe the same attribute

Footnote 20
Relationships within the Relational Database (1 of 6)

• The one-to-many (1:M) relationship is the norm for relational databases


• In the one-to-one (1:1) relationship, one entity can be related to only one other entity and vice versa
• The many-to-many (M:N) relationship can be implemented by creating a new entity in 1:M
relationships with the original entities
• A composite entity (i.e., bridge or associative entity) helps avoid problems inherent to M:N
relationships
• It includes the primary keys of tables to be linked

Footnote 21
Relationships within the Relational Database (2 of 6)

• Figure 3.19 The 1:M Relationship between


COURSE and CLASS

• Figure 3.20 The Implemented 1:M


Relationship between COURSE and CLASS

Footnote 22
Relationships within the Relational Database (3 of 6)

• Figure 3.21 The 1:1 Relationship between


PROFESSOR and DEPARTMENT

• Figure 3.22 The Implemented 1:1


Relationship between PROFESSOR and
DEPARTMENT

Footnote 23
Relationships within the Relational Database (4 of 6)

• Figure 3.23 The ERM’s M:N Relationship


between STUDENT and CLASS

• Figure 3.24 The Wrong Implementation of


the M:N Relationship between STUDENT
and CLASS

Footnote 24
Relationships within the Relational Database (5 of 6)

• Figure 3.25 Converting the M:N Relationship into Two


1:M Relationships

• Because the ENROLL table links two tables, it is also


called a linking table

• Figure 3.26 Changing the M:N Relationships to Two


1:M Relationships

Footnote 25
Relationships within the Relational Database (6 of 6)

• Figure 3.27 The Expanded ER


Model

• Figure 3.28 The Relational Diagram


for the Ch03_TinyCollege Database

Footnote 26
Data Redundancy Revisited (1 of 2)

The relational database facilitates


Recall that foreign keys are common attributes that
control of data redundancies are shared by tables
through use of foreign keys

Sometimes data redundancy must be increased to


Data redundancy should be make the database serve crucial information
controlled except in the following purposes
Sometimes data redundancy exists to preserve the
circumstances: historical accuracy of data

Footnote 27
Data Redundancy Revisited (2 of 2)

• Figure 3.29 A Small Invoicing System

• Figure 3.30 The Relational Diagram for


the Invoicing System

Footnote 28
Indexes (1 of 2)

An index is an orderly arrangement to logically access rows in a table

The index key is the index’s reference point that leads to data location identified by the key

In a unique index, the index key can have only one pointer value associated with it

A table can have many indexes, but each index is associated with only one table

The index key can have multiple attributes

Footnote 29
Indexes (2 of 2)

Footnote Figure 3.31 Components of an Index 30


Cobb’s Relational Database Rules (1 of 2)

Table 13.8 Dr. Codd’s 12 Relational Database Rules

Rule Rule Name Description

1 Information All information in a relational database must be logically represented as column values in rows
within tables.
2 Guaranteed access Every value in a table is guaranteed to be accessible through a combination of table name, primary
key value, and column name.
3 Systematic treatment of nulls Nulls must be represented and treated in a systematic way, independent of data type.

4 Dynamic online catalog based The metadata must be stored and managed as ordinary data—that is, in tables within the database;
on the relational model such data must be available to authorized users using the standard database relational language.
5 Comprehensive data The relational database may support many languages; however, it must
sublanguage support one well-defined, declarative language as well as data definition,
view definition, data manipulation (interactive and by program), integrity
constraints, authorization, and transaction management (begin, commit,
and rollback).
6 View updating Any view that is theoretically updatable must be updatable through the
system.
7 High-level insert, update, and delete The database must support set-level inserts, updates, and deletes.

Footnote 31
Cobb’s Relational Database Rules (2 of 2)

Table 13.8 Dr. Codd’s 12 Relational Database Rules

Rule Rule Name Description

8 Physical data independence Application programs and ad hoc facilities are logically unaffected when physical access methods
or storage structures are changed.
9 Logical data independence Application programs and ad hoc facilities are logically unaffected when changes are made to the
table structures that preserve the original table values (changing order of columns or inserting
columns).
10 Integrity independence All relational integrity constraints must be definable in the relational language and stored in the
system catalog, not at the application level.
11 Distribution independence The end users and application programs are unaware of and unaffected by the data location
(distributed vs. local databases).
12 Nonsubversion If the system supports low-level access to the data, users must not be allowed to bypass the
integrity rules of the database.
13 Rule zero All preceding rules are based on the notion that to be considered relational, a database must use its
relational facilities exclusively for management.

Footnote 32
Questions???

Footnote 33

You might also like