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

Relational Data Model

The document describes the relational database model including its logical structure, basic components like tables and keys, integrity rules, and relational algebra operators. Relational databases use tables to store data with rows and columns, and establish relationships between tables using primary and foreign keys. This ensures data integrity and allows queries across related data.

Uploaded by

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

Relational Data Model

The document describes the relational database model including its logical structure, basic components like tables and keys, integrity rules, and relational algebra operators. Relational databases use tables to store data with rows and columns, and establish relationships between tables using primary and foreign keys. This ensures data integrity and allows queries across related data.

Uploaded by

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

IT131-8:

Information Management
The Relational Data Model
Learning Objectives
After completing this chapter, you will be able to:

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
A Logical
View Of Relational database model enables
logical representation of the data
Data
and its relationships
Logical simplicity yields simple and effective
database design methodologies
The logical view is facilitated by the creation of
data relationships based on a logical construct
called a relation
Tables and Their Characteristics
Characteristics of a Relational Table

A table is perceived as a two-dimensional structure composed of rows


and columns.

Each table row (tuple) represents a single entity occurrence within the
entity set.

Each table column represents an attribute, and each column has a distinct
name.

Each intersection of a row and column represents a single data value.


Tables and Their Characteristics
Characteristics of a Relational Table

All values in a column must conform to the same data format.

Each column has a specific range of values known as the attribute domain.

The order of the rows and columns is immaterial to the DBMS.

Each table must have an attribute or combination of attributes that uniquely


identifies each row.
Keys
Table name: STUDENT Database name: Ch03_TinyCollege

STU_NUM = Student number


STU_LNAME = Student last name
STU_FNAME = Student first name
STU_INIT = Student middle initial
STU_DOB = Student date of birth
STU_HRS = Credit hours earned
STU_CLASS = Student classification
STU_GPA = Grade point average
STU_TRANSFER = Student transferred from another institution
DEPT_CODE = Department code
STU_PHONE = 4-digit campus phone extension
PROF_NUM = Number of the professor who is the student's advisor
Keys
Keys consist of one or more
attributes that determine other
attributes
Ensure that each row in a table is uniquely
identifiable
Establish relationships among tables and to
ensure the integrity of the data
Determination
State in which knowing the value of one attribute makes
Dependencies it possible to determine the value of another
Establishes the role of a key and is based on the
relationships among the attributes

Functional Dependence
value of one or more attributes determines the value of one
or more other attributes

Determinant Dependent
attribute whose value attribute whose value
determines another is determined by the
other attribute
Dependencies Examples of Functional Dependence
STU_NUM →
STU_LNAME
STU_NUM →
(STU_FNAME, STU_LNAME, STU_GPA)
(STU_FNAME, STU_LNAME, STU_NUM) →
(STU_DOB, STU_HRS,
STU_GPA)

Full functional dependence


entire collection of attributes in the determinant is
necessary for the relationship
Types of Keys
Key Type Definition
A candidate key selected to uniquely identify all other attribute values in any
Primary key
given row; cannot contain null entries.

A key that is composed of more than one attribute. Note: key attribute is an
Composite key
attribute that is part of a key.

An attribute or combination of attributes that uniquely identifies any row in a


Superkey
table.

A minimal (irreducible) superkey; a superkey that does not contain a subset of


Candidate key
attributes that is itself a superkey.

An attribute or combination of attributes in one table whose values must


Foreign key
either match the primary key in another table or be null.

An attribute or combination of attributes used strictly for data retrieval


Secondary key
purposes.
Entity integrity: condition in which each row in
Integrity the table has its own unique identity
All of the values in the primary key must be unique and no
Rules key attribute in the primary key can contain a null
Null: absence of any data value, may be an unknown
attribute value, known but missing attribute value, or
inapplicable condition

Referential integrity: every reference to an


entity instance by another entity instance is
valid
In other words, every foreign key entry must either be null
or a valid value in the primary key of the related table.
Example

Integrity Table name: PRODUCT


Primary key: PROD_CODE
Database name: Ch03_SaleCo

Rules Foreign key: VEND_CODE

link

Table name: VENDOR


Primary key: VEND_CODE
Foreign key: none
Integrity
Rules Relational database integrity rules are very
important to good database design

Relational database management systems


(RDBMSs) enforce integrity rules
automatically
Integrity Entity Integrity Description

Rules All primary key entries are unique, and no part of a


Requirement
primary key may be null.

Each row will have a unique identity, and foreign key


Purpose
values can properly reference primary key values.

No invoice can have a duplicate number, nor can it


Example be null; in short, all invoices are uniquely identified by
their invoice number.
Referential
Integrity Integrity Description

Rules A foreign key may have either a null entry, as long as it is not a
part of its table’s primary key, or an entry that matches the
Requirement primary key value in a table to which it is related (every non-null
foreign key value must reference an existing primary key value).

It is possible for an attribute not to have a corresponding value,


but it will be impossible to have an invalid entry; the
Purpose
enforcement of the referential integrity rule makes it impossible
to delete a row in one table whose primary key has mandatory
matching foreign key values in another table.

A customer might not yet have an assigned sales representative


Example (number), but it will be impossible to have an invalid sales
representative (number).
Ways to Handle Nulls

Flags
Special codes used to indicate the absence of some value

Constraints
NOT NULL constraint: placed on a column to ensure that every row in
the table has a value for that column
UNIQUE constraint: restriction placed on a column to ensure that no
duplicate values exist for that column
Relational Theoretical way of manipulating table contents using relational

Algebra
operators

Relvar
variable that holds a relation
Heading contains the names of
the attributes
Body contains the relation

Relational operators have


the property of closure
Closure: use of relational
algebra operators on existing
relations produces new
relations
Relational Set Operators
Original Table New Table
SELECT
SELECT ALL yields (Restrict)
Unary operator
that yields a
horizontal subset
SELECT only PRICE less than $2.00 yields of a table

SELECT only P_CODE = 311452 yields


Relational Set Operators
Original Table New Table

PROJECT PRICE yields


PROJECT
Unary operator
that yields a
vertical subset of
PROJECT P_DESCRIPT and PRICE yields
a table

PROJECT P_CODE and PRICE yields


Relational Set Operators
UNION
Combines all rows from
two tables, excluding
UNION yields duplicate rows
Union-compatible: tables
share the same number
of columns, and their
corresponding columns
share compatible
domains

INTERSECT yields INTERSECT


Yields only the rows that
appear in both tables
Tables must be union-
compatible to yield valid
results
Relational Set Operators
DIFFERENCE
DIFFERENCE yields
Yields all rows in one
table that are not found
in the other table
Tables must be union-
compatible to yield
valid results

yields
PRODUCT
PRODUCT
Yields all possible
pairs of rows from two
tables
Relational Joins allow information to be
Set Operators intelligently combined from two or
more tables
Natural join
Equijoin
Theta join
Inner join
Outer join
Left outer join
Right outer join
Natural Join
Links tables by selecting only the rows with
common values in all their common
attributes (three step process)

Given:
Table name : CUSTOMER Table name : AGENT
Natural Join
Step 1 : Product
Natural Join
Step 2 : Select only common attributes with equal values

Step 3 : Perform project to eliminate duplicates


Thetajoin
Links tables using an inequality comparison operator (<, >, <=, >=)

Given:
Table name : CUSTOMER Table name : AGENT
Equijoin
Links tables on the basis of an equality condition that compares
specified columns of each table

Given:
Table name : CUSTOMER Table name : AGENT
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

Given:
Table name : CUSTOMER Table name : AGENT
Outer Join
Matched pairs are retained and unmatched values in the other table are left null

Right outer join


yields all of the rows in the second table, including those that do not have
matching values in the first table

Given:
Table name : CUSTOMER Table name : AGENT
Divide
Uses one double-column table as the dividend and one single-column table
as the divisor
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

Example:
yields
DIVIDE
Data Dictionary
Description of all tables in the database created by the user and designer

Sample Data Dictionary:


System
Catalog Homonyms and synonyms must
System data dictionary be avoided to lessen confusion
that describes all
objects within the
database
Homonym Synonym
same name is used different names are
to label different used to describe
attributes the same attribute
Relationships within
One-to-many (1:M)
the Relational Norm for relational databases
Database
One-to-one (1:1)
One entity can be related to only one other entity
and vice versa

Many-to-many (M:N)
Implemented by creating a new entity in 1:M
relationships with the original entities
Composite entity (i.e., bridge or associative entity):
helps avoid problems inherent to M:N relationships
and includes the primary keys of tables to be linked
THE 1:1 RELATIONSHIP BETWEEN PROFESSOR AND
Relationships within
DEPARTMENT
the Relational
Database

CHANGING THE M:N RELATIONSHIPS TO TWO 1:M


RELATIONSHIPS
Data The relational database facilitates control of
Redundancy data redundancies through use of foreign keys
(common attributes that are shared by tables)
Revisited
To be controlled except the following
circumstances:
Sometimes data redundancy must be
increased to make the database serve
crucial information purposes
Sometimes data redundancy exists to
preserve the historical accuracy of data
Indexes Orderly arrangement to logically access rows
in a table
Index key: index’s reference point that
leads to data location identified by the key
Unique index: index key can have only one
pointer value associated with it

Each index is associated with only one table


but the index key can have multiple attributes
Codd’s Relational Database Rules

Rule Rule Name Description

All information in a relational database must be logically


1 Information
represented as column values in rows within tables.

Guaranteed Every value in a table is guaranteed to be accessible through a


2
Access combination of table name, primary key value, and column name.

Systematic treatment Nulls must be represented and treated in a systematic way,


3
of nulls independent of data type.

The metadata must be stored and managed as ordinary data—that


Dynamic online catalog based
4 is, in tables within the database; such data must be available to
on the relational model
authorized users using the standard database relational language.
Codd’s Relational Database Rules
Rule Rule Name Description

The relational database may support many languages; however, it


must
Comprehensive data support one well-defined, declarative language as well as data
5
sublanguage definition, view definition, data manipulation (interactive and by
program), integrity constraints, authorization, and transaction
management (begin, commit, and rollback)

Every value in a table is guaranteed to be accessible through a


6 View updating
combination of table name, primary key value, and column name.

High-level insert,
7 The database must support set-level inserts, updates, and deletes.
update, and delete

Application programs and ad hoc facilities are logically unaffected


8 Physical data independence
when physical access methods or storage structures are changed.
Codd’s Relational Database Rules
Rule Rule Name Description

Application programs and ad hoc facilities are logically unaffected


Logical data when changes are made to the table structures that preserve the
9
independence original table values (changing order of columns or inserting
columns).

All relational integrity constraints must be definable in the relational


Integrity
10 language and stored in the system catalog, not at the application
independence
level.

Distribution The end users and application programs are unaware of and
11
independence unaffected by the data location (distributed vs. local databases).

If the system supports low-level access to the data, users must not
12 Nonsubversion
be allowed to bypass the integrity rules of the database.

All preceding rules are based on the notion that to be considered


13 Rule zero relational, a database must use its relational facilities exclusively for
management.

You might also like