0% found this document useful (0 votes)
11 views25 pages

5ER Keysand Normalization

Uploaded by

birungiderick887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

5ER Keysand Normalization

Uploaded by

birungiderick887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ER Model: Keys

• A Key can be a single attribute or a group of


attributes, where the combination may act as
a key.
• Primary Key
• Composite key
• Foreign Key
• Candidate Key
• Super Key
Examples - Primary Key

Primary Key for this table

I
studentid name age phone

19-11-2022 2
Composite Key

• Key that consists of two or more attributes


that uniquely identify any record in a table is
called Composite key.
Composite Key

X
studentid subject_id marks exo mname

Score Table - To save scores of the student for


various subjects.
Examples - Primary Key
OrderLine

-1
■ PartNum NumOrdered Quoted Price

21608 AT94 11 $2195


21610 OR93 1 $495.00
21610 DWU 1 3399.99
21613 KL62 4 3329.95

21614 K'1X)3 2 $595.00


21617 BV06 2 3794.95
21617 CE>52 4 3150.00

2161? TYR93 1 $495.00


21623 KV29 2 31,290.00

Ordernum and Partnum makes up the primary key


Of the OrderLine table. This is what is known as a Composite
Primary key, that is, primary key that is made up of more than
19-11-2022
one field.
4
Candidate Key
• Candidate keys are defined as the minimal set of fields which
can uniquely identify each record in a table. It is an attribute
or a set of attributes that can act as a Primary Key for a table
to uniquely identify each record in that table. There can be
more than one candidate key.
• In our example, student_id and phone both are candidate
keys for table Student.
• A candidate key can never be NULL or empty. And its value
should be unique.
• There can be more than one candidate keys for a table.
• A candidate key can be a combination of more than one
columns(attributes).
Stud ID Roll No First Name LastName Emai
1 11Tom Price abcOomail.com
2 2Nick Wright xvzOamail.com
13Dana mnoOvahoo.com
1

Natan
t _/

primari/i
Super Key
• Super Key is defined as a set of attributes within a
table that can uniquely identify each record within a
table. Super Key is a superset of Candidate key.

• student_id, (student_id, name), phone etc.

student_id name phone age


1 Akon 9876723452 17
2 Akon 9991165674 19
3 Bkon 7898756543 18
4 Ckon 8987867898 19
5 Dkon 9990080080 17
Employee (
Employee ID,
FullName,
SSN, DeptID
)
Normalization of Database
Normalization
• Database Normalization is a technique of organizing
the data in the database.
• Normalization is a systematic approach of
decomposing tables to eliminate data
redundancy(repetition) and undesirable
characteristics like Insertion, Update and Deletion
Anamolies.
Reasons for Normalization

There are three main reasons to normalize a


database.
• Minimize duplicate data
• Minimize or avoid data modification issues
• Simplify queries
SalesStaff
EmplayealD Salesperson SalesCffice Off iceN umber Custom e rl Customers Customs r3

1003 Mary Smith Chicago [312-555-1212 Ford GM


1004 John Hunt New York 212-555-1212 P Dell HP Apple
1005 Martin Hap Chicago 312-555 1212 Boeing

This table serves many purposes


including:
— Identifying the organization's salespeople
— Listing the sales offices and phone numbers
— Associating a salesperson with an sales
office
— Showing each salesperson's customers
Data Duplication and
Modification Anomalies

Ref: SalesOffice and OfficeNumber

Duplicated information presents two


problems:

- It increases storage and decrease performance.


— It becomes more difficult to maintain data
changes.
Insert Anomaly

Employee ID Salesperson SalesOffice OfficeNumber Customerl Customer Customers


1003 Mary Smith Chicago 312-555-1212 Ford GM
1004 John Hunt New York 212-555-1212 Dell HP Apple
1005 Martin Hap Chicago 312-555-1212 Boeing
?7? ??? Atlanta 312-555-1212
Update Anomaly

EmployeelD Salesperson SalesOffice OfficeNumber Custom er 1 Customer 2 Customer


1003 Mary Smith Chicago 312-555-1212 Ford GM
1004 John Hunt New York 212-555-1212 Dell HP Apple
1005 Martin Hap Chicago 312-555-1212 Boeing

The same information is recorded in multiple rows.


Deletion Anomaly

EmployealD Sal&sPerson SalesOfflce Office Number Customerl Cu£tcmer2 Customer


1003 Mary Smith Chicago 312-5554212 Ford GM
John Hunt NBW York 2U-S5542U W Anmn ~r rTW

1005 Martin Hap Chicago 312-555-1212 Boeing

Deletion of a row can cause more than one set of facts to be removed
Search and Sort Issues

SELECT SalesOffice
FROM SalesStaff
WHERE Customer1 = ‘Ford' OR
Customer2 = ‘Ford' OR
Customer3 = ‘Ford'
First Normal Form (1NF)

For a table to be in the First Normal Form, it should


follow the following 4 rules:
- It should only have single(atomic) valued
attributes/columns.
- Values stored in a column should be of the same domain
- All the columns in a table should have unique names.
-A Key column to bring uniqueness for all the rows in the
table
- It should not contain repeated columns.
roll_no name subject
101 Akon OS, CN
103 Ckon Java
102 Bkon C, C++

we have stored the subject names in a single column

As per the 1st Normal form each column must contain atomic value

roll_no name subject


101 Akon OS
101 Akon CN
103 Ckon Java
102 Bkon C

102 Bkon C++


Second Normal Form (2NF)

For a table to be in the Second Normal


Form,
— It should be in the First Normal form.
— And, it should not have Partial Dependency.
What is Dependency?

student_id name reg_no branch address


10 Akon 07-WY CSE Kampala
11 Akon 08-WY IT Jinja

student_id and every other column depends on it, or can be fetched using it.
What is Partial Dependency?
student_id name reg_no Course address
10 Akon 07-WY CSE Kampala
11 Akon 08-WY IT Jinja
Together, student_id + subject_id forms a Compoiste Key

subject_id subject_name
1 Java

2 C++
3 Php

score_id student_id subject_id marks teacher


70
1 10 1 Java
Teacher
2 10 2 75 C++ Teacher
3 Java
11 1 80
Teacher
What is Partial Dependency?
subject_id subject_name teacher
1 Java Java Teacher
2 C++ C++ Teacher
3 Php Php Teacher

score_id student_id subject_id marks


1 10 1 70

2 10 2 75
3 11 1 80
Third Normal Form (3NF)

A table is said to be in the Third Normal Form


when,
— It is in the Second Normal form.
— And, it doesn't have Transitive Dependency.

When a non-prime attribute depends on other non-prime attributes


rather than depending upon the prime attributes or primary key.
score_id student_id subject_id marks exam_name total_marks
Total marks depends on exam name as with exam type the total score

subject_id
exam name is dependent on both student_id and
score id student id subject id marks exam id

The new Exam table

exam_id exam_name total_marks


1 Workshop 200
2 Mains 70
3 Practicals 30

You might also like