Upload
joella-austin
View
217
Download
1
Embed Size (px)
Citation preview
Normalisation
Rules and Practical Application
Geoff Leese January 2010
Normalisation and Rules of Normalisation
• Normalisation: the process of converting complex data structures into simple, stable data structures.
• First Normal From (1NF)– Unique rows, no multivalued attributes.– All relations are in 1NF.
• Second Normal Form (2NF)• Each nonprimary key attribute is identified by the whole key (called full
functional dependency). • Third Normal Form (3NF)
– Nonprimary key attributes do not depend on each other (i.e. no transitive dependencies).
• The result of normalisation is that every nonprimary key attribute depends upon the whole primary key.
Functional Dependencies and Primary Keys
• Functional Dependency– A particular relationship between two
attributes. – For a given relation, attribute B is
functionally dependent on attribute A if, for every valid value of A, that value of A uniquely determines the value of B.
– The functional dependence of B on A is represented by A→B.
Functional Dependencies and Primary Keys (Cont.)
• Functional dependency is not a mathematical dependency.
• Instances (or sample data) in a relation do not prove the existence of a functional dependency.
• Knowledge of problem domain is most reliable method for identifying functional dependency.
Second Normal Form (2NF)
• A relation is in second normal form (2NF) if any of the following conditions apply:– Every non-primary key attribute is functionally dependent on the
full set of primary key attributes.
• To convert a relation into 2NF, you decompose the relation into new relations using the attributes, called determinants, that determine other attributes.
• The determinants are the primary key of the new relation.
Third Normal Form (3NF)
• A relation is in third normal form (3NF) if it is in second normal form (2NF) and there are no functional (transitive) dependencies between two (or more) nonprimary key attributes.
Third Normal Form (3NF) (Cont.)
• Foreign Key: an attribute that appears as a non-primary key attribute in one relation and as a primary key attribute (or part of a primary key) in another relation.
• Referential Integrity: an integrity constraint specifying that the value (or existence) of an attribute in one relation depends on the value (or existence) of the same attribute in another relation.
Example stage oneStudent entity
Student_id (primary key)
Student_name
Student_addressStudent_phone_noStudent_email_addressStudent_course_code_oneStudent_course_title_oneStudent_course_location_oneStudent_course_leader_id oneStudent_course_leader_name_oneStudent_course_leader_email_oneStudent_course_code_twoStudent_course_title_twoStudent_course_location_twoStudent_course_leader_id twoStudent_course_leader_name_twoStudent_course_leader_email_two
Where are the problems?
Example stage twoStudent entity
Student_id (primary key)
Student_surname
Student_firstnameStudent_address_house and streetStudent_address_districtStudent_address_townStudent_address_cityStudent_address_postcodeStudent_phone_noStudent_email_address
Course entity
Student_addressStudent_phone_noStudent_email_addressCourse_codeCourse_titleCourse_locationCourse_leader_idCourse_leader_first_nameCourse_leader_surnameCourse_leader_email
First Normal Form – repeating group removed to form a new entity, multi-valued attributes decomposed.Second normal form?
Example stage threeStudent entity
Student_id (primary key)
Student_surname
Student_firstnameStudent_address_house and streetStudent_address_districtStudent_address_townStudent_address_cityStudent_address_postcodeStudent_phone_noStudent_email_address
Course entity
Course_code (primary key)Course_titleCourse_location
Second Normal Form – “Course leader” set of attributes removed to form a new entity as they don’t depend on the course ID.Third normal form? Relationships?
Course_Leader entity
Course_ Leader_idCourse_leader_first_nameCourse_leader_surnameCourse_leader_email
Student
Student_idStudent_surnam eStudent_firs tnam eStudent_address_house no and streetStudent_address_dis trictStudent_address_tow nStudent_address_cityStudent_address_postcodeStudent_phone_noStudent_em ail_address
C ourse_1
C ourse_codeC ourse_titleC ourse_location
* C ourse_leader_ id
C ourse_leader
C ourse_leader_ idC ourse_leader_first_nam eC ourse_leader_surnam eC ourse_leader_em ail
Enrolm ent
* Student_id* C ourse_codeEnrolm ent_date
ow nedby
the ow nerof
for
the subjectof
ledby
the leaderof
The completed ERD (LDS in SELECT SSADM language!)
I’m not sure about the “address” set of attributes – are you?
Further reading
• http://askgeoff.org.uk/ITSKILLS/Presentations/Hoffer5e_CH10.ppt - Week 20.
• Hoffer et al (2008), Modern Systems Analysis and Design (5th edition) pages 352-355
• http://www.youtube.com/watch?v=uO80f642LCY– Accent grates a bit, but otherwise OK!
• http://www.dbnormalization.com/examples