comp 2216 fortran programming · 2015-02-02 · 8 normal forms •if you can design your database...
TRANSCRIPT
1
Database Concepts and Applications
COMP 244
Normal Forms
2
Normalization
• Normalization: The process of
decomposing unsatisfactory "bad"
relations by breaking up their attributes
into smaller relations.
• Normalization is carried out in practice
so that the resulting designs are of
high quality and meet the desirable
properties.
3
Essence of Normalization
• Every normalized relation should have a single theme.
• Any relation with two or more themes should be split into two or more relations each having a single theme.
– We continue doing this for every relation with modification anomalies.
– Splitting relations into two or more new relations could result in creating Referential Integrity Constraints.
4
Referential Integrity Constraints
How to
record the
fact that
Student
300
participates
in Scuba
Diving?
Activity SID
Football 100
Swimming 150
Squash 175
Swimming 200
Fee Activity
200 Football
50 Swimming
50 Squash
STUDENT-ACTIVITY ACTIVITY-COST
5
Referential Integrity Constraints
Activity SID
Football 100
Swimming 150
Squash 175
Swimming 200
Scuba Diving 300
Fee Activity
200 Football
50 Swimming
50 Squash
No corresponding
row for Scuba
Diving in this table.
STUDENT-ACTIVITY ACTIVITY-COST
• It is the user’s requirements
• We have to record that fact in the design
Who should decide
if to allow adding
Scuba Diving in
STUDENT-ACTIVITY
without adding a
corresponding row
in ACTIVITY-COST?
6
Normal Forms
• The set of rules that govern the ways in which attributes can be arranged are called Normal Forms.
• Normal forms provide an increasingly more stringent set of design rules that relations must meet.
• The least stringent is the first normal form (called 1NF) and the most stringent is the domain/key normal form (called DK/NF).
• The normal forms are nested in a way to indicate that if a relation is in an inner normal form, then it meets the normal forms outside it.
7
Normal Forms
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
Fourth Normal Form (4NF)
Fifth Normal Form (5NF)
Domain/Key Normal Form (DK/NF)
8
Normal Forms
• If you can design your database to meet the 3NF, then you will have avoided the majority of database design problems.
• The Boyce-Codd and fourth normal forms were created to handle special situations that are less frequent.
• The fifth and domain/key normal forms are more of theoretical interest and are not considered as practical design objectives.
• Any form in the DK/NF normal form is guaranteed to be free of all modification anomalies.
9
What is a Relation?
• A relation is a two-dimensional table with rows (records) and columns (fields).
• For a table to be a relation, it must meet certain restrictions: – The cells of the table must be single valued (i.e.,
no repeating groups or arrays).
– All the entries of a column are of the same type.
– Each column must have a unique name.
– Order of columns is insignificant.
– No two rows may be identical.
– Order of rows is insignificant.
10
First Normal Form
• Any table that meets the definition of a relation is said to be in first normal form.
• Relations in first normal form suffer from modification anomalies.
• When we eliminate modification anomalies, the relation becomes in a different form (depending on which anomaly was removed).
11
Borrower-
Name
Borrower-
Phone
BookTitle Author-
Name
Loan-
Date
Return-
Date
Fee
Nasra 993 The best two
recipes
Najma 08/05/2003 19/07/2003 0.300
Khalid 831 Cars at light speed Ahmed 15/08/2003 23/08/2003
Ihsan 359 The best two
recipes
Najma 01/09/2003 07/09/2003
Nasra 993 How to sleep in
class?
Naser 12/10/2003
Fatma 818 Cars at light speed Ahmed 12/10/2003 27/10/2003 0.250
The cells of the table must be single valued (i.e., no repeating groups or arrays). All the entries of a column are of the same
type. Each column must have a unique name. Order of columns is insignificant. No two rows may be identical. Order of rows is insignificant.
Is this table in first
normal form?
12
How to put this table in first normal form?
Course
Code Course Name Section First Name Last Name Days Time Room Capacity
COMP101 Computer Skills 1 QASIM AL OBAIDAT
Sat 01:00 PM-01:50 PM
32-8 60 Sun 01:00 PM-01:50 PM
Mon 01:00 PM-01:50 PM
Tue 01:00 PM-01:50 PM
COMP101 Computer Skills 2 Zahir Al Abri
Sat 10:00 AM-10:50 AM
29A Not more than 40 Sun 10:00 AM-10:50 AM
Mon 10:00 AM-10:50 AM
Tue 10:00 AM-10:50 AM
COMP101L Computer Skills Lab 1 Zahir Al Abri Sun 08:00 AM-09:50 AM
8-6 30 Tue 08:00 AM-09:50 AM
COMP101L Computer Skills Lab 2 Naeem Al-Shukaili Sat 08:00 AM-09:50 AM
8-4 30 Mon 08:00 AM-09:50 AM
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 AM-09:50 AM
8-1 30 Tue 08:00 AM-09:50 AM
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 AM-11:50 AM
8-5 Reserved Mon 10:00 AM-11:50 AM
Is this table in first normal form?
This column does not contain values of the
same type. The solution is to add a new
column for the remarks.
These two columns contain multiple values for
the same record. The solution is to split each
record into multiple records.
13
Course Code Course Name Section First Name Last Name Day Time Room Capacity Remark
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sat 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sun 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Mon 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Tue 13:00 - 13:50 32-8 60
COMP101 Computer Skills 2 Zahir Al Abri Sat 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Sun 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Mon 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Tue 10:00 - 10:50 29A Not more than 40
COMP101L Computer Skills Lab 1 Zahir Al Abri Sat 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 1 Zahir Al Abri Mon 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Sat 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Mon 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Tue 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 - 11:50 8-5 Reserved
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Mon 10:00 - 11:50 8-5 Reserved
Solution
14
Second Normal Form
• A relation is in second normal form if
all of its non-key attributes are
dependent on all of the key.
– Second normal form is of concern in
relations that have composite keys.
An implication of this rule is that if a
relation has a single attribute as its
key, then it is automatically in its
second normal form.
15
Second Normal Form - Example Borrower-
Name
Borrower-
Phone
BookTitle Author-
Name
Loan-
Date
Return-
Date
Fee
Nasra 993 The best two
recipes
Najma 08/05/2003 19/07/2003 0.300
Khalid 831 Cars at light speed Ahmed 15/08/2003 23/08/2003
Ihsan 359 The best two
recipes
Najma 01/09/2003 07/09/2003
Nasra 993 How to sleep in
class?
Naser 12/10/2003
Fatma 818 Cars at light speed Ahmed 12/10/2003 27/10/2003 0.250
• Functional Dependencies: • BorrowerName BorrowerPhone
• BookTitle AuthorName
• (BorrowerName, BookTitle, LoanDate) ReturnDate
• (BorrowerName, BookTitle, LoanDate) Fee
How to put this table in
second normal form?
16
Solution
• From the functional dependencies, we
conclude that the relation has three
different themes:
– Borrowers information
– We conclude this from the functional
dependency:
• BorrowerName BorrowerPhone
17
Solution
• From the functional dependencies, we
conclude that the relation has three
different themes:
– Books information
– We conclude this from the function
dependency:
• BookTitle AuthorName
18
Solution
• From the functional dependencies, we
conclude that the relation has three
different themes:
– Book Loans information
– We conclude this from the functional
dependencies:
• (BorrowerName, BookTitle, LoanDate)
ReturnDate
• (BorrowerName, BookTitle, LoanDate) Fee
19
Solution
• This tells us that we need to split the original relation into 3 smaller relations:
• Each relation will hold information about only one theme:
– Borrowers: Holds information about borrowers.
– Books: Holds information about books.
– Loans: Holds information about book loans.
20
Solution
BorrowerName BorrowerPhone
Nasra 993
Khalid 831
Ihsan 359
Fatma 818
Borrowers
Is this relation in second
normal form?
21
Solution
BookTitle AuthorName
The best two recipes Najma
Cars at light speed Ahmed
How to sleep in class? Naser
Books
Is this relation in second
normal form?
22
Solution
Borrower-
Name
BookTitle LoanDate Return-
Date
Fee
Nasra The best two recipes 08/05/2003 19/07/2003 0.300
Khalid Cars at light speed 15/08/2003 23/08/2003
Ihsan The best two recipes 01/09/2003 07/09/2003
Nasra How to sleep in class? 12/10/2003
Fatma Cars at light speed 12/10/2003 27/10/2003 0.250
Loans
Is this relation in second
normal form?
23
Course Code Course Name Section First Name Last Name Day Time Room Capacity Remark
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sat 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sun 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Mon 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Tue 13:00 - 13:50 32-8 60
COMP101 Computer Skills 2 Zahir Al Abri Sat 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Sun 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Mon 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Tue 10:00 - 10:50 29A Not more than 40
COMP101L Computer Skills Lab 1 Zahir Al Abri Sat 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 1 Zahir Al Abri Mon 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Sat 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Mon 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Tue 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 - 11:50 8-5 Reserved
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Mon 10:00 - 11:50 8-5 Reserved
How to put this table in 2NF?
24
Course Code Course Name Section First Name Last Name Day Time Room Capacity Remark
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sat 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sun 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Mon 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Tue 13:00 - 13:50 32-8 60
COMP101 Computer Skills 2 Zahir Al Abri Sat 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Sun 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Mon 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Tue 10:00 - 10:50 29A Not more than 40
COMP101L Computer Skills Lab 1 Zahir Al Abri Sat 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 1 Zahir Al Abri Mon 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Sat 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Mon 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Tue 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 - 11:50 8-5 Reserved
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Mon 10:00 - 11:50 8-5 Reserved
Step 1 – Identify Key
25
Course Code Course Name Section First Name Last Name Day Time Room Capacity Remark
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sat 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sun 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Mon 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Tue 13:00 - 13:50 32-8 60
COMP101 Computer Skills 2 Zahir Al Abri Sat 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Sun 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Mon 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Tue 10:00 - 10:50 29A Not more than 40
COMP101L Computer Skills Lab 1 Zahir Al Abri Sat 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 1 Zahir Al Abri Mon 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Sat 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Mon 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Tue 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 - 11:50 8-5 Reserved
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Mon 10:00 - 11:50 8-5 Reserved
Step 1 – Identify Key
26
Course Code Course Name Section First Name Last Name Day Time Room Capacity Remark
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sat 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Sun 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Mon 13:00 - 13:50 32-8 60
COMP101 Computer Skills 1 QASIM AL OBAIDAT Tue 13:00 - 13:50 32-8 60
COMP101 Computer Skills 2 Zahir Al Abri Sat 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Sun 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Mon 10:00 - 10:50 29A Not more than 40
COMP101 Computer Skills 2 Zahir Al Abri Tue 10:00 - 10:50 29A Not more than 40
COMP101L Computer Skills Lab 1 Zahir Al Abri Sat 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 1 Zahir Al Abri Mon 08:00 - 09:50 8-5 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Sat 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 2 Alaa Aljanaby Mon 08:00 - 09:50 8-4 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Sun 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 3 Naeem Al-Shukaili Tue 08:00 - 09:50 8-1 30
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Sat 10:00 - 11:50 8-5 Reserved
COMP101L Computer Skills Lab 4 Naeem Al-Shukaili Mon 10:00 - 11:50 8-5 Reserved
Step 2 – List All FDs
27
Step 2 – List All FDs
• CourseCode CourseName
• FirstName LastName
• (CourseCode, Section) CourseName,
FirstName, LastName, Time, Room
• (CourseCode, Section, Day)
CourseName, FirstName, LastName,
Time, Room, Capacity, Remark
28
Step 3 – Split Relation into Sub
Relations
• Themes:
– Courses
– Instructors
– Course-Sections
– Section-Capacities
29
Code Name
COMP101 Computer Skills
COMP101L Computer Skills Lab
COMP151 Introduction to Algorithms
COMP222 Object-Oriented Programming
Courses
Is this relation in second
normal form?
30
ID FirstName LastName
100 Qasem Al Obeidat
101 Zahir Al Abri
102 Neem Al-Shukaili
103 Alaa Aljanaby
Instructors
Is this relation in second
normal form?
31
Course Code Section Time InstructorID Room
COMP101 1 13:00 - 13:50 100 32-8
COMP101 2 10:00 - 10:50 101 29A
COMP101L 1 08:00 - 09:50 101 8-5
COMP101L 2 08:00 - 09:50 103 8-4
COMP101L 3 08:00 - 09:50 102 8-1
COMP101L 4 10:00 - 11:50 102 8-5
Course-Sections
Is this relation in second
normal form?
32
Course Code Section Day Capacity Remark
COMP101 1 Sat 60
COMP101 1 Sun 60
COMP101 1 Mon 60
COMP101 1 Tue 60
COMP101 2 Sat Not more than 40
COMP101 2 Sun Not more than 40
COMP101 2 Mon Not more than 40
COMP101 2 Tue Not more than 40
COMP101L 1 Sat 30
COMP101L 1 Mon 30
COMP101L 2 Sat 30
COMP101L 2 Mon 30
COMP101L 3 Sun 30
COMP101L 3 Tue 30
COMP101L 4 Sat Reserved
COMP101L 4 Mon Reserved
Section-Capacities
4
Is this relation in second
normal form?
33
Third Normal Form
• Second normal form can still suffer
from insertion and deletion anomalies.
• A relation is in third normal form if it is
in second normal form and has no
transitive dependencies.
– Transitive dependency occurs when:
• Key Attribute N
• Attribute N Attribute M
• This means that indirectly (Key Attribute M)
34
Example
Fee Activity SID
200 Football 100
50 Swimming 150
60 Squash 175
50 Swimming 200
ACTIVITY
• Functional
Dependencies:
• SID Activity
• Activity Fee
• SID Fee
(transitive
dependency) • Suffers from:
– Insertion anomaly
– Deletion anomaly
Each student is allowed to register for only one activity.
35
Solution
• The problem with this relation is that it
records information about two themes:
– Activities that students can participate in.
– Cost of each activity.
• The solution is to split the relation into
two relations: – STUDENT-ACTIVITY
– ACTIVITY-COST
36
Solution
Activity SID
Football 100
Swimming 150
Squash 175
Swimming 200
STUDENT-ACTIVITY
Is this relation in second normal form?
Is this relation in third normal form?
37
Solution
Fee Activity
200 Football
50 Swimming
60 Squash
ACTIVITY-COST
Is this relation in second normal form?
Is this relation in third normal form?
38
Boyce-Codd Normal Form
• A relation is in Boyce-Codd normal form if the relation is in third normal form and every determinant is a candidate key.
– Candidate keys are collections of two or more attributes each of which can be used as a key.
– The candidate key that will be selected as the key for the relation is called the primary key.
39
Boyce-Codd Normal Form
SID Major AdvisorName
100 Math Naser
150 Psychology Wafa
200 Math Moza
250 Math Naser
300 Psychology Ishaq
300 Math Moza
ADVISOR
• For this relation:
– A student can have one or more majors
– A major can have several faculty members as advisors
– Each faculty member advises in only one major
40
Boyce-Codd Normal Form
SID Major AdvisorName
100 Math Naser
150 Psychology Wafa
200 Math Moza
250 Math Naser
300 Psychology Ishaq
300 Math Moza
ADVISOR
• Candidate Keys:
– (SID, Major)
– (SID, AdvisorName)
• Functional Dependencies:
• (SID, Major) AdvisorName
• (SID, AdvisorName) Major
• AdvisorName Major
• Suffers from:
– Deletion anomaly
– Insertion anomaly
This is a determinant
that is not a candidate
key.
41
Boyce-Codd Normal Form
Major Advisor-Name
Math Naser
Psychology Wafa
Math Moza
Psychology Ishaq
ADVISOR-SUBJECT
SID Advisor-
Name
100 Naser
150 Wafa
200 Moza
250 Naser
300 Ishaq
300 Moza
STUDENT-ADVISOR
42
Boyce-Codd Normal Form
• A relation in Boyce-Codd normal form
has no anomalies in regards to
functional dependencies.
– It was discovered that anomalies can arise
from situations other than functional
dependencies.
43
Fourth Normal Form
SID Major Activity
100 Math Swimming
100 Accounting Tennis
150 Math Jogging
STUDENT
• Consider the following situation: – A student can enroll in one or more majors
– A student can participate in one or more activities
– Major and Activity are independent of each other
• This relation is misleading: – One might think that student
100 engages in Swimming when he is majoring in Math and engages in Tennis when he is majoring in Accounting.
• Such interpretation is not logical since the student is majoring in Math and Accounting at the same time.
44
Fourth Normal Form
SID Major Activity
100 Math Swimming
100 Accounting Swimming
100 Math Tennis
100 Accounting Tennis
100 Math Skiing
100 Accounting Skiing
150 Math Jogging
STUDENT
• Proposed Solution:
• Suffers from:
– Update anomaly (too much
updating needs to be done to
make a simple change in the
data)
If a student adds a
major, we must add a
tuple for each of the
student activities.
Similarly, if a student
adds an activity, we
must add a tuple for
each of the student
majors.
If a student drops
from one major, then
we must delete all
records that have
that major for this
student.
• This relation contains
Multi-Valued Dependencies:
• SID Major
• SID Activity
• Multi-Valued Dependencies: lead to
modification anomalies
45
Fourth Normal Form
• In general, multi-valued dependency exists
when a relation has at least three attributes,
two of them are multi-valued, and their
values depend on only the third attribute.
• If a relation has attributes A, B, and C, then a
multi-valued dependency exists if:
– A B (A determines multiple values of B)
– A C (A determines multiple values of C)
– B and C are independent of each other
46
Fourth Normal Form
SID Major
100 Math
100 Accounting
150 Math
STUDENT-MAJOR
SID Activity
100 Skiing
100 Swimming
100 Tennis
150 Jogging
STUDENT-ACTIVITY
• Solution:
– Create two relations, each one storing data
for only one of the multi-valued attributes.
• A relation is in Fourth normal form if it is in
BCNF and has no multi-valued dependencies.
47
Fifth Normal Form
• Concern dependencies that are rather
obscure.
• It has to do with relations that can be
divided into sub-relations, but cannot
be reconstructed.
• The condition under which this
situation arises has no clear, intuitive
meaning.
48
Domain/Key Normal Form
• Was published in 1981 by R. Fagin.
• It guarantees that any relation in DK/NF
has no modification anomalies.
• It also guarantees that any relation
having no modification anomalies is in
DK/NF.
– Implies no higher normal form is needed.
49
Domain/Key Normal Form
• Involves only the concepts of key and domain which are supported by most DBMS products. – A key is a group of one or more attributes that
uniquely identify a row.
– A domain is a description of the attribute’s allowed values.
• Physical description: The set of values the attribute can have.
• Logical (or semantic) description: The meaning of the attribute.
– A constraint is a restriction, or rule, that governs which data can be stored in a relation.
50
Domain/Key Normal Form
• Examples of valid constraints:
– Edit rules
– Intra-relation constraints
• Constraints that govern relationships among
attributes of the same relation
– Inter-relation constraints
• Constraints that govern relationships among
attributes of different relations
51
Domain/Key Normal Form
• Examples of excluded constraints:
– Constraints pertaining to changes in data
values
– Time-dependent constrains
• “Salary of current period can never be less
than salary of the prior period”.
52
Domain/Key Normal Form
• There is no known algorithm for
converting a relation to DK/NF.
– It is not even known which relations can
be converted to DK/NF.
• Finding or designing DK/NF relations is more
of an art than a science.
53
Domain/Key Normal Form
• Example
– STUDENT (SID, GradeLevel, Building, FEE)
• Key: SID
• Constraints: Building Fee
• SID must not begin with digit 1
– Domain Definitions:
• SID CDDD where C is decimal digit
not = 1; D = decimal digit
• GradeLevel (“FR”, “SO”, “JR”, “GR”)
• Building CHAR(4)
• FEE DEC(4)
54
Domain/Key Normal Form
• Example (cont.)
– Relations and Key Definitions
• STUDENT (SID, GradeLevel, Building)
– Key: SID
• BUILDING-FEE (Building, Fee)
– Key: Building
55
Design Trade-Offs
• It is sometimes better to leave a relation in its un-normalized form because of simplicity and efficiency.
• Example: – CUSTOMER (CustomerNumber, CustomerName,
City, State, Zipcode) • CustomerNumber can be used as the key
• Zipcode (City, State)
– Possible Normalized Solution: • CUSTOMER (CustomerNumber, CustomerName,
Zipcode)
• CODE (Zipcode, City, State)
56
Design Trade-Offs
• There are sometimes more than one
normalized solution to the same un-
normalized relation.
• Example:
– COLLEGE (CollegeName, Dean,
AssistantDean)
• Each college can have from one to three
assistant deans
• (CollegeName, AssistantDean) is the key
57
Design Trade-Offs
• Possible Normalized Solutions:
– Solution 1:
• DEAN (CollegeName, Dean)
• ASSITANT-DEAN (CollegeName, AssistantDean)
– Solution 2:
• COLLEGE (CollegeName, Dean, AssistantDean1,
AssistantDean2, AssistantDean3)
• CollegeName is the key
• Problem in searching (e.g., searching for all assistant
deans with a specific name)