Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

Similar documents
Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

Chapter 10. Chapter Outline. Chapter Outline. Functional Dependencies and Normalization for Relational Databases

Functional Dependencies and Normalization for Relational Databases Design & Analysis of Database Systems

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 10-2

Informal Design Guidelines for Relational Databases

Chapter 14. Database Design Theory: Introduction to Normalization Using Functional and Multivalued Dependencies

Functional Dependencies and. Databases. 1 Informal Design Guidelines for Relational Databases. 4 General Normal Form Definitions (For Multiple Keys)

Relational Database design. Slides By: Shree Jaswal

UNIT 3 DATABASE DESIGN

MODULE: 3 FUNCTIONAL DEPENDENCIES

We shall represent a relation as a table with columns and rows. Each column of the table has a name, or attribute. Each row is called a tuple.

Chapter 14 Outline. Normalization for Relational Databases: Outline. Chapter 14: Basics of Functional Dependencies and

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

The strategy for achieving a good design is to decompose a badly designed relation appropriately.

Functional Dependencies & Normalization for Relational DBs. Truong Tuan Anh CSE-HCMUT

Dr. Anis Koubaa. Advanced Databases SE487. Prince Sultan University

Database Design Theory and Normalization. CS 377: Database Systems

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

CS 2451 Database Systems: Database and Schema Design

Relational DB Design by ER- and EER-to-Relational Mapping Design & Analysis of Database Systems

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

ER to Relational Mapping

Relational Design: Characteristics of Well-designed DB

Schema Refinement: Dependencies and Normal Forms

Course Notes on From Entity-Relationship Schemas to Relational Schemas

Outline. Note 1. CSIE30600 Database Systems ER/EER to Relational Mapping 2

Schema Refinement: Dependencies and Normal Forms

Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

COSC Dr. Ramon Lawrence. Emp Relation

TDDD12 Databasteknik Föreläsning 4: Normalisering

FUNCTIONAL DEPENDENCIES

Relational Model. CS 377: Database Systems

Schema Refinement: Dependencies and Normal Forms

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

Functional Dependencies CS 1270

Functional Dependencies and Normalization

Steps in normalisation. Steps in normalisation 7/15/2014

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

Database Management

CSC 742 Database Management Systems

Entity Relationship Data Model. Slides by: Shree Jaswal

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

In Chapters 3 through 6, we presented various aspects

Databases The theory of relational database design Lectures for m

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

Relational Calculus: 1

V. Database Design CS448/ How to obtain a good relational database schema

CS 405G: Introduction to Database Systems

FINAL EXAM REVIEW. CS121: Introduction to Relational Database Systems Fall 2018 Lecture 27

This chapter discusses how to design a relational

DC62 DATABASE MANAGEMENT SYSTEMS DEC 2013

Relational Database Design (II)

FUNCTIONAL DEPENDENCIES CHAPTER , 15.5 (6/E) CHAPTER , 10.5 (5/E)

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

Chapter 7: Relational Database Design

CSE 562 Database Systems

Relational Design 1 / 34

Normalization. VI. Normalization of Database Tables. Need for Normalization. Normalization Process. Review of Functional Dependence Concepts

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

QUESTION BANK. SUBJECT CODE / Name: CS2255 DATABASE MANAGEMENT SYSTEM UNIT III. PART -A (2 Marks)

ER-to-Relational Mapping

CSCI 403: Databases 13 - Functional Dependencies and Normalization

Functional Dependencies and Finding a Minimal Cover

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences

DATABASE MANAGEMENT SYSTEMS

Chapter 2 Introduction to Relational Models

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 7: Entity-Relationship Model

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Chapter 7: Entity-Relationship Model

Functional Dependencies and Single Valued Normalization (Up to BCNF)

Relational Design Theory. Relational Design Theory. Example. Example. A badly designed schema can result in several anomalies.

CS 338 Functional Dependencies

Chapter 8: Relational Database Design

Chapter 7: Entity-Relationship Model

Chapter 6: Relational Database Design

Lecture 11 - Chapter 8 Relational Database Design Part 1

Normalisation. Normalisation. Normalisation

Redundancy:Dependencies between attributes within a relation cause redundancy.

Data Modeling with the Entity Relationship Model. CS157A Chris Pollett Sept. 7, 2005.

SVY227: Databases for GIS

Schema Normalization. 30 th August Submitted By: Saurabh Singla Rahul Bhatnagar

Chapter 2 ENTITY RELATIONSHIP MODEL

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

Database Management Systems Paper Solution

DATABASE DESIGN I - 1DL300

Unit- III (Functional dependencies and Normalization, Relational Data Model and Relational Algebra)

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

Relational Database Design Theory. Introduction to Databases CompSci 316 Fall 2017

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Normalization in DBMS

Database Systems ER Model. A.R. Hurson 323 CS Building

MIT Database Management Systems Lesson 03: ER-to-Relational Mapping

Database Design Process

Normalization is based on the concept of functional dependency. A functional dependency is a type of relationship between attributes.

RELATIONAL DATA MODEL

Transcription:

CSC 74 Database Management Systems Topic #6: Database Design Weak Entity Type E Create a relation R Include all simple attributes and simple components of composite attributes. Include the primary key of the relation corresponding to the owner entity type of E. Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning 4 Relations Regular Entity Type Create a relation R Include simple attributes and simple components of composite attributes Choose one of the key attributes as the primary key Multi-valued attributes: Don t include in R To be discussed later. Dependents_of Dependent Sex BDate Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning 5 MI Fname Lname Salary Sex Binary : relationship R Suppose S and T are the relations corresponding to the entity types participating R Choose either S (or T), and include the primary of T (or S) as foreign key. Include the simple attributes and the simple components of composite attributes of R. Better to choose the one with total participation in R. Spring 00 CSC 74: DBMS by Dr. Peng Ning 3 Spring 00 CSC 74: DBMS by Dr. Peng Ning 6

Manages Since Department Binary M:N relationship R Suppose S and T are the relations corresponding to the entity types participating R Create a relation U Include in U the primary keys of both S and T as foreign keys. They form the primary key of U. Include the simple attributes and the simple components of composite attributes of R. Spring 00 CSC 74: DBMS by Dr. Peng Ning 7 Spring 00 CSC 74: DBMS by Dr. Peng Ning 0 Binary :N relationship R Suppose S and T are the relations corresponding to the entity types participating R, and S is the N-side. Choose either S, and include the primary key of T as foreign key in S. Include simple attributes and simple components of composite attributes in S. Works_on Hours Project Spring 00 CSC 74: DBMS by Dr. Peng Ning 8 Spring 00 CSC 74: DBMS by Dr. Peng Ning Works_for Since Department Multi-valued attribute A Suppose A is an attribute of the entity type corresponding relation S. Create a relation R Include an attribute corresponding to A and the primary key K of S as a foreign key. The primary key of R is the combination of A and K. Spring 00 CSC 74: DBMS by Dr. Peng Ning 9 Spring 00 CSC 74: DBMS by Dr. Peng Ning

Department Relations Subclass-superclass relationships: Commonly four options Assume there are a super-class C and m subclasses {S, S,, Sm}. Assume the attributes of C are {k, a,, an}, and k is the key attribute. Spring 00 CSC 74: DBMS by Dr. Peng Ning 3 Spring 00 CSC 74: DBMS by Dr. Peng Ning 6 The n-ary relationship R Create a new relation S Include the primary keys of all the relations corresponding to the participating entity types in R. They form the primary key of S Include the simple attributes and the simple components of composite attributes of R. Option Create a relation L for C with all its attributes, and have k as the primary key. For each subclass Si, create a relation Li with attributes k and all the attributes of Si. The primary key of Si is k. Intuition: keep the attributes of the individual classes separately. Spring 00 CSC 74: DBMS by Dr. Peng Ning 4 Spring 00 CSC 74: DBMS by Dr. Peng Ning 7 S Supplier PartNo Supply PartNo Part Option For each subclass Si, create a relation Li with all the attributes of C and all the attributes of Si. The primary key of Si is k. Project Intuition: replicate the attributes of the super-class in subclasses. Proj Spring 00 CSC 74: DBMS by Dr. Peng Ning 5 Spring 00 CSC 74: DBMS by Dr. Peng Ning 8 3

Option 3 Create a single relation with the attributes of the super-class and all the subclasses plus a type attribute. The type attribute is used to indicate the subclass to which each tuple belong. Intuition: store all classes together. For disjoint specialization. Multiple inheritance: all superclasses have the same key Spring 00 CSC 74: DBMS by Dr. Peng Ning 9 Spring 00 CSC 74: DBMS by Dr. Peng Ning Option 4 Create a single relation with the attributes of the super-class and all the subclasses plus m type attributes. The type attributes boolean attributes indicating whether the tuple belongs to the corresponding subclasses. Intuition: Store all classes together. For overlapping specialization. Design Guidelines Have schemas that are easy to explain. Keep different entities and relationships apart where possible at least in base relations Prevent anomalies in insertion deletion modification Spring 00 CSC 74: DBMS by Dr. Peng Ning 0 Spring 00 CSC 74: DBMS by Dr. Peng Ning 3 Fname MI Lname Smith --3333 Tom -33-4444 0//7 0/4/68 DNumber Salary Sex Department D Research DNumber Mgr --3333 d EMP_DEPT Secretary Technican Engineer Smith Tom --3333-33-4444 0//7 0/4/68 DNumber D Research Research Mgr --3333 --3333 TypingSpeed TGrade EngType Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning 4 4

Design Guidelines (Cont d) Avoid NULL values in base relations, although they may occur in views. NULLs should apply rarely and have well-defined meaning: Not applicable unknown absent (known but absent) Prevent spurious tuples Spring 00 CSC 74: DBMS by Dr. Peng Ning 5 Registration StudentID Smith Smith John Course CSC0 CSC0 CSC0 V 50 V 00 V 50 Course StudentID X Y: The vales of the Y component of a tuple are determined by the values of the X component. Alternative statements The values of X functionally determines the values of Y. Y is functionally dependent on X. There is functional dependence from X to Y. Spring 00 CSC 74: DBMS by Dr. Peng Ning 8 Registration Reg Loc StudentID StudentID StudentID Course Smith CSC0 Smith CSC0 John CSC0 Course Smith CSC0 Smith CSC0 John CSC0 V 50 V 00 V 50 V 50 V 00 V 50 Reasoning With FDs: FDs can be inferred from other FDs. Let F be a set of FDs X Y is inferred from F if X Y holds in every relation r that satisfies F (notation: F = X Y) F+ is the set of all FDs that can be inferred from F. Called the closure of F. Spring 00 CSC 74: DBMS by Dr. Peng Ning 6 Spring 00 CSC 74: DBMS by Dr. Peng Ning 9 Functional Dependencies A constraint R is treated as a set of attributes below For subsets X and Y of R, X Y means that For all relations r of R, (forall t, t: t, t in r (t[x] = t[x] t[y] = t[y])) FDs depend on R and its meaning, not on r. Reasoning With FDs: FDs can be inferred based on Their formal definition Armstrong's rules: Reflexivity: If X contains Y, then X Y Augmentation: {X Y} = XZ YZ Transitivity: {X Y, Y Z} = X Z which are provably complete. Spring 00 CSC 74: DBMS by Dr. Peng Ning 7 Spring 00 CSC 74: DBMS by Dr. Peng Ning 30 5

Reasoning With FDs: 3 Minimal Cover (Cont d) Additional Inference Rules: Decomposition rule {X YZ} = X Y. Union rule {X Y, X Z} = X YZ Pseudo-transitive rule {X Y, WY Z} = WX Z. A minimal cover of a set F of FDs is a minimal set of FDs that is equivalent to F. Always exist. Algorithm 4. in textbook Step. Step. Change the FDs to those with one attribute on the right-hand side. Step 3. Try to remove attributes from the lefthand sides of FDs. Step 4. Try to remove redundant FDs. Spring 00 CSC 74: DBMS by Dr. Peng Ning 3 Spring 00 CSC 74: DBMS by Dr. Peng Ning 34 Find Additional FDs Given a set F of FDs, For each set of attributes X that appears as a left-hand side of an FD in F, Determine the set X + of attributes that are functionally determined by X based on F. X + : the closure of X under F. Algorithm to compute X + under F. X + :=X; Repeat OldX + := X + For each FD Y Z in F do If X + Y then X + := X + Z Until (X + = oldx + ) Spring 00 CSC 74: DBMS by Dr. Peng Ning 3 Normalization A process of cleaning up a schema by decomposing the relations in it to remove various anomalies but additional considerations apply A schema is in some normal form if it satisfies the specified mathematical properties and thereby avoids some potential anomalies Spring 00 CSC 74: DBMS by Dr. Peng Ning 35 Minimal Cover Equivalence of sets of FDs Two sets of functional dependencies E and F are equivalent if E + = F +. A set F of FDs is minimal if Every FD in F has a single attribute for the right-hand side We cannot replace any X A with Y A, where Y X, and still have a set of FDs equivalent to F. We cannot remove any FD from F and still have a set of FDs equivalent to F. Spring 00 CSC 74: DBMS by Dr. Peng Ning 33 Keys S is a superkey of R = {A,..., An} iff R contains S (forall t, t: t[s] = t[s]?) K is a (candidate) key or identifier of R iff K is a superkey (forall L: K contains L?) The primary key is one of the candidate keys. Spring 00 CSC 74: DBMS by Dr. Peng Ning 36 6

Achtung! Prime attribute member of any key not just the primary key Full FD X Y is a full FD if (forall W: (X contains W & W Y) X = W) X Y is a partial FD, otherwise Spring 00 CSC 74: DBMS by Dr. Peng Ning 37 Spring 00 CSC 74: DBMS by Dr. Peng Ning 40 NF Attributes must be atomic: they can be chars, ints, strings they can t be tuples sets relations composite multivalued NF R is in NF if every nonprime attribute is fully functionally dependent on every key of R Note that every attribute must be functionally dependent on every key (by definition of a key) Spring 00 CSC 74: DBMS by Dr. Peng Ning 38 Spring 00 CSC 74: DBMS by Dr. Peng Ning 4 Obtaining NF Obtaining NF NF is obtained by Splitting composite attributes splitting the relation and propagating the primary key to remove multivalued attributes If a nonprime attribute is dependent only on a proper part of a key, then we take the given attribute as well as the key attributes that determine it and move them all to a new relation We can bundle all attributes determined by the same subset of the key as a unit Spring 00 CSC 74: DBMS by Dr. Peng Ning 39 Spring 00 CSC 74: DBMS by Dr. Peng Ning 4 7

3NF: Alternative Definition EMP_PROJ PNumber FD FD FD3 Hours Ename Pname P R is in 3NF if every nonprime attribute of R is fully functionally dependent on every key of R, and nontransitively dependent on every key of R. Spring 00 CSC 74: DBMS by Dr. Peng Ning 43 Spring 00 CSC 74: DBMS by Dr. Peng Ning 46 3NF R is in 3NF if and only if if X A then X is a superkey of R, or A is a prime attribute of R Obtaining 3NF Split off the attributes in the FD that causes trouble and move them, so there are two relations for each such FD The determinant of the FD remains in the original relation Spring 00 CSC 74: DBMS by Dr. Peng Ning 44 Spring 00 CSC 74: DBMS by Dr. Peng Ning 47 Transitive Dependency X Y is a transitive dependency if (exists Z: Z is not contained in any key of R & X Z and Z Y) EMP_DEPT Ename BDate Address DNumber D DMgr Spring 00 CSC 74: DBMS by Dr. Peng Ning 45 Spring 00 CSC 74: DBMS by Dr. Peng Ning 48 8

BCNF R is in Boyce-Codd Normal Form iff if X A then X is a superkey of R more restrictive than 3NF preferable has fewer anomalies Universal Relation: A universal relation is a single giant relation containing the entire database has all attributes (renamed to be unique) has enough tuples with NULL values as appropriate not used in practice only a theoretical construct! Spring 00 CSC 74: DBMS by Dr. Peng Ning 49 Spring 00 CSC 74: DBMS by Dr. Peng Ning 5 Obtaining BCNF As usual, split the schema to move the attributes of the troublesome FD to another relation, leaving its determinant in the original so they remain connected not always attainable Universal Relation: One way to think about DB design is to imagine that we begin with the universal relation and normalize the schema to whatever level we like theoretically interesting partially usable should not be the only tool in one s DB design Spring 00 CSC 74: DBMS by Dr. Peng Ning 50 Spring 00 CSC 74: DBMS by Dr. Peng Ning 53 Student Course Instructor Spring 00 CSC 74: DBMS by Dr. Peng Ning 5 9