Upload
sarahi-rumrill
View
221
Download
0
Tags:
Embed Size (px)
Citation preview
Team Dosen UMN
Normalization
Connolly BookChapter 14-15
Team Dosen UMN
Normalization
• What is Normalization?– Normalization is a technique for producing a set of relations with
desirable properties, given the data requirements of an enterprise.
• The purpose of Normalization is to make a suitable set of relations to support data requirements of an enterprise.
• What is suitable set of relations?– Minimum redundancy– Attributes in a relation must have functional dependency– Minimum number of attribute
Team Dosen UMN
Redundancy
• Redundancy in database happens when we copy the primary keys from a parent/strong entity to child/weak entity.
• If we copy more than the primary key, redundancy will make problems called update anomalies.
• Update anomalies consist of – Insertion anomalies.– Deletion anomalies.– and modification anomalies.
Team Dosen UMN
Insertion Anomalies
StudentsProdi
• Two types of insertion anomalies:• Insert a relation must include the detail of other information
Example: To insert Students data, we need the detail of Prodi• Null is not allowable when inserting a relation
Example: To insert Prodi, we need to insert Student Data first as Student Data is not null
NIM Name Address Prodi Kaprodi
001 Aldo Emerald C1 Serpong TI Jacky
002 Bernard Crystal B1 Serpong SI Wayan
003 Cameron Aqua Marine T1 Serpong TI Jacky
004 Demi Illago R1 Serpong SI Wayan
005 Emma Crystal B2 Serpong SI Wayan
Prodi KaprodiTI JackySI Wayan
Prodi
Team Dosen UMN
Deletion Anomalies
StudentsProdi
• When we delete a tuple of a relation, the other information is also lost.
• Example: When we delete student=003, information about Prodi is also lost.
NIM Name Address Prodi Kaprodi
001 Aldo Emerald C1 Serpong TI Jacky
002 Bernard Crystal B1 Serpong SI Wayan
003 Cameron Aqua Marine T1 Serpong TI Jacky
004 Demi Illago R1 Serpong SI Wayan
005 Emma Crystal B2 Serpong SI Wayan
Team Dosen UMN
Modification Anomalies
StudentsProdi
• When we try to update a value of an attribute, we need to update all tuples at the same attribute. Otherwise, the relation becomes inconsistency
• Example when we need to change the Kaprodi from Wayan to become Made, we need to change all Kaprodi=Wayan
NIM Name Address Prodi Kaprodi
001 Aldo Emerald C1 Serpong TI Jacky
002 Bernard Crystal B1 Serpong SI Wayan
003 Cameron Aqua Marine T1 Serpong TI Jacky
004 Demi Illago R1 Serpong SI Wayan
005 Emma Crystal B2 Serpong SI Wayan
Team Dosen UMN
Functional Dependencies
• Functional Dependency describes the relationship between attributes in relation.
• If A and B are attributes of a relation R, B is functionally dependent on A (denoted AB) if each value of A is associated with exactly one value of B.
• We can say A functionally determines B.
• Functional Dependencies can also include a set of attributes.• If A,B,C, and D are attributes of a relation R, (C,D) is functionally
dependent on (A,B), denoted (A,B)(C,D) if each value of (A,B) is associated with exactly one value of (C,D)
Team Dosen UMN
Determinant and not determinant
• Determinant refers to the attribute, or group of attributes, on the left hand side of the arrow of a functional dependencies. If AB, the A is the Determinant.
• From determinant to another attribute, the relationship must be 1:1 since it must be associated wit exactly one value of that attribute.
• Example we can determine Name, Address, City from its NIM. NIM is the determinant. Relationship from NIM to Name is one to one. NIMName.
• City does not functionally determine NIM as the relationship from City to NIM is one to many (Tangerang has more than one NIMs). City NIM
x
NIM Name Address City
001 Aldo Emerald C1 Serpong Tangerang
002 Bernard Crystal B1 Jakarta
003 Cameron Aqua Marine T1 Serpong Tangerang
004 Demi Illago R1 Serpong Tangerang
005 Emma Crystal B2 Serpong Tangerang
Team Dosen UMN
Type of Functional Dependency
• There are two types of functional dependency, which are full functional dependency and partial dependency.
• Full functional dependency indicates that if A,B, and C are attributes of a relation, C is fully functionally dependent on (A,B) if C functionally dependent on (A,B) but not on A and not on B.
(A,B) C but AC and BC.
• Partial dependency indicates that if A,B, and C are attributes of a relation, C is partial dependent on combination of A and B, denoted (A,B), if C functionally dependent on (A,B) and C also functionally dependent on any A or B.
(A,B) C but AC or BC.
• If A is a single attribute and AC then C full functional dependency on A because we can’t break down A into other attributes.
x x
Team Dosen UMN
Example of Functional Dependencies
NIM Name Address City Prodi Kaprodi
001 Aldo Emerald C1 Serpong Tangerang TI Jacky
002 Bernard Crystal B1 Jakarta SI Wayan
006 Cameron Student Dormitory Tangerang TI Jacky
007 John Student Dormitory Tangerang SI Wayan
008 John Crystal B2 Serpong Tangerang SI Wayan
• Combination of NIM and Name determines the Prodi. Thus, Prodi functionally dependent on (NIM,Name) noted (NIM,Name)Prodi.However, NIM also determines Prodi. Thus, NIMProdi. In conclusion, Prodi has partial dependency on (NIM, Name).
• Prodi has a full functional dependency on combination of Name and Address as Not any of Name or Address determines Prodi but (Name,Address)Prodi.
• Prodi has full functional dependency on NIM.
Team Dosen UMN
Transitive Dependency
• Transitive dependency is a condition where A, B, and C are attributes of a relation R such that AB and BC, then C is transitive dependency on A via B or AC.
NIM Name Address City Prodi Kaprodi
001 Aldo Emerald C1 Serpong Tangerang TI Jacky
002 Bernard Crystal B1 Jakarta SI Wayan
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky
004 Demi Illago R1 Serpong Tangerang SI Wayan
005 Emma Crystal B2 Serpong Tangerang SI Wayan
• Example NIMProdi and ProdiKaprodi then NIMKaprodi.
Team Dosen UMN
Identifying Primary Key Using Functional Dependencies
• The main purpose of functional dependencies is to specify a set candidate key.• From those candidate keys, we can identify one primary key.
NIM Name Address City Prodi Kaprodi
001 Aldo Emerald C1 Serpong Tangerang TI Jacky
002 Bernard Crystal B1 Jakarta SI Wayan
003 CameronAqua Marine T1 Serpong Tangerang TI Jacky
004 Demi Illago R1 Serpong Tangerang SI Wayan
005 Emma Crystal B2 Serpong Tangerang SI Wayan
• Four functional dependencies:– NIM Name, Address, City, Prodi and Kaprodi– ProdiKaprodi– KaprodiProdi– (Name, Addres, City)NIM
• All attributes that are not part of primary key if functionally dependent on the key. As all attributes functionally dependent on NIM, then NIM is the primary key.
• NIM is chosen rather than (Name, Addres, City) as it more atomic.• Prodi and Kaprodi are not candidate keys as their relationship to other attributes are 1:*
StudentProdi
Team Dosen UMN
Relationship between the normal forms
Team Dosen UMN
Un-normalized Form (UNF)
• Definition: a table that contains one or more repeating groups.• Repeating group refers to an attribute or a set of attribute in a table which occurs with
multiple values for a single occurrences of nominated key attributes for that table.• Key attribute is attribute(s) that uniquely identify each row within the un-normalized table.
NIM Name Address City Prodi Kaprodi CourseCode CourseName Lecturerid LecturerName001 Aldo Emerald C1 Serpong Tangerang TI Jacky TI403 Database System L001 Aryl TI405 Oracle SQL L002 Mayya TI407 Cisco L003 Tarrie002 Bernard Crystal B1 Jakarta SI Wayan TI403 Database System L001 Aryl SI401 Data Analysist L004 Anank TI407 Cisco L003 Tarrie
003 CameronAqua Marine T1 Serpong Tangerang TI Jacky TI403 Database System L001 Aryl
TI405 Oracle SQL L002 Mayya TI407 Cisco L003 Tarrie004 Demi Illago R1 Serpong Tangerang SI Wayan TI403 Database System L001 Aryl SI401 Data Analysist L004 Anank TI407 Cisco L003 Tarrie005 Emma Crystal B2 Serpong Tangerang SI Wayan TI403 Database System L001 Aryl TI405 Oracle SQL L002 Mayya TI407 Cisco L003 Tarrie
What is the key attribute for above table? What are the repeating groups?
Team Dosen UMN
First Normal Form (1NF)
• Definition: a relation in which intersection of each row and column contains one and only one value.
• Transforming from UNF to 1NF:– Identify and remove repeating groups within a table– There are two common approach in removing repeating groups from
un-normalized table:1. By entering appropriate data in the empty columns of rows
containing the repeating data (Flattening the table).2. By placing the repeating data, along with a copy of original key
attributes in a separate relation.
Team Dosen UMN
Transform from UNF to 1NF
• Flattening the table:
NIM Name Address City Prodi Kaprodi CourseCode CourseName Lecturerid LecturerName
001 Aldo Emerald C1 Serpong Tangerang TI Jacky TI403 Database System L001 Aryl
001 Aldo Emerald C1 Serpong Tangerang TI Jacky TI405 Oracle SQL L002 Mayya
001 Aldo Emerald C1 Serpong Tangerang TI Jacky TI407 Cisco L003 Tarrie
002 Bernard Crystal B1 Jakarta SI Wayan TI403 Database System L001 Aryl
002 Bernard Crystal B1 Jakarta SI Wayan SI401 Data Analysist L004 Anank
002 Bernard Crystal B1 Jakarta SI Wayan TI407 Cisco L003 Tarrie
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky TI403 Database System L001 Aryl
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky TI405 Oracle SQL L002 Mayya
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky TI407 Cisco L003 Tarrie
004 Demi Illago R1 Serpong Tangerang SI Wayan TI403 Database System L001 Aryl
004 Demi Illago R1 Serpong Tangerang SI Wayan SI401 Data Analysist L004 Anank
004 Demi Illago R1 Serpong Tangerang SI Wayan TI407 Cisco L003 Tarrie
005 Emma Crystal B2 Serpong Tangerang SI Wayan TI403 Database System L001 Aryl
005 Emma Crystal B2 Serpong Tangerang TI Jacky TI405 Oracle SQL L002 Mayya
005 Emma Crystal B2 Serpong Tangerang SI Wayan TI407 Cisco L003 Tarrie
Team Dosen UMN
Transform from UNF to 1NF
• Making separate tables along with the key attribute (NIM):
NIM Name Address City Prodi Kaprodi001 Aldo Emerald C1 Serpong Tangerang TI Jacky002 Bernard Crystal B1 Jakarta SI Wayan003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky004 Demi Illago R1 Serpong Tangerang SI Wayan005 Emma Crystal B2 Serpong Tangerang SI Wayan
NIM CourseCode CourseName Lecturerid LecturerName001 TI403 Database System L001 Aryl001 TI405 Oracle SQL L002 Mayya001 TI407 Cisco L003 Tarrie002 TI403 Database System L001 Aryl002 SI401 Data Analysist L004 Anank002 TI407 Cisco L003 Tarrie003 TI403 Database System L001 Aryl003 TI405 Oracle SQL L002 Mayya003 TI407 Cisco L003 Tarrie004 TI403 Database System L001 Aryl004 SI401 Data Analysist L004 Anank004 TI407 Cisco L003 Tarrie005 TI403 Database System L001 Aryl005 TI405 Oracle SQL L002 Mayya005 TI407 Cisco L003 Tarrie
Team Dosen UMN
Second Normal Form (2NF)
• Definition: A relation that is in the first normal form and every non-primary key attribute is fully functionally dependent on the primary key.
• Transforming 1NF to 2NF:– Identify partial dependent attributes– Remove all partial dependent attributes from the table in a new table
along with copy of their determinant
Team Dosen UMN
Transform from 1NF to 2NF
• Which attribute(s) is the primary key?• Which attributes are partially dependent on the primary key?
NIM Name Address City Prodi Kaprodi
001 Aldo Emerald C1 Serpong Tangerang TI Jacky
002 Bernard Crystal B1 Jakarta SI Wayan
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky
004 Demi Illago R1 Serpong Tangerang SI Wayan
005 Emma Crystal B2 Serpong Tangerang SI Wayan
• As NIM is a single attribute, all attributes are fully functional dependent on NIM.
Team Dosen UMN
Transform from 1NF to 2NF
• Which attribute(s) is the primary key?• Which attributes are partially dependent on the primary key?
• (NIM, CourseCode) all attributes (Primary Key)• CourseCode CourseName (Partially Dependent)• Is CourseCodeLecturerId?
NIM CourseCode CourseName Lecturerid LecturerName001 TI403 Database System L001 Aryl001 TI405 Oracle SQL L002 Mayya001 TI407 Cisco L003 Tarrie002 TI403 Database System L001 Aryl002 SI401 Data Analysist L004 Anank002 TI407 Cisco L003 Tarrie003 TI403 Database System L001 Aryl003 TI405 Oracle SQL L002 Mayya003 TI407 Cisco L003 Tarrie004 TI403 Database System L001 Aryl004 SI401 Data Analysist L004 Anank004 TI407 Cisco L003 Tarrie005 TI403 Database System L001 Aryl005 TI405 Oracle SQL L002 Mayya005 TI407 Cisco L003 Tarrie
Team Dosen UMN
Transform from 1NF to 2NF
CourseCode CourseNameSI401 Data AnalysistTI403 Database SystemTI405 Oracle SQLTI407 Cisco
NIM CourseCode Lecturerid LecturerName001 TI403 L001 Aryl001 TI405 L002 Mayya001 TI407 L003 Tarrie002 SI401 L004 Anank002 TI403 L001 Aryl002 TI407 L003 Tarrie003 TI403 L001 Aryl003 TI405 L002 Mayya003 TI407 L003 Tarrie004 SI401 L004 Anank004 TI403 L001 Aryl004 TI407 L003 Tarrie005 TI403 L001 Aryl005 TI405 L002 Mayya005 TI407 L003 Tarrie
Team Dosen UMN
Third Normal Form (3NF)
• Definition: A relation that is in first and second normal form and in which no non-primary-key attribute is transitive dependent on the primary key
• Transforming from 2NF to 3NF:– Remove all transitive dependencies by placing attributes in new table
along with a copy of the determinant.
Team Dosen UMN
Transforming 2NF to 3NF
• NIMProdi but ProdiKaprodi (Transitive Dependency)
NIM Name Address City Prodi Kaprodi
001 Aldo Emerald C1 Serpong Tangerang TI Jacky
002 Bernard Crystal B1 Jakarta SI Wayan
003 Cameron Aqua Marine T1 Serpong Tangerang TI Jacky
004 Demi Illago R1 Serpong Tangerang SI Wayan
005 Emma Crystal B2 Serpong Tangerang SI Wayan
NIM Name Address City Prodi001 Aldo Emerald C1 Serpong Tangerang TI002 Bernard Crystal B1 Jakarta SI003 Cameron Aqua Marine T1 Serpong Tangerang TI004 Demi Illago R1 Serpong Tangerang SI005 Emma Crystal B2 Serpong Tangerang SI
Prodi KaprodiSI WayanTI Jacky
Team Dosen UMN
Transform from 2NF to 3NF
CourseCode CourseNameSI401 Data AnalysistTI403 Database SystemTI405 Oracle SQLTI407 Cisco
NIM CourseCode Lecturerid LecturerName001 TI403 L001 Aryl001 TI405 L002 Mayya001 TI407 L003 Tarrie002 SI401 L004 Anank002 TI403 L001 Aryl002 TI407 L003 Tarrie003 TI403 L001 Aryl003 TI405 L002 Mayya003 TI407 L003 Tarrie004 SI401 L004 Anank004 TI403 L001 Aryl004 TI407 L003 Tarrie005 TI403 L001 Aryl005 TI405 L002 Mayya005 TI407 L003 Tarrie
• (NIM,CourseCode)LecturerId, but LecturerIdLecturerName (Transitive Dependency)
Team Dosen UMN
Transform from 2NF to 3NF
CourseCode CourseNameSI401 Data AnalysistTI403 Database SystemTI405 Oracle SQLTI407 Cisco
Lecturerid LecturerNameL001 ArylL002 MayyaL003 TarrieL004 Anank
NIM CourseCode Lecturerid001 TI403 L001001 TI405 L002001 TI407 L003002 SI401 L004002 TI403 L001002 TI407 L003003 TI403 L001003 TI405 L002003 TI407 L003004 SI401 L004004 TI403 L001004 TI407 L003005 TI403 L001005 TI405 L002005 TI407 L003
Team Dosen UMN
Result from UNF to 3NF
CourseCode CourseNameSI401 Data AnalysistTI403 Database SystemTI405 Oracle SQLTI407 Cisco
Lecturerid LecturerNameL001 ArylL002 MayyaL003 TarrieL004 Anank
NIM CourseCode Lecturerid001 TI403 L001001 TI405 L002001 TI407 L003002 SI401 L004002 TI403 L001002 TI407 L003003 TI403 L001003 TI405 L002003 TI407 L003004 SI401 L004004 TI403 L001004 TI407 L003005 TI403 L001005 TI405 L002005 TI407 L003
NIM Name Address City Prodi001 Aldo Emerald C1 Serpong Tangerang TI002 Bernard Crystal B1 Jakarta SI003 Cameron Aqua Marine T1 Serpong Tangerang TI004 Demi Illago R1 Serpong Tangerang SI005 Emma Crystal B2 Serpong Tangerang SI
Prodi KaprodiSI WayanTI Jacky