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

Module 2 Lecture

This document covers the relational model in database concepts, focusing on key terminology, relationships, and normalization processes. It explains the significance of keys, foreign keys, and functional dependencies, as well as the steps for normalizing relations to ensure data integrity. The document also outlines various normal forms, including 1NF, 2NF, 3NF, BCNF, and 4NF, detailing their requirements and implications.

Uploaded by

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

Module 2 Lecture

This document covers the relational model in database concepts, focusing on key terminology, relationships, and normalization processes. It explains the significance of keys, foreign keys, and functional dependencies, as well as the steps for normalizing relations to ensure data integrity. The document also outlines various normal forms, including 1NF, 2NF, 3NF, BCNF, and 4NF, detailing their requirements and implications.

Uploaded by

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

Database Concepts

Ninth Edition

Chapter 2
The Relational Model

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Learning Objectives
2

• Learn the conceptual foundation of the relational model


• Understand how relations differ from nonrelational tables
• Learn basic relational terminology
• Learn the meaning and importance of keys, foreign keys, and
related terminology
• Understand how foreign keys represent relationships
• Learn the purpose and use of surrogate keys
• Learn the meaning of functional dependencies
• Learn to apply a process for normalizing relations

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Relational Terms
3

Learn the conceptual foundation of the


relational model
• An entity is something of importance to the user that needs to
be represented in a database.
– In an entity-relationship model (discussed in Chapter 4),
entities are restricted to things that can be represented by a
single table.
• A relation is a two-dimensional table consisting of rows and
columns that has the characteristics shown in Figure 2.1 on the
next slide.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.1 Characteristics of a
4

Relation

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.2 Sample EMPLOYEE
5

Relation

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.3 Nonrelational Table-
6

Multiple Entries per Cell

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.4 Nonrelational Table-Order
7

of Rows Matters and Kind of Column


Entries Differs in Email

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.5 Relation with Variable-
8

Length Column Values

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Presenting Relation Structures
9

Learn basic relational terminology


• When writing out relation structures use the following format:
– Relation names are written first in all caps (if two words
then use an underscore between them) and they are
always singular.
– A column name is written with the first letter capitalized (if
two words, then run them together and capitalize the first
letter of each word)
• A database schema is the design on which a database and its
associated applications are built.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.6 Equivalent Sets of Terms
10

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Types of Keys
11

Learn the meaning and importance of keys,


foreign keys, and related terminology
• A key is one or more columns of a relation that is used to
identify a row.
– A key can be unique (primary key) or nonunique (foreign
key)
• A composite key contains two or more attributes.
• Candidate keys are keys that uniquely identify each row in a
relation.
• A primary key is a candidate key that is chosen as the key that
the DMBS will use to uniquely identify each row in a relation.
– The primary key in a relation will be underlined.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Example of a Relation
12

Learn the meaning and importance of keys,


foreign keys, and related terminology
• Consider the following example of a relation:
• EMPLOYEE (EmployeeNumber, FirstName, LastName,
Department, EmailAddress, Phone)
• Notice the following in the example above:
– The relation is in all caps
– All the attributes are within parentheses
– The primary key consists of two words run together with the
first letter of each word capitalized. It is also underlined.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.7 Defining a Primary Key in
13

Microsoft Access 2019

Access 2019, Windows 10, Microsoft Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.8 Defining a Primary Key in
14

MySQL 8.0

MySQL Community Server 8.0, MySQL Workbench, Oracle Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.9 Defining a Key in
15

Microsoft SQL Server 2017

SQL Server 2017, SQL Server Management Studio, Microsoft Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.10 Defining a Primary Key in
16

Oracle Database XE

Oracle Database XE, SQL Developer 18.4, Oracle Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Surrogate Keys
17

Learn the purpose and use of surrogate keys


• A surrogate key is a column with a unique, DBMS-assigned
identifier that has been added to a table to be the primary key.
– The ideal surrogate key is short, numeric and never
changes.
• Suppose we have the following table:
PROPERTY (Street, City, State, ZIP, OwnerID)
– Notice that it takes the street, city, state, and zip to uniquely
identify a row in a table.
• Now lets use a surrogate key as a unique identifier!
PROPERTY (PropertyID, Street, City, State, ZIP, OwnerID)

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Foreign Keys
18

Learn how foreign keys represent relationships


• A foreign key is a primary key of another relation that has
been placed in the current relation to represent a relationship
between two tables.
– It is represented in a relation by italics as seen in the
example below.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Referential Integrity
19

Understand how foreign keys represent


relationships
• A referential integrity constraint states that every value of a
foreign key must match a value of an existing primary key.
• In the relationship between EMPLOYEE and DEPARTMENT
seen on the previous slide, the department attribute located in
the EMPLOYEE table is the foreign key and whatever value is
placed in that column, the same value MUST exist in the
Department attribute in the DEPARTMENT table.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.11 Enforcing Referential
20

Integrity in Microsoft Access 2019

Access 2019, Windows 10, Microsoft Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.12 Enforcing Referential
21

Integrity in MySQL 8.0

MySQL Community Server 8.0, MySQL Workbench, Oracle Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.13 Enforcing Referential
22

Integrity in Microsoft SQL Server 2017

SQL Server 2017, SQL Server Management Studio, Microsoft Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.14 Enforcing Referential
23

Integrity in Oracle Database XE

Oracle Database XE, SQL Developer 18.4, Oracle Corporation


Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
The NULL Value
24

Learn the meaning and importance of keys,


foreign keys, and related terminology
• A null value is a missing value in a cell in a relation.
• The problem with null values is that it is ambiguous:
– Is it that no value is appropriate,
– Is it known, but not entered, or
– Is it unknown, thus not entered.
• You can eliminate null values by requiring an attribute value.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.15 Sample ITEM Relation
25

and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Functional Dependencies
26

Learn the meaning of functional dependencies


• A functional dependency occurs when a candidate key
determines all the other attributes in a relation.
– In other words, all the attributes in a relation is functionally
dependent on the candidate key.
– A dependency is shown with the determinant on the left
and then an arrow showing the attribute(s) that depend on
it, as shown below.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
27

Learn to apply a process for normalizing


relations
• Normalization is the process of (or set of steps for) breaking a
table or relation with more than one theme into a set of tables
such that each has only one theme.
• Relational design principles for a well-formed relation:
– Every determinant must be a candidate key
– Any relation that is not well formed should be broken into
two or more relations that are well formed

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
28

First Normal Form (1NF)

• A relation is in first normal form (1NF) if it:


– Has characteristics listed in Figure 2.1
– Has a defined primary key
– No repeating groups
§ repeating group is a set of logically related fields or values that occur
multiple times in one record

Any table that meets the requirements of a relation, has a primary key,
and no repeating groups is in first normal form.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
29

First Normal Form (1NF)

StudentId StudentName ClassName


101 Student1 DB, Java
102 Student2 Interface Design
Ethics,
103 Student3
Programming 2

StudentId StudentName ClassName


101 Student1 DB
101 Student1 Java
102 Student2 Interface Design
103 Student3 Ethics
103 Student3 Programming 2
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
30

Second Normal Form (2NF)

• In first formal form.


• No Partial Dependency.

• Partial Dependency, where an attribute in a table depends


on only a part of the primary/candidate key and not on the
whole key.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
31

Second Normal Form (2NF)

ProfessorId Subject ProfessorAge


1 Math 30
2 Physics 38
3 Biology 40
3 Physics 40

- Primary key is ProfessorId and Subject


- ProfessorAge depend on ProfessorId

ProfessorId Subject ProfessorId ProfessorAge


1 Math 1 30
2 Physics 2 38
3 Biology 3 40
3 Physics
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
32

Third Normal Form (3NF)

• In second normal form.


• No Transitive Dependency.

- Transitive Dependency. When a non-prime attribute


depends on other non-prime attributes

- Non-prime attribute is an attribute that does not


belong to any candidate key

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
33

Third Normal Form (3NF)

StudentId ClassId ProfessorId ProfessorName


10 1 11 Prof 1
10 2 22 Prof 2
11 1 11 Prof 1

- ProfessorId depends on the StudentId, and ClassId


- ProfessorName depend on ProfessorId

StudentId ClassId ProfessorId ProfessorId ProfessorName


10 1 11 11 Prof 1
10 2 22 22 Prof 2
11 1 11
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
34

Boyce and Codd Normal Form (BCNF)

• In third normal form


• For each functional dependency ( X → Y ), X should be a
super key

- For a dependency A → B, A cannot be a non-prime


attribute, if B is a prime attribute.
- A superkey is a set of attributes within a table whose
values can be used to uniquely identify a tuple
- A candidate key a minimal superkey

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
35

Boyce and Codd Normal Form (BCNF)


StudentId Class ProfessorName
101 DB DBProf1
101 Ethics EthicsProf
102 DB DBProf2
103 ID IDProf
104 DB DBProf2

- Primary Key is StudentId, Class, then Class is prime attribute


! "#$%&''$# ---------------à ()*''.

StudentId ProfessorId ProfessorId ProfessorName Class


101 1 1 DBProf1 DB
101 4 2 DBProf2 DB
102 2 3 IDProf ID
103 3 4 EthicsProf Ethics
104 2 Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
36

Forth Normal Form (4NF)

• In Boyce-Codd normal form.


• No Multi-Valued Dependency

• What is Multi-valued Dependency?


– A table is said to have multi-valued dependency, if:
§ For a dependency A ->> B, if for a single value of A, multiple value of B exists,
then the table may have multi-valued dependency.
§ Also, a table should have at-least 3 columns for it to have a multi-valued
dependency.
§ And, for a relation R(A,B,C), if there is a multi-valued dependency between, A
and B, then B and C should be independent of each other.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization
37

Forth Normal Form (4NF)


StudentId Class Advisor
101 DB Advisor1
101 IC Advisor2
101 DB Advisor2
101 IC Advisor1

! +,-.&/,0. ---------------à ()*''12single student has multiple classes


! +,-.&/,0. ---------------à 3.45'$#!"single student has multiple advisors
- Classes and Advisors are independent

StudentId Class StudentId Advisor


101 DB 101 Advisor1
101 IC 101 Advisor2

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Normalization Process
38

Learn to apply a process for normalizing relations


• Steps in the normalization process are as follows:
1. Identify all the candidate keys of the relation.
2. Identify all the functional dependencies in the relation.
3. Examine the determinants of the functional dependencies. If any
determinant is not a candidate key, the relation is not well formed. In
this case:
a. Place the columns of the functional dependency in a new relation of
their own.
b. Make the determinant of the functional dependency the primary key
of the new relation.
c. Leave a copy of the determinant as a foreign key in the original
relation.
d. Create a referential integrity constraint between the original and the
new relation.
4. Repeat Step 3 until every determinant of every relation is a candidate
key.
Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.17 Sample PRESCRIPTION
39

Relation and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.18 Normalized CUSTOMER
40

and PRESCRIPTION Relations and


Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.19 Sample STU_DORM
41

Relation and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.20 Normalized STU_DORM
42

and DORM Relations and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.21 Sample EMPLOYEE
43

Relation and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.22 Normalized EMPLYEE
44

and DEPARTMENT Relations and


Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.23 Sample MEETING
45

Relation and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Figure 2.24 Normalized MEETING and
46

CLIENT Relations and Data

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Eliminating Anomalies from
47

Multivalued Dependencies
Learn to apply a process for normalizing
relations
• When modification problems are due to functional
dependencies and we then normalize relations to BCNF, we
eliminate these anomalies.
• Anomalies can also arise from another kind of dependency—
the multivalued dependency.
– A multivalued dependency occurs when a determinant is
matched with a particular set of values as seen below.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
48

Figure 2.25 Examples of Multivalued Dependencies

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
The Normal Forms (1 of 2)
49

Learn to apply the process for normalizing


relations
• First Normal Form (1NF)
– each cell has only one value, and all entries in a column are
of the same kind
• Second Normal Form (2NF)
– each table is in 1NF and all non-key attributes are
determined by the entire primary key
• Third Normal Form (3NF)
– each table is in 2NF and no non-key attributes are
determined by another non-key attribute

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
The Normal Forms (2 of 2)
50

Learn to apply the process for normalizing


relations
• Boyce Codd Normal Form (BCNF)
– each table is in 3NF and all determinants are candidate
keys
• Fourth Normal Form (4NF)
– each table is in BCNF and all multivalued dependencies
have been moved to their own table
• Fifth Normal Form (5NF)
• Domain/Key Normal Form (DK/NF)

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved
Copyright
51

This work is protected by United States copyright laws and is


provided solely for the use of instructors in teaching their
courses and assessing student learning. Dissemination or sale of
any part of this work (including on the World Wide Web) will
destroy the integrity of the work and is not permitted. The work
and materials from it should never be made available to students
except by instructors using the accompanying text in their
classes. All recipients of this work are expected to abide by these
restrictions and to honor the intended pedagogical purposes and
the needs of other instructors who rely on these materials.

Copyright © 2020, 2017, 2015 Pearson Education, Inc. All Rights Reserved

You might also like