14
Normalization

Oracle Normalization Simplified

Embed Size (px)

DESCRIPTION

For my dear accy friends

Citation preview

Page 1: Oracle Normalization Simplified

Normalization

Page 2: Oracle Normalization Simplified

Normalize the Data Model

First Normal Form (1NF) All Attributes must be single-valued

Second Normal Form (2NF) An attribute must be dependent upon its

entity’s entire unique identifier Third Normal Form (3NF)

All non key attributes are mutually independent and are fully dependent on primary key

A normalized entity-relationship data model automatically translates into a A normalized entity-relationship data model automatically translates into a normalized relational database design!normalized relational database design!

Normalization is a relational database concept, but its principlesNormalization is a relational database concept, but its principlesapply to Conceptual Data Modelling.apply to Conceptual Data Modelling.

Page 3: Oracle Normalization Simplified

First Normal FormSingle-valued attributes

Validate that each attribute has a single value for each occurrence of the entity. No attribute should have repeating values.

CLIENTCLIENT#* identifier#* identifier * date contacted* date contacted

Does the entity CLIENT comply with 1NF?Does the entity CLIENT comply with 1NF?

The attribute The attribute date contacteddate contacted has multiple values, therefore the has multiple values, therefore the entity CLIENT is not in 1NF.entity CLIENT is not in 1NF.

First Normal Form Rule: All attributes must be singled-valued.First Normal Form Rule: All attributes must be singled-valued.

Page 4: Oracle Normalization Simplified

First Normal Form (cont)

If an attribute has multiple values, create an additional entity and relate it to the original entity with a M:1 relationship.

CLIENTCLIENT#* identifier#* identifier

CONTACTCONTACT#* date contacted#* date contacted o locationo location o resulto result

forfor

the the subject subject

ofof

Page 5: Oracle Normalization Simplified

Second Normal FormDependency on entire UID

Validate that each attribute is dependent on its entity’s entire unique identifier. Each specific instance of the UID must determine a single instance of each attribute.

Validate that an attribute is not dependent upon only part of its entity’s UID.

COURSECOURSE#* code#* code * name* name * duration* duration * fee* fee

Validate placement of the COURSE entity’s Validate placement of the COURSE entity’s attributesattributes

In this example, each instance of a In this example, each instance of a course codecourse code determines determines a specific value for a specific value for namename, , durationduration, and , and feefee. The . The attributes are properly placed.attributes are properly placed.

Second Normal Form Rule: An attribute must be dependent uponSecond Normal Form Rule: An attribute must be dependent uponits entity’s entire unique identifier.its entity’s entire unique identifier.

Page 6: Oracle Normalization Simplified

Second Normal Form (cont)

Validate the placement of the attributes for the ACCOUNT and BANK entities

ACCOUNTACCOUNT BANKBANK#* number#* number * name* name

#* number#* number * balance* balance * date opened* date opened * bank location* bank location

managed managed byby

the the manager manager

ofof

Are there any attributes which can be determined from a portion of Are there any attributes which can be determined from a portion of its entity’s UID?its entity’s UID?

Page 7: Oracle Normalization Simplified

Second Normal Form (cont)

Validate the placement of the attributes for the ACCOUNT and BANK entities

ACCOUNTACCOUNT BANKBANK#* number#* number * name* name * bank location* bank location

#* number#* number * balance* balance * date opened* date opened

managed managed byby

the the manager manager

ofof

Each instance of a BANK and Each instance of a BANK and account numberaccount number determine specific determine specific values of values of balancebalance and and date openeddate opened for each account. The attribute for each account. The attribute bank locationbank location is misplaced. It is dependent on BANK but not on is misplaced. It is dependent on BANK but not on account numberaccount number and so should be an attribute of BANK. and so should be an attribute of BANK.

Page 8: Oracle Normalization Simplified

Third Normal FormNo non-UID interdependencies

Validate that each non-UID attribute is not dependent upon another non-UID attribute

Move any non-UID attribute that is dependent upon another non-UID attribute

ORDERORDER#* id#* id * date of order* date of order * customer id* customer id * customer name* customer name * state* state

Are any of the non-UID attributes for this Are any of the non-UID attributes for this entity dependent upon another non-UID entity dependent upon another non-UID attribute?attribute?

Third Normal Form Rule: No non-UID attribute can be dependentThird Normal Form Rule: No non-UID attribute can be dependentupon another non-UID attribute.upon another non-UID attribute.

Page 9: Oracle Normalization Simplified

Third Normal Form (cont)

ORDERORDER#* id#* id * date of order* date of order * customer id* customer id * customer name* customer name * state* state

forfor

the the submitter submitter

ofof

CUSTOMERCUSTOMER#* id#* id * name* name * state* state

ORDERORDER#* id#* id * date of order* date of order

The attributes The attributes customer namecustomer name and and statestate are are dependent on the dependent on the customer idcustomer id. Create another . Create another entity called CUSTOMER with a UID of entity called CUSTOMER with a UID of customer customer idid and place the attributes accordingly. and place the attributes accordingly.

Page 10: Oracle Normalization Simplified

Exercise N-1For the following E-R Model, evaluate each entity against the rules

of normalization, identify the misplaced attribute, and explain what rule of normalization each misplaced attribute violates.

Optionally, re-draw the E-R diagram in third normal form.

forfor

completed completed withwith

COURSECOURSE#* course number#* course number course namecourse name teacher numberteacher number department codedepartment code department namedepartment name teacher nameteacher name

ENROLLMENTENROLLMENT

grade codegrade codeteacher numberteacher numbergrade descriptiongrade descriptioncourse namecourse name

STUDENTSTUDENT

#* student id#* student id last namelast name first namefirst name

forfor

assignedassigned

Page 11: Oracle Normalization Simplified

Exercise N-1 Solution-1NF

Any repeating values?

forfor

completed completed withwith

ENROLLMENTENROLLMENT

grade codegrade code teacher numberteacher number grade descriptiongrade description course namecourse name

STUDENTSTUDENT

#* student id#* student id last namelast name first namefirst name

forfor

assignedassigned

COURSECOURSE#* course number#* course number course namecourse name teacher numberteacher number department codedepartment code department namedepartment name teacher nameteacher name

There is no violation of There is no violation of First Normal form, so First Normal form, so the entities stay the same.the entities stay the same.

Page 12: Oracle Normalization Simplified

Exercise N-1 Solution-2NF Any partial UID dependencies?

forfor

completed completed withwith

COURSECOURSE#* course number#* course number course namecourse name teacher numberteacher number department codedepartment code department namedepartment name teacher nameteacher name

ENROLLMENTENROLLMENT

grade codegrade code teacher numberteacher number grade descriptiongrade description course namecourse name

STUDENTSTUDENT

#* student id#* student id last namelast name first namefirst name

forfor

assignedassigned Yes! Teacher Number Yes! Teacher Number and Course Name, in the and Course Name, in the ENROLLMENT entity, ENROLLMENT entity, do not depend on both do not depend on both the Course Number and the Course Number and Student Id.Student Id.

Page 13: Oracle Normalization Simplified

Exercise N-1 Solution-3NF

forfor

completed completed withwith

COURSECOURSE#* course number#* course number course namecourse name teacher numberteacher number department codedepartment code department namedepartment name teacher nameteacher name

ENROLLMENTENROLLMENT

grade codegrade code grade descriptiongrade description

STUDENTSTUDENT

#* student id#* student id last namelast name first namefirst name

forfor

assignedassigned

• Any transitive UID dependencies?Any transitive UID dependencies?

Yes! Grade Description is dependent Yes! Grade Description is dependent on Grade Code, Department Name is on Grade Code, Department Name is dependent on Department Number, dependent on Department Number, and Teacher name is dependent on and Teacher name is dependent on Teacher Number.Teacher Number.

Page 14: Oracle Normalization Simplified

offered byoffered by

the offerer ofthe offerer of

COURSECOURSE# * course number# * course number course namecourse name

ENROLLMENTENROLLMENT

STUDENTSTUDENT# * student id# * student id last namelast name first namefirst name

forforassignedassigned

GRADEGRADE# * code# * code descriptiondescription

DEPARTMENTDEPARTMENT

TEACHERTEACHER# * number# * number namename

taught bytaught by

the the teacher teacher

ofof

the receiver the receiver ofof

assigned toassigned to

forfor

completed withcompleted with

# * number# * number namename

The ENROLLMENT entity The ENROLLMENT entity has no attributes of its own. has no attributes of its own. It is still considered an It is still considered an entity, since it participates entity, since it participates in 2 or more relationships.in 2 or more relationships.

Exercise N-1Solution-Normalized Model