DBMS Session 6 Notes
DBMS Session 6 Notes
Session 6 Agenda
Anomalies
Types of Anomalies
Insertion anomaly: It is not possible to add a new class, for MTH101A , even if
faculty, schedule, room are known, unless there is a student registered for it,
because stuId is part of primary key
Update anomaly: If schedule of ART103A is updated in first record, and not in
second and third – data is inconsistent
Deletion anomaly: If record of student S1001 is deleted, information about
HST205A class is also lost
Chapter 6: Normalization and Denormalization
Normalization / Objectives
Normal Forms
Functional dependencies
Multi-valued dependencies
Join dependencies
Chapter 6: Normalization and Denormalization
Functional Dependencies
Multi-Valued Dependencies
Join Dependencies
Note: that there are many classes with the same cost.
ART103A, MTH103C = 1000
Chapter 6: Normalization and Denormalization
Table 1 Table 2
StuId classNumber classNumber Cost
S1001 ART103A ART103A 1000
S1002 HST205A HST205A 1500
S1001 MTH101B MTH101B 2000
S1004 MTH103C MTH103C 1000
S1004 ART103A CSC201A 2000
S1002 CSC201A
Chapter 6: Normalization and Denormalization
StuId Hobby
S1001 Cricket
S1001 Hockey
Chapter 6: Normalization and Denormalization
Note: 5NF is satisfied when all the tables are broken into as many tables
as possible in order to avoid redundancy.
Chapter 6: Normalization and Denormalization
F101 teaches History and Math for Semester 1 but does not teach
Math for Semester 2
The primary key is the combination of all three columns.
Assume we want to add Semester 3 but do not know who will be
teaching what subject. We cannot leave the attributes null since they
are part of the primary key
Chapter 6: Normalization and Denormalization
The basic idea behind the DKNF is to specify the normal form that
takes into account all the possible dependencies and constraints.
In other words, DKNF requires that the database contains no
constraints other than domain constraints and key constraints.
Chapter 6: Normalization and Denormalization
Denormalization
Non-Normalized Databases
OLAP systems
Used for planning and decision-making
Require historical data, not just current data
Updates are rare; optimized for reading
Data stored in denormalized form
Object-based systems
Needed for advanced applications
Objects are not normalized
Chapter 6: Normalization and Denormalization
Normalization
Step 6.1 - Begin with the list of the tables that the entities and
relationships from the E-R diagram mapped to naturally, from
the sample project section at the end of chapter 4.
For each table on the list, identify functional dependencies and
normalize the relation to Boyce-Codd Normal Form (BCNF). Then
decide whether the resulting tables should be implemented in that
form. If not, explain why.
Chapter 6: Team Assignment Review
Normalization (Con’t)
Step 6.3 - For each table, write the table name and write out the
names, data types, and sizes of all the data items.
Identify any constraints, using the conventions of the DBMS you will use for
implementation.
Step 6.4 - Write and execute SQL statements to create all the tables
needed to implement the design
Step 6.5 - Write and execute SQL statements to create indexes for
foreign keys and any other columns that will be used most often for
queries. (primary key, foreign key, check constraints)
Note: Step 6.4 and Step 6.5 can be combined.
Chapter 6: Team Assignment Review
Normalization (Con’t)
Step 6.6 - Write and execute SQL statements to insert at least five
records in each table, preserving all constraints.
Put in enough data to demonstrate how the database will function.
Step 6.7 - Write and execute SQL statements that will process five
non-routine requests for information from the database just
created.
Note: Make sure to write 5 different SQL statements. Also use a
WHERE clause or join tables.
Do not write select * from <table_name>;
Chapter 6: Team Assignment Review
Normalization (Con’t)
Step 6.8 - Write and execute SQL statements to create at least one
trigger.