You are on page 1of 12

CSC271 Database Systems

Relational Database Design


Anomalies

Dr. Khalid Latif


Students Course-Enrollment Data
RegNum Name Program Grade Course Completed
100 Umar MS-CS B SemWeb 24-01-2015
100 Umar MS-CS B Inf Ret 06-05-2015
140 Ali MS-EE B+ Net Sec 06-05-2015
110 Usman MS-IT A,B AdvDB, InfRet 15-02-2015
110 Usman MS-IT B Data Mining 24-01-2015
190 Akbar MS-IT ABS Data Mining
150 Fatima MS-EE B Net Sec 06-01-2015
150 Fatima MS-EE C+ Ad. Net Com 06-01-2015
110 Usman MS-IT B Data Mining 24-01-2015

Is this a rela+on?
Unique rows and atomic a6ributes

2
Students Course-Enrollment Data
RegNum Name Program Grade Course Completed
100 Umar MS-CS B SemWeb 24-01-2015
100 Umar MS-CS B Inf Ret 06-05-2015
140 Ali MS-EE B+ Net Sec 06-05-2015
110 Usman MS-IT A Adv DB 15-02-2015
110 Usman MS-IT B Data Mining 24-01-2015
190 Akbar MS-IT ABS Data Mining
150 Fatima MS-EE B Net Sec 06-01-2015
150 Fatima MS-EE C+ Ad. Net Com 06-01-2015
Is this a rela+on? Unique rows and atomic a6ributes
Whats the primary key? (RegNum, Course)
Is this rela+on Well Structured?

3
Well Structured Relation

A relation that contains minimal data


redundancy and allows users to insert,
delete, and update rows without causing
data inconsistencies
General rule of thumb: A table should
not pertain to more than one entity type.
Achieved by removing inconsistencies
(called anomalies)

4
Insertion Anomaly

Adding new rows is either


restricted or forces user to
create duplicate data.

5
Insertion Anomaly - Restriction

The primary key for the relation is the


combination of RegNum and Course
RegNum Name Program Grade Course Completed
100 Umar MS-CS B SemWeb 24-01-2015
To insert a new row, the user must supply both
values (since primary keys cannot be null)
Cant enter a new student without having the
student take a class
This is an anomaly, since the user should be
able to enter student data without supplying
course data
6
Insertion Anomaly - Duplicates

Insert a new course enrollment by an existing


student, the user must also supply student
name even if it exists in a previous enrollment
record
RegNum Name Program Grade Course Completed
100 Umar MS-CS B SemWeb 24-01-2015
100 Umar MS-CS B Inf Ret 06-05-2015

This is an anomaly, since the user should not be


asked to reenter student data which already
exists in the database

7
Deletion Anomalies

Deleting rows may cause a loss of data that


would be needed for other future rows.
Suppose that the data for a particular course for
a student is deleted from the table.

140 Ali MS-EE B+ Net Sec 06-05-2015

This may result in losing the information about


existence of the student deletion anomaly.

8
Modification Anomalies

Changing data in a row requires changes


to other rows because of duplication.
RegNum Name Program Grade Course Completed
140 Ali MS-EE B+ Net Sec 06-05-2015
150 Fatima MS-EE B Net Sec 06-01-2015
150 Fatima MS-EE C+ Ad. Net Com 06-01-2015

If Fatima changes the program, this must


be updated in both the rows of the table
otherwise the data will be inconsistent.
Can you identify another modification anomaly?

9
Checkpoint

Find insert, update, and delete anomalies in the


following relation.

Order Order Customer Customer Name Product Product Unit Ordered


ID Date ID ID Name Price Quantity
106 10.02.2016 2 Value Furniture 7 Dining Table 800 2
106 10.02.2016 2 Value Furniture 5 Bed 900 2
106 10.02.2016 2 Value Furniture 4 Writers Desk 600 1
107 15.02.2016 6 Furniture Gallery 11 4-Dr Dresser 500 3
107 15.02.2016 6 Furniture Gallery 4 Writers Desk 600 4
108 15.02.2016 2 Value Furniture 5 Bed 900 1
109 16.02.2016 7 Office Valley 8 Office Desk 500 4

10
Checkpoint

Find insert, update, and delete anomalies in the


following relation.
Order Order Customer Customer Customer Product Product Product Unit Ordered
ID Date ID Name Address ID Name Finish Price Quantity
106 10.02.2016 2 Value Furniture F10 7 Dining Table Ash 800 2
Markaz
106 10.02.2016 2 Value Furniture F10 5 Bed Oak 900 2
Markaz
106 10.02.2016 2 Value Furniture F10 4 Writers Maple 600 1
Markaz Desk
107 15.02.2016 6 Furniture Golra 11 4-Dr Dresser Oak 500 3
Gallery
107 15.02.2016 6 Furniture Golra 4 Writers Maple 600 4
Gallery Desk
108 15.02.2016 2 Value Furniture F10 5 Bed Maple 900 1
Markaz
109 16.02.2016 7 Office Valley Golra 8 Office Desk Ash 500 4

11
Why do these anomalies exist?

Because there are two themes (entity types) in


one relation. This results in data duplication and
an unnecessary dependency between the
entities.
These anomalies indicate that the relation is not
well-structured.
We should use normalization theory to divide the
relation into multiple relations.
For
example one for STUDENT core information,
another for COURSE information and yet another to
keep track of students enrollments.

12

You might also like