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

5. Relational Model (1)

The document discusses the Relational Data Model, which is based on the concept of relations as mathematical structures. It covers key concepts such as relations, tuples, schemas, and integrity constraints, including key, entity, and referential integrity. Additionally, it outlines operations for retrieving and updating data while maintaining integrity constraints.

Uploaded by

mohamedmt
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)
5 views

5. Relational Model (1)

The document discusses the Relational Data Model, which is based on the concept of relations as mathematical structures. It covers key concepts such as relations, tuples, schemas, and integrity constraints, including key, entity, and referential integrity. Additionally, it outlines operations for retrieving and updating data while maintaining integrity constraints.

Uploaded by

mohamedmt
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/ 28

23CSIS03C

Database Systems
Lecture 5

The Relational Data Model

Copyright © 2004 Pearson Education, Inc.


Literature
• El Masri, R and Navathe, S., “Fundamentals of Database
Systems”, 5th Edition, Pearson Int Edition, Addison Wesley,
ISBN: 0-321-4150-X (2007).

• El Masri, R and Navathe, S. Slides

Slide 2-2
Chapter Outline
⚫ Relational Model Concepts
⚫ Relational Model Constraints and Relational Database
Schemas
⚫ Update Operations and Dealing with Constraint
Violations

Slide 2-3
Relational Model Concepts
• The relational Model of Data is based on the
concept of a Relation.
• A Relation is a mathematical concept based on the
ideas of sets.
• The strength of the relational approach to data
management comes from the formal foundation
provided by the theory of relations.
• We review the essentials of the relational approach
in this lecture.

Slide 2-4
Relational Model Concepts
⚫ The model was first proposed by Dr. E.F. Codd of
IBM in 1970 in the following paper:
"A Relational Model for Large Shared Data
Banks," Communications of the ACM, June 1970.

The above paper caused a major revolution in the field of


Database management and earned Ted Codd the coveted
ACM Turing Award.

Slide 2-5
INFORMAL DEFINITIONS
⚫ A relation is a two-dimensional table:
– Relation ≈ table.
– Attribute ≈ column name.
– Tuple ≈ row (not the header row).
⚫ Database ≈ collection of relations.
⚫ A relation has two parts:
Schema defines column heads of the table (attributes).
Instance contains the data rows (tuples, rows, or records) of the table.

Student Course Grade


Hermione Grainger Database A-
Draco Malfoy Database B
Harry Potter Database A
Ron Weasley Database C

Slide 2-6
FORMAL DEFINITIONS
⚫ A Relation may be defined in multiple ways.
⚫ The Schema of a Relation: R (A1, A2, .....An)
Relation schema R is defined over attributes A1, A2, .....An
For Example -
CUSTOMER (Cust-id, Cust-name, Address, Phone#)

Here, CUSTOMER is a relation defined over the four


attributes Cust-id, Cust-name, Address, Phone#, each of
which has a domain or a set of valid values. For example, the
domain of Cust-id is 6 digit numbers.

Slide 2-7
FORMAL DEFINITIONS
⚫ A tuple is an ordered set of values

⚫ Each value is derived from an appropriate domain.

⚫ Each row in the CUSTOMER table may be referred to as a


tuple in the table and would consist of four values.

⚫ <632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000">

is a tuple belonging to the CUSTOMER relation.

⚫ A relation may be regarded as a set of tuples (rows).

⚫ Columns in a table are also called attributes of the relation.

Slide 2-8
DEFINITION SUMMARY

Informal Terms Formal Terms

Table Relation
Column Attribute/Domain
Row Tuple
Values in a column Domain
Table Definition Schema of a Relation

Slide 2-9
Example - Figure 5.1

Slide 2-10
CHARACTERISTICS OF
RELATIONS
⚫ Ordering of tuples in a relation r(R): The tuples are not
considered to be ordered, even though they appear to be in
the tabular form.
⚫ Ordering of attributes in a relation schema R (and of
values within each tuple): We will consider the attributes
in R(A1, A2, ..., An) and the values in t=<v1, v2, ..., vn> to
be ordered .
(However, a more general alternative definition of relation
does not require this ordering).
⚫ Values in a tuple: All values are considered atomic
(indivisible). A special null value is used to represent
values that are unknown or inapplicable to certain tuples.

Slide 2-11
CHARACTERISTICS OF
RELATIONS
⚫ Each relation in the same relational database schema has a

distinct name

⚫ Each attribute in a relation has a distinct name.

⚫ Values of an attribute are all from the same domain.

⚫ Each tuple is distinct.

Slide 2-12
Degree and Cardinality
Student Course Grade
Hermione Grainger Database A-
Draco Malfoy Database B
Harry Potter Database A
Ron Weasley Database C

⚫ Degree is the number of fields/attributes in schema (=3 in the


table above)
⚫ Cardinality is the number of tuples in relation (=4 in the table
above)

Slide 2-13
Relational Model Integrity
Constraints
⚫ Constraints are conditions that must hold
on all valid relation instances. There are
three main types of constraints:
1. Key constraints
2. Entity integrity constraints
3. Referential integrity constraints
• ICs are specified when schema is defined.
• ICs are checked when relations are modified.

Slide 2-14
Key Constraint

⚫ Supper key

⚫ Candidate Key

⚫ Primary Key

⚫ Composite Keys

⚫ Foreign Key

Slide 2-15
Supper Key
⚫ A Supper key (SK) is an attribute or a set of attributes that uniquely
identify a tuple within a relation.
– Example:
• SS#, Name, Age, License#, Salary
• SS#, Name, Age, License#
• SS#, Name, Age
• SS#, Name
• SS#
➢ Name, Age, Salary (not a super key) ???
➢ Name, Age, Salary, License# (A supper key) ???

Employee
SS# Name Age License# Salary

Slide 2-16
Primary Key
⚫ A Primary key (PK) is a minimal supper key that is used to
identify tuples uniquely. This means that no subset of the primary
key is sufficient to provide unique identification of tuples.

⚫ If a relation has several candidate keys, one is chosen arbitrarily to


be the primary key. The primary key attributes are underlined.

Which candidate should we choose???

⚫ If the key consists of more than one attribute, than this is a


composite key

⚫ Exercise:

Name all the keys in the employee relation.

Slide 2-17
Foreign Key
⚫ A Foreign key (FK) is an attribute(s) in one relation
that matches the primary key of another relation.

⚫ The foreign key should have the same domain(s) of the


referenced primary key.

Department
Dept.# Dept. Name Foreign Key

Employee
SS# Name Age License# Salary Dept.#

Slide 2-18
Entity Integrity
⚫ Relational Database Schema: A set S of relation schemas
that belong to the same database. S is the name of the
database.
S = {R1, R2, ..., Rn}
⚫ Entity Integrity: The primary key attributes PK of each
relation schema R in S cannot have null values in any tuple
of r(R). This is because primary key values are used to
identify the individual tuples.
t[PK]  null for any tuple t in r(R)
⚫ Note: Other attributes of R may be similarly constrained
to disallow null values, even though they are not members
of the primary key.

Slide 2-19
Referential Integrity
⚫ A constraint involving two relations (the previous constraints
involve a single relation).
⚫ Used to specify a relationship among tuples in two relations:
the referencing relation and the referenced relation.
⚫ Tuples in the referencing relation R1 have attributes FK that
reference the primary key attributes PK of the referenced
relation R2.
⚫ A tuple t1 in R1 is said to reference a tuple t2 in R2 if
t1[FK] = t2[PK].
⚫ A referential integrity constraint can be displayed in a
relational database schema as a directed arc from R1.FK to R2.

Slide 2-20
Referential Integrity
Constraint
Statement of the constraint
The value in the foreign key column(s) FK of
the referencing relation R1 can be either:
(1) a value of an existing primary key value of
the corresponding primary key PK in the
referenced relation R2,, or..
(2) a null.
In case (2), the FK in R1 should not be a part of its
own primary key. WHY ??????????

Slide 2-21
Other Types of Constraints
Semantic Integrity Constraints:
- based on application semantics and cannot
be expressed by the model
- E.g., “the max. no. of hours per employee
for all projects he or she works on is 56 hrs
per week”
- A constraint specification language may
have to be used to express these
- SQL-99 allows triggers and ASSERTIONS
to allow for some of these
Slide 2-22
Slide 2-23
Slide 2-24
Slide 2-25
Relational Data Model
Operations
⚫There are two categories of relational data
model operations:
– Retrieval operations extract information from the
relational database.
– Update operations causes the relation (and the
relational database) state changes. They Include:
⚫ Insert a tuple
⚫ Delete a tuple
⚫ Modify a value

Slide 2-26
Relational Data Model
Operations
⚫ Integrity constraints should not be violated by the update
operations.

⚫ Several update operations may have to be grouped


together.

⚫ Updates may propagate to cause other updates


automatically. This may be necessary to maintain integrity
constraints.

Slide 2-27
Violating Integrity Constraints

Slide 2-28

You might also like