IT-501 Database Management Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.

Slides:



Advertisements
Similar presentations
Normalisation.
Advertisements

PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
CS263:Revision on Normalisation
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
Terms - data,information, file record, table, row, column, transaction, concurrency Concepts - data integrity, data redundancy, Type of databases – single-user,
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Model Database Management Systems I Alex Coman, Winter 2006.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
DBSQL 4-1 Copyright © Genetic Computer School 2009 Chapter 4 Database Design.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Avoiding Database Anomalies
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
Module Title? DBMS Normalization. Module Title? DBMS Normalization  Normalization is the process of removing redundant data from tables in order to improve.
Normalisation Mia’s Sandwich Shop The Process Explained.
SALINI SUDESH. Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Chapter 13 Normalization Transparencies. 2 Chapter 13 - Objectives u Purpose of normalization. u Problems associated with redundant data. u Identification.
1 5 Normalization. 2 5 Database Design Give some body of data to be represented in a database, how do we decide on a suitable logical structure for that.
Customer Order Order Number Date Cust ID Last Name First Name State Amount Tax Rate Product 1 ID Product 1 Description Product 1 Quantity Product 2 ID.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
1 Session 3 Welcome: To session 3-the fifth learning sequence “ Relational algebra “ Recap : In the previous learning sequences, we discussed the eight.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
Handling Many to Many Relationships. 2 Handling Many:Many Relationships Aims: To explain why M:M relationships cannot be implemented in relational database.
ITN Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization.
1 5 Chapter 5 Database Design 1: Some Normalization Examples Spring 2006.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
PMIT-6102 Advanced Database Systems
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Computing & Information Sciences Kansas State University Wednesday, 03 Sep 2008CIS 560: Database System Concepts Lecture 3 of 42 Wednesday, 03 September.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
IMS 4212: Normalization 1 Dr. Lawrence West, Management Dept., University of Central Florida Normalization—Topics Functional Dependency.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Lecture # 17 Chapter # 10 Normalization Database Systems.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database Systems. DataBase System Haichang Gao, Software School, Xidian University 2 Major Content & Grade  Introduction*  The Relational Model** 
Normalisation Worked example for an Order Remember : The data should depend upon the key, the whole key and nothing but the key.
Session 3 Welcome: To session 3-the fifth learning sequence
Chapter 3: Relational Model III
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
Some Normalization Examples
Chapter 8 – Part2 Database Design.
Chapter 8 – Part2 Database Design.
Chapter 14 Normalization Pearson Education © 2009.
User Views and merging relations & Journaling
Some Normalization Examples
Presentation transcript:

IT-501 Database Management Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University

Lecture 04 Relational Database Design Normalization-Part-2

Outline Overview of Relational DBMS  Normalization

Example 3: Determine NF Part_ID  Description Part_ID  Price Part_ID, Comp_ID  No Comp_ID and No are not determined by the primary key; therefore, the relation is NOT in 1 NF. No sense in looking at partial or transitive dependencies. Part_IDDescrPriceComp_IDNo

Example 3: Determine NF Part_ID  Description Part_ID  Price Part_ID, Comp_ID  No In your solution you will write the following justification: 1) There are M/V attributes; therefore, not 1NF Conclusion: The relation is not normalized.

Bringing a Relation to 1NF

Option 1: Make a determinant of the repeating group (or the multivalued attribute) a part of the primary key. Composite Primary Key

Bringing a Relation to 1NF Option 2: Remove the entire repeating group from the relation. Create another relation which would contain all the attributes of the repeating group, plus the primary key from the first relation. In this new relation, the primary key from the original relation and the determinant of the repeating group will comprise a primary key.

Bringing a Relation to 1NF

Bringing a Relation to 2NF Composite Primary Key

Bringing a Relation to 2NF Composite Primary Key Goal: Remove Partial Dependencies Partial Dependencies

Bringing a Relation to 2NF Remove attributes that are dependent from the part but not the whole of the primary key from the original relation. For each partial dependency, create a new relation, with the corresponding part of the primary key from the original as the primary key.

Bringing a Relation to 2NF

Bringing a Relation to 3NF Goal: Get rid of transitive dependencies. Transitive Dependency

Bringing a Relation to 3NF Remove the attributes, which are dependent on a non-key attribute, from the original relation. For each transitive dependency, create a new relation with the non-key attribute which is a determinant in the transitive dependency as a primary key, and the dependent non-key attribute as a dependent.

Bringing a Relation to 3NF

Unnormalised Normal Form (UNF) ORDER (order-no, order-date, cust-no, cust-name, cust-add, (prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total

First Normal Form (1NF) Definition: A relation is in 1NF if, and only if, all its underlying attributes contain atomic values only. Steps from UNF to 1NF:  Remove the outermost repeating group (and any nested repeated groups it may contain) and create a new relation to contain it.  Add to this relation a copy of the PK of the relation immediately enclosing it.  Name the new entity (appending the number 1 to indicate 1NF)  Determine the PK of the new entity  Repeat steps until no more repeating groups. Remove repeating groups into a new relation A repeating group is shown by a pair of brackets within the relational schema. ORDER (order-no, order-date, cust-no, cust-name, cust-add, (prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total

Example - UNF to 1NF ORDER (order-no, order-date, cust-no, cust-name, cust-add, (prod-no, prod-desc, unit-price, ord-qty, line-total)*, order-total 1. Remove the outermost repeating group (and any nested repeated groups it may contain) and create a new relation to contain it. (rename original to indicate 1NF) ORDER-1 (order-no, order-date, cust-no, cust-name, cust-add, order-total (prod-no, prod-desc, unit-price, ord-qty, line-total) 2. Add to this relation a copy of the PK of the relation immediately enclosing it. ORDER-1 (order-no, order-date, cust-no, cust-name, cust-add, order-total (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total) 3. Name the new entity (appending the number 1 to indicate 1NF) ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total) 4. Determine the PK of the new entity ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total)

Second Normal Form (2NF) Definition: A relation is in 2NF if, and only if, it is in 1NF and every non-key attribute is fully dependent on the primary key. Steps from 1NF to 2NF:  Remove the offending attributes that are only partially functionally dependent on the composite key, and place them in a new relation.  Add to this relation a copy of the attribute(s) which are the determinants of these offending attributes. These will automatically become the primary key of this new relation.  Name the new entity (appending the number 2 to indicate 2NF)  Rename the original entity (ending with a 2 to indicate 2NF) Remove partial functional dependencies into a new relation

Example - 1NF to 2NF ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total) 1. Remove the offending attributes that are only partially functionally dependent on the composite key, and place them in a new relation. ORDER-LINE-1 (order-no, prod-no, ord-qty, line-total) (prod-desc, unit-price) 2. Add to this relation a copy of the attribute(s) which determines these offending attributes. These will automatically become the primary key of this new relation.. (prod-no, prod-desc, unit-price) ORDER-LINE-1 (order-no, prod-no, ord-qty, line-total) 3. Name the new entity (appending the number 2 to indicate 2NF) PRODUCT-2 (prod-no, prod-desc, unit-price) 4. Rename the original entity (ending with a 2 to indicate 2NF) ORDER-LINE-2 (order-no, prod-no, ord-qty, line-total)

Third Normal Form (3NF) Definition: A relation is in 3NF if, and only if, it is in 2NF and every non-key attribute is non-transitively dependent on the primary key. Steps from 2NF to 3NF:  Remove the offending attributes that are transitively dependent on non-key attribute(s), and place them in a new relation.  Add to this relation a copy of the attribute(s) which are the determinants of these offending attributes. These will automatically become the primary key of this new relation.  Name the new entity (appending the number 3 to indicate 3NF)  Rename the original entity (ending with a 3 to indicate 3NF) Remove transitive dependencies into a new relation

Example - 2NF to 3NF ORDER-2 (order-no, order-date, cust-no, cust-name, cust-add, order-total 1. Remove the offending attributes that are transitively dependent on non-key attributes, and place them in a new relation. (cust-name, cust-add ) ORDER-2 (order-no, order-date, cust-no, order-total 2. Add to this relation a copy of the attribute(s) which determines these offending attributes. These will automatically become the primary key of this new relation.. (cust-no, cust-name, cust-add ) ORDER-2 (order-no, order-date, cust-no, order-total 3. Name the new entity (appending the number 3 to indicate 3NF) CUSTOMER-3 (cust-no, cust-name, cust-add ) 4. Rename the original entity (ending with a 3 to indicate 3NF) ORDER-3 (order-no, order-date, cust-no, order-total

Example - Relations in 3NF CUSTOMER-3 (cust-no, cust-name, cust-add ) ORDER-3 (order-no, order-date, cust-no, order-total ORDER-LINE-2 (order-no, prod-no, ord-qty, line-total) PRODUCT-2 (prod-no, prod-desc, unit-price) CUSTOMER ORDER ORDER-LINE PRODUCT places placed by contains part of shows belongs to cust-no order-no prod-no order-no, prod-no

Case Study on Normalization Consider the table EMP_DEPT_PROJ And the following dependencies which exist in the above table: Slide 25

Steps to Normalize the database D Thus we will have 3 tables Slide 26

Step 2  Let us now identify the transitive dependency and remove it. Slide 27 Steps to Normalize the database

Step 3:  Let us now identify the non key determinants and remove them.  Thus we will have 5 tables Slide 28 Steps to Normalize the database

Suppose The Gill Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at one time. Paintings may be bought and sold several times. In other words, the gallery may sell a painting, then buy it back at a later date and sell it to another customer. UNF:  customer [ custno, cust_name, cust_addr, cust_phone, ( artist_id, artist_name, art_title, pur_date, price) ] 1NF:  customer [ custno, cust_name, cust_addr, cust_phone]  cust_art [ custno, art_code, pur_date, artist_id, artist_name, art_title, price ] Slide 29 Case Study on Normalization

UNF:  customer [ custno, cust_name, cust_addr, cust_phone, ( artist_id, artist_name, art_title, pur_date, price) ] 1NF:  customer [ custno, cust_name, cust_addr, cust_phone]  cust_art [ custno, art_code, pur_date, artist_id, artist_name, art_title, price ] o note: the key chosen for the repeating group is the piece of art itself (a code was assigned), however because a piece of art may be bought by a customer more than once, the purchase date was added as part of the key to make the rows unique. Slide 30 Case Study on Normalization

1NF:  customer [ custno, cust_name, cust_addr, cust_phone]  cust_art [ custno, art_code, pur_date, artist_id, artist_name, art_title, price ] 2NF:  customer [ custno, cust_name, cust_addr, cust_phone]  cust_art [ custno, art_code, pur_date, price ]  art [ art_code, art_title, artist_id, artist_name ] Slide 31 Case Study on Normalization

2NF:  customer [ custno, cust_name, cust_addr, cust_phone]  cust_art [ custno, art_code, pur_date, price ]  art [ art_code, art_title, artist_id, artist_name ] 3NF:  customer [ custno, cust_name, cust_street, cust_city, cust_prov, cust_pstlcd, cust_phone]  cust_art [ custno, art_code, pur_date, price ]  art [ art_code, art_title, artist_id(FK) ]  artist [ artist_id, artist_fname, artist_lname ] Slide 32 Case Study on Normalization

3NF:  customer [ custno, cust_name, cust_street, cust_city, cust_prov, cust_pstlcd, cust_phone]  cust_art [ custno, art_code, pur_date, price ]  art [ art_code, art_title, artist_id(FK) ]  artist [ artist_id, artist_fname, artist_lname ] Slide 33 Case Study on Normalization

Review Class on Relational Algebra Slide 34

Natural Join Operation – Example Relations r, s: AB  CD  aababaabab B D aaabbaaabb E  r AB  CD  aaaabaaaab E  s r s Slide 35  r.A, r.B, r.C, r.D, s.E (  r.B = s.B  r.D = s.D (r x s))

The customer Relation 36 The branch Relation The depositor Relation Account Relation

borrower Relation 37 The Loan Relation Loan-numberBranch-nameamount L-11Round Hill900 L-14Downtown1500 L-15Perryridge1500 L-16Perryridge1300 L-17Downtown1000 L-23Redwood2000 L-93Mianus500

Result of  customer-name, branch-name (depositor account) 38 Result of  customer-name, loan-number, amount (borrower loan)

Division Operation – Example Relations r, s: r  s:r  s: A B  1212 AB  r s 39

Another Division Example AB  aaaaaaaaaaaaaaaa CD  aabababbaabababb E Relations r, s: r  s:r  s: D abab E 1111 AB  aaaa C  r s 40

Find all customers who have an account at all branches located in Brooklyn city. Example Queries  customer-name, branch-name (depositor account)   branch-name (  branch-city = “Brooklyn” (branch)) Slide 41 depositor account branch

Result of  customer-name, branch-name (depositor account) 42 Result of  branch-name (  branch-city = “Brooklyn” (branch))  customer-name, branch-name (depositor account)   branch-name (  branch-city = “Brooklyn” (branch)) Customer-name Johnson

Thank You