Professional Documents
Culture Documents
MIS710 Module 1b
Relational Model and Normalization
Arijit Sengupta
0. Intro
Database
Fundamentals
Conceptual
Modeling
Relational
Model
2. Querying
Query
Languages
Advanced
SQL
3. Applications
4. Advanced
Topics
Java DB
Applications
JDBC
Transaction
Management
Data
Mining
Normalization
Newbie
Users
Designers
Developers
Professionals
Todays Buzzwords
ISOM
Relational Model
Superkey, Candidate Key, Primary Key
and Foreign Key
Entity Integrity Rule
Referential Integrity Rule
Normalization
First, Second, Third, and Boyce-Codd
Normal Forms
Unnormalization
Relation
Tuples
ID
S1
S2
S3
S4
S5
Name
Jose
Alice
Lin
Joyce
Sunil
Age
21
18
32
20
27
Attributes
Address
Stoned Hill
BigHead
Done-Audy
Atlanta
Mare-iota
GPA
3.1
3.2
2.9
3.7
3.2
Attribute
Values
Relation: Properties
ISOM
Name
Jose' 'M.' 'Smith'
Address
3413 Main Street', 'Atlanta', GA
Attributes
ISOM
Attribute name
Attribute names are unique within a relation
Attribute domain
Set of all possible values an attribute may
take
Domain (GPA) =
Domain (name) =
Domain (DateOfBirth) =
Domain (year)
Tuples
ISOM
Name
Jose
Alice
Lin
Joyce
Sunil
Age
21
18
32
20
27
Address
Stoned Hill
BigHead
Done-Audy
Atlanta
Mare-iota
GPA
3.1
3.2
2.9
3.7
3.2
Primary Keys
ISOM
Keys - example
ISOM
Disk: (ISBN#, Artist_name, Album_name, Year, Producer, Genre, time, price)
Superkeys?
Candidate keys?
Primary key?
Primary Key
Course
201
201
NULL
Section
1
NULL
NULL
Meets
MW
TTh
MWF
Enrolled
20
25
18
Foreign Key
ISOM
Physician (ID, Name, )
Foreign Key ..
ISOM
Primary Key
Value Set
Foreign Key
Domain
How do we define
the Domain of an FK?
Domain
Can an FK have a NULL value?
What can we enforce with PKs and FKs?
ISOM
Referential Integrity
Enforcement
If an operation violates referential integrity:
Restrict
reject the operation
Cascade
try to propagate the operation to all dependent FK
values, if it is not possible, reject the operation
Creating Relations
ISOM
create table STUDENT (
ID char (11) not null primary key,
Name char(30) not null,
age int,
GPA number (2,1));
create table COURSE (
courseno char (6) not null primary key,
coursename char(30) not null,
credithours number (2,1));
create table REGISTRATION (
ID references STUDENT (ID)
on delete cascade,
CourseNum references COURSE (courseno),
primary key (ID, CourseNum) );
Name
Joseph
Joseph
Joseph
Alice
Alice
Tom
Tom
Tom
Grade
A
B
A
A
A
B
B
A
Course#
CIS800
CIS820
CIS872
CIS800
CIS872
CIS800
CIS872
CIS860
Text
b1
b2
b5
b1
b5
b1
b5
b1
Major
CIS
CIS
CIS
CS
CS
Acct
Acct
Acct
Dept
CIS
CIS
CIS
MCS
MCS
Acct
Acct
Acct
Why Normalization?
ISOM
Why Normalization?
ISOM
Benefits
contain minimum amount of redundancy
allow users to insert, delete and modify tuples
in the relation without errors or inconsistencies.
improve quality of information in the database
decrease storage space for the database
Costs
may contribute to performance problems
may require more storage in some cases
Unnormalized Relation
ISOM
COURSE
NAME
Intro CBIS
Database Mgt
Sys.Analysis
COBOL
Sys.Analysis
Intro CBIS
COBOL
Sys.Analysis
INSTR
NAME
Greene
Hong
Purao
Brown
Purao
Greene
Brown
Purao
ROOM
CREDITS GRADE
205G
311S
139S
629G
139S
205G
629G
139S
5
5
5
3
5
5
3
5
A
B
B
B
C
B
B
B
Normal Forms
ISOM
NF2
1NF
2NF
3NF
BCNF
Unnormalized Relation
Only atomic attributes
Properties of FDs
ISOM
If R.X R.Y or X Y
X is called the determinant of Y.
X may or may not be the key attribute of R.
A FD changes with its semantic meaning
Name Address?
When is X Y a FFD?
When Y is not functionally dependent on any proper subset
of X
Transitive Dependencies
ISOM
X Y and Y Z
For example:
SID Dept, SID Major,
Dept School, Major Dept
DEFINITION
A relation R is in first normal form (1NF) if and
only if all underlying domains contain atomic
values only.
Translation
To be in first normal form the table must not
contain any repeating attributes.
Implication
Are all relations in First Normal Form (1NF) ?
Example - 1NF
ISOM
StudentID
224
251
421
Relation: Student
Relation: Student-Course
StudentID
224
224
224
351
351
421
421
421
Course#
CIS20
CIS40
CIS50
CIS30
CIS50
CIS20
CIS30
CIS50
Course Title
Intro CBIS
Database Mgt
Sys.Analysis
COBOL
Sys.Analysis
Intro CBIS
COBOL
Sys.Analysis
Instrname
Greene
Hong
Purao
Brown
Purao
Greene
Brown
Purao
ROOM
205G
311S
139S
629G
139S
205G
629G
139S
StudentName
Waters
Byron
Smith
CREDITS
5
5
5
3
5
5
3
5
GRADE
A
B
B
B
C
B
B
B
Insertion Anomaly
A new course cannot be inserted in the database (relation
Student-Course) until a student registers for that course.
Update Anomaly
If the instructor of a course is changed, this fact would have
to be noted at many places in the database (many tuples of
the relation Student-Course).
Deletion Anomaly
Withdrawal of all students from an existing course (that is,
deletion of related tuples from the relation Student-Course)
will result in unwarranted removal of that course from the
database.
Anomalies in 1NF
ISOM
SID
Name
Course#
Grade
Dept
Text
DEFINITION
A relation R is in second normal form (2NF) if
and only if it is in 1NF and every nonkey attribute
is dependent on the full primary key.
Translation
A table is in second normal form if there are no
partial dependencies.
Implication
What kinds of primary keys may lead to a
violation of the Second Normal Form (2NF) ?
Bubble Chart
ISOM
CourseTitle
Instructor
Classroom
Grade
ISOM
CourseTitle
Instructor
CourseId
Classroom
Grade
Example - 2NF
ISOM
STUDENT STUDENT
ID
NAME
224 Waters
251 Byron
421 Smith
COURSE
ID
CIS20
CIS30
CIS40
CIS50
COURSE
TITLE
Intro to CIS
Java
DBMS
Systems Analysis
CREDITS
5
3
5
5
STUDENT COURSE
ID
ID
224 CIS20
224 CIS40
224 CIS50
351 CIS30
351 CIS50
421 CIS20
421 CIS30
421 CIS50
GRADE
A
B
B
B
C
B
B
B
Insertion anomaly
Information about a faculty (potential advisor) cannot be
added to the database unless a student is assigned to
him/her.
Update anomaly
If the advisors office location or phone were changed, many
tuples would need to be changed.
Deletion anomaly
If all students assigned to an advisor graduate, information
about the advisor will disappear from the database.
DEFINITION
A relation R is in third normal form (3NF) if and only if
it is in 2NF and every nonkey attribute is nontransitively dependent on the primary key.
Translation
A table is in Third Normal Form if every non-key
attribute is determined by the key, and nothing else.
Implication
How many total attributes must the relation have for a
possible violation of the Third Normal Form (3NF) ?
3NF Example
ISOM
TotalCredits
Advisor
Status
Advisor
AdvisorOffice
1.
2.
3.
4.
5.
Lossless Decomposition
ISOM
Other Dependencies
Inclusion Dependencies (Casanova 1981)
Template Dependencies (Sadri 1982)
Domain-Key Normal Form (Fagin 1981)