You are on page 1of 42

CHAPTER 3 : DATA RELATIONAL MODEL

Prepared by : Norzelan bin Saleh


Relational model
Enables programmer to view data logically rather than
physically
Relational Model
A database is a collection of information that is organized so
that it can easily be accessed, managed, and updated.

In one view, databases can be classified according to types of
content: bibliographic, full-text, numeric, and images.
What is Database?
Table: two-dimensional structure composed of rows and
columns

Components of database table are :
Record (tuple) - is a sequence of attributes i.e. a row in the relation
table.
Attribute (field) - is a named column in the relation table.
Domain - The domain of an attribute defines the set of values which can
apply to that attribute.
Degree - The degree of a relation refers to the number of attributes in
each tuple.
Cardinality - This refers to the number of tuples in the relation


Components of Database Table


Relation Schema: relation name + attribute names + domain

Relation name

Attribute name

Domains


Characteristic of Relation Scheme
Consists of one or more attributes that determine other
attributes.




Keys
Primary Key - Primary key (PK) is an attribute (or a
combination of attributes) that uniquely identifies any given
entity (row)

Superkey - Any key that uniquely identifies each row

Candidate key - A superkey without redundancies

Composite key - Composed of more than one attribute

Foreign key a field in a relational table that matches the
primary key column of another table. The foreign key can be
used to cross-reference tables





Entity Integrity

Referential Integrity - FK contains a value that refers to an existing valid
tuple (row) in another relation

Integrity Rules



Relational Model Relationship
One entity
related to
another of
the same
entity type
Entities of
two different
types related
to each other
Entities of three
different types
related to each
other
Each entity in the relationship will have exactly one related
entity

One to Many Relationship
Entities on both sides of the relationship can have many related
entities on the other side

Many to Many Relationship


Converting the M:N relationship into TWO 1:M relationships
Foreign keys reference the primary keys in the other
tables of which it has a relationship with

The database designer has 2 main options to define
a composite tables primary key:
either
use the combination of those foreign keys or
create a new primary key.
Self-referencing relationships are a special case of a normal
table relationship.

The only difference is that in this case, there is only one table
involved and it is on both sides of the relationship.

Example :
One common example is an Employees table that contains information
about the supervisor of each employee. Each supervisor is also an
employee and has his or her own supervisor. In this case, there is a one-
to-many self-referencing relationship, as each employee has one
supervisor but each supervisor may have more than one employee.
Self Referencing Relationship


Relational algebra
Defines theoretical way of manipulating table contents using relational
operators
Use of relational algebra operators on existing tables (relations)
produces new relations

Relational Database Algebra
Restrict (select)
Project
Join (outer, inner)
Cartesian Product

Yields values for all rows found in a table

Can be used to list either all row values or it can yield only those row
values that match a specified criterion

Yields a horizontal subset of a table

Select


Yields all values for selected attributes

Yields a vertical subset of a table

Project


Allows information to be combined from two or more tables

Real power behind the relational database, allowing the use of
independent tables linked by common attributes

Join

Outer join:

Matched pairs are retained and any unmatched values in other table
are left null

In outer join for tables CUSTOMER and AGENT, two scenarios are
possible:

Left outer join
Yields all rows in CUSTOMER table, including those that do not
have a matching value in the AGENT table

Right outer join
Yields all rows in AGENT table, including those that do not have
matching values in the CUSTOMER table


Inner Join

An inner join (sometimes called a simple join) is a join of two or more
tables that returns only those rows that satisfy the join condition.

Traditional inner joins look for rows that match rows in the other
table(s), i.e. to join two tables based on values in one table being equal
to values in another table

Also known as equality join, equijoin or natural join

Returns results only if records exist in both tables


Database Systems: Design, Implementation, &
Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators (continued)
Union:
Combines all rows from two tables, excluding duplicate
rows
Tables must have the same attribute characteristics
Intersect:
Yields only the rows that appear in both tables
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
Database Systems: Design, Implementation, &
Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators (continued)
Difference
Yields all rows in one table not found in the other
table that is, it subtracts one table from the
other
Product
Yields all possible pairs of rows from two tables
Also known as the Cartesian product
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)
Database Systems: Design, Implementation, &
Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators (continued)
DIVIDE requires the use of one single-column
table and one two-column table
Database Systems: Design, Implementation, & Management, 7
th
Edition, Rob & Coronel
Relational Algebra Operators
(continued)

You might also like