Database Management System



Similar documents
Chapter 10. Functional Dependencies and Normalization for Relational Databases

Theory of Relational Database Design and Normalization

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Theory of Relational Database Design and Normalization

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Database Design and Normalization

Chapter 10. Functional Dependencies and Normalization for Relational Databases. Copyright 2007 Ramez Elmasri and Shamkant B.

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Functional Dependency and Normalization for Relational Databases

Relational Database Design Theory

Relational Database Design

Chapter 5: FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL DATABASES

Schema Refinement, Functional Dependencies, Normalization

Database Design and Normal Forms

Functional Dependencies and Finding a Minimal Cover

Normalization for Relational DBs

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Normalisation to 3NF. Database Systems Lecture 11 Natasha Alechina

Design of Relational Database Schemas

DATABASE NORMALIZATION

Normalization in Database Design

CS143 Notes: Normalization Theory

Lecture 2 Normalization

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

Chapter 7: Relational Database Design

Schema Refinement and Normalization

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 5: Normalization II; Database design case studies. September 26, 2005

Functional Dependencies and Normalization

Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation

Week 11: Normal Forms. Logical Database Design. Normal Forms and Normalization. Examples of Redundancy

Normalization of Database

Normalization in OODB Design

Relational Database Design: FD s & BCNF

Database Management Systems. Redundancy and Other Problems. Redundancy

Functional Dependencies

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

normalisation Goals: Suppose we have a db scheme: is it good? define precise notions of the qualities of a relational database scheme

RELATIONAL DATABASE DESIGN

Boyce-Codd Normal Form

Chapter 8. Database Design II: Relational Normalization Theory

Lecture Notes on Database Normalization

MCQs~Databases~Relational Model and Normalization

Chapter 7: Relational Database Design

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

Normalization. CIS 331: Introduction to Database Systems

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

DATABASE DESIGN: NORMALIZATION NOTE & EXERCISES (Up to 3NF)

Normalisation. Why normalise? To improve (simplify) database design in order to. Avoid update problems Avoid redundancy Simplify update operations

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

Database Constraints and Design

Normalization. Functional Dependence. Normalization. Normalization. GIS Applications. Spring 2011

Normalisation and Data Storage Devices

C# Cname Ccity.. P1# Date1 Qnt1 P2# Date2 P9# Date9 1 Codd London Martin Paris Deen London

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Lecture 6. SQL, Logical DB Design

Database Systems Concepts, Languages and Architectures

Chapter 9: Normalization

Introduction to Database Systems. Chapter 4 Normal Forms in the Relational Model. Chapter 4 Normal Forms

Introduction to Database Systems. Normalization

Fundamentals of Database System

Theory behind Normalization & DB Design. Satisfiability: Does an FD hold? Lecture 12

Normalisation 1. Chapter 4.1 V4.0. Napier University

Advanced Relational Database Design

BCA. Database Management System

Figure 14.1 Simplified version of the

Design Theory for Relational Databases: Functional Dependencies and Normalization

DATABASE SYSTEMS. Chapter 7 Normalisation

Determination of the normalization level of database schemas through equivalence classes of attributes

DATABASE DESIGN: Normalization Exercises & Answers

Normalisation 6 TABLE OF CONTENTS LEARNING OUTCOMES

Normal forms and normalization

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

LOGICAL DATABASE DESIGN

Chapter 6. Database Tables & Normalization. The Need for Normalization. Database Tables & Normalization

Database Management Systems 2015

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Conceptual Design Using the Entity-Relationship (ER) Model

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Normalisation in the Presence of Lists

Jordan University of Science & Technology Computer Science Department CS 728: Advanced Database Systems Midterm Exam First 2009/2010

Normalization of database model. Pazmany Peter Catholic University 2005 Zoltan Fodroczi

How To Find Out What A Key Is In A Database Engine

Normalization. Normalization. Normalization. Data Redundancy

Topic 5.1: Database Tables and Normalization

Module 5: Normalization of database tables

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Unit 3.1. Normalisation 1 - V Normalisation 1. Dr Gordon Russell, Napier University

Objectives of Database Design Functional Dependencies 1st Normal Form Decomposition Boyce-Codd Normal Form 3rd Normal Form Multivalue Dependencies

3. Database Design Functional Dependency Introduction Value in design Initial state Aims

Limitations of DB Design Processes

UNDERSTANDING NORMALIZATION

Normalization. Normalization. First goal: to eliminate redundant data. for example, don t storing the same data in more than one table

Database Normalization. Mohua Sarkar, Ph.D Software Engineer California Pacific Medical Center

The Relational Database Model

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Transcription:

UNIT -6 Database Design Informal Design Guidelines for Relation Schemas; Functional Dependencies; Normal Forms Based on Primary Keys; General Definitions of Second and Third Normal Forms; Boyce-Codd Normal Form. Fourth Normal Form; and Fifth Normal Form; INFORMAL DESIGHN GUIDELINES FOR RELATIONAL SCHEMA 1.Semantics of the Attributes 2.Reducing the Redundant Value in Tuples. 3.Reducing Null values in Tuples. 4.Dissallowing spurious Tuples. 1. Semantics of the Attributes Whenever we are going to form relational schema there should be some meaning among the attributes.this meaning is called semantics.this semantics relates one attribute to another with some relation. Eg: USN No Student name Sem 2. Reducing the Redundant Value in Tuples Mixing attributes of multiple entities may cause problems Information is stored redundantly wasting storage Problems with update anomalies Insertion anomalies Deletion anomalies Modification anomalies VTU-EDUSAT Page 1

The main goal of the schema diagram is to minimize the storage space that the base memory occupies.grouping attributes information relations has asignificant effect on storage space. Eg; USN No Student name Sem Eg: Dept No Dept Name If we integrate these two and is used as a single table i.e Student Table USN No Student name Sem Dept No Dept Name Here whenever if we insert the tuples there may be N stunents in one department,so Dept No,Dept Name values are repeated N times which leads to data redundancy. Another problem is updata anamolies ie if we insert new dept that has no students. If we delet the last student of a dept,then whole information about that department will be deleted If we change the value of one of the attributes of aparticaular table the we must update the tuples of all the students belonging to thet depy else Database will become inconsistent. Note: Design in such a way that no insertion,deletion,modification anamolies will occur 3. Reducing Null values in Tuples. Note: Relations should be designed such that their tuples will have as few NULL values as possible Attributes that are NULL frequently could be placed in separate relations (with the primary key) Reasons for nulls: attribute not applicable or invalid attribute value unknown (may exist) VTU-EDUSAT Page 2

value known to exist, but unavailable 4. Disallowing spurious Tuples Bad designs for a relational database may result in erroneous results for certain JOIN operations The "lossless join" property is used to guarantee meaningful results for join operations Note: The relations should be designed to satisfy the lossless join condition. No spurious tuples should be generated by doing a natural-join of any relations. Functional dependency 1. Functional dependencies (FDs) are used to specify formal measures of the "goodness" of relational designs 2. FDs and keys are used to define normal forms for relations 3. FDs are constraints that are derived from the meaning and interrelationships of the data attributes 4. X->Y : A set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for Y 5. X -> Y holds if whenever two tuples have the same value for X, they must have the same value for Y 6. For any two tuples t1 and t2 in any relation instance r(r): If t1[x]=t2[x], then t1[y]=t2[y] 7. X -> Y in R specifies a constraint on all relation instances r(r) 8. Written as X -> Y; can be displayed graphically on a relation schema as in Figures. ( denoted by the arrow: ). 9. FDs are derived from the real-world constraints on the attributes 10. social security number determines employee name SSN -> ENAME 11.project number determines project name and location PNUMBER -> {PNAME, PLOCATION} 11. employee ssn and project number determines the hours per week that the employee works on the project VTU-EDUSAT Page 3

{SSN, PNUMBER} -> HOURS Inference rules for FDs: Inference rules also known as Armstrong's Axioms are published by Armstrong. These properties are as given below: 1. Reflexivity property: X ->Y is true if Y is subset of X. 2. Augmentation property: If X->Y is true, then XZ ->YZ is also true. 3. Transitivity property: If X->Y and Y->Z then X ->Z is implied. 4. Union property: If X ->Y and X ->Z are true, then X ->YZ is also true. This property indicates that if right hand side of FD contains many attributes then FD exists for each of them. 5. Decomposition property: If X ->Y is implied and Z is subset of Y, then X ->Z is implied. This property is the reverse of union property. 6. Pseudotransitivity property: If X ->Y and WY ->Z are given, then XW ->Z is true. Normalization: Normalizing the database ensures the following things: Dependencies between data are identified. Redundant data is minimized. The data model is flexible and easier to maintain Normalization: The process of decomposing unsatisfactory "bad" relations by breaking up their attributes into smaller relations Normal form: Condition using keys and FDs of a relation to certify whether a relation schema is in a particular normal form VTU-EDUSAT Page 4

FIRST NORMAL FORM Database Management System The purpose of first normal form (1NF) is to eliminate repeating groups of attributes in an entity. Disallows composite attributes, multivalued attributes, and nested relations; attributes whose values for an individual tuple are non-amanjuic Consider the following table: SECOND NORMAL FORM The purpose of second normal form (2NF) is to eliminate partial key dependencies. Each attribute in an entity must depend on the whole key, not just a part of it. VTU-EDUSAT Page 5

THIRD NORMAL FORM Third Normal form also helps to eliminate redundant information by eliminating interdependencies between non-key attributes. It is already in 2NF There are no non-key attributes that depend on another non-key attribute VTU-EDUSAT Page 6

General Normal Form Definitions (For Multiple Keys) The above definitions consider the primary key only The following more general definitions take into account relations with multiple candidate keys A relation schema R is in second normal form (2NF) if every non-prime attribute A in R is fully functionally dependent on every key of R Definition: Superkey of relation schema R - a set of attributes S of R that contains a key of R A relation schema R is in third normal form (3NF) if whenever a FD X -> A holds in R, then either: X is a superkey of R, or A is a prime attribute of R Example 1 CUSTOMER CustomerID Firstname Surname City PostCode 12123 Harry Enfield London SW7 2AP 12443 Leona Lewis London WC2H 7JY 354 Sarah Brightman Coventry CV4 7AL VTU-EDUSAT Page 7

This is not in strict 3NF as the City could be obtained from the Post code attribute. If you create a table containing postcodes then city could be derived. CustomerID Firstname Surname PostCode* 12123 Harry Enfield SW7 2AP 12443 Leona Lewis WC2H 7JY 354 Sarah Brightman CV4 7AL POSTCODES PostCode SW7 2AP WC2H 7JY CV4 7AL City London London Coventry Example 2. VideoID Title Certificate Description 12123 Saw IV 18 Eighteen and over 12443 Igor PG Parental Guidance 354 Bambi U Universal Classification The Description of what the certificate means could be obtained frome the certifcate attribute - it does not need to refer to the primary key VideoID. So split it out and use the primary key / secondary key approach. Example 3 CLIENT ClientID CinemaID* CinemaAddress 12123 LON23 1 Leicester Square. London 12443 COV2 34 Bramby St, Coventry 354 MAN4 56 Croydon Rd, Manchester CINEMAS CinemaID LON23 CinemaAddress 1 Leicester Square. London VTU-EDUSAT Page 8

COV2 MAN4 34 Bramby St, Coventry 56 Croydon Rd, Manchester In this case the database is almost in 3NF - for some reason the Cinema Address is being repeated in the Client table, even though it can be obtained from the Cinemas table. So simply remove the column from the client table BOYCE-CODD NORMAL FORM (BCNF) A relation schema R is in Boyce-Codd Normal Form (BCNF) if whenever an FD X -> A holds in R, then X is a superkey of R Each normal form is strictly stronger than the previous one Every 2NF relation is in 1NF Every 3NF relation is in 2NF Every BCNF relation is in 3NF There exist relations that are in 3NF but not in BCNF The goal is to have each relation in BCNF (or 3NF) Definition: A multivalued dependency (MVD) X >> Y specified on relation schema R, where X and Y are both subsets of R, specifies the following constraint on any relation state r of R: If two tuples t1 and t2 exist in r such that t1[x] = t2[x], then two tuples t3 and t4 should also VTU-EDUSAT Page 9

exist in r with the following properties, where we use Z to denote (R - (X υ Y)): t3[x] = t4[x] = t1[x] = t2[x]. t3[y] = t1[y] and t4[y] = t2[y]. t3[z] = t2[z] and t4[z] = t1[z]. An MVD X >> Y in R is called a trivial MVD if (a) Y is a subset of X, or (b) X υ Y = R. Fourth Normal Form (4NF) Fourth normal form eliminates independent many-to-one relationships between columns. To be in Fourth Normal Form, a relation must first be in Boyce-Codd Normal Form. a given relation may not contain more than one multi-valued attribute. Defined as a relation that is in Boyce-Codd Normal Form and contains no nontrivial multi-valued dependencies. Example VTU-EDUSAT Page 10

Fifth Normal Form (5NF) A relation decompose into two relations must have the lossless-join property, which ensures that no spurious tuples are generated when relations are reunited through a natural join operation. However, there are requirements to decompose a relation into more than two relations. Although rare, these cases are managed by join dependency and fifth normal form (5NF). Constraints as Assertions VTU-EDUSAT Page 11

General constraints: constraints that do not fit in the basic SQL categories Mechanism: CREAT ASSERTION Components include: a constraint name, followed by CHECK, followed by a condition Assertions: An Example The salary of an employee must not be greater than the salary of the manager of the department that the employee works for CREAT ASSERTION SALARY_CONSTRAINT CHECK (NOT EXISTS (SELECT * FROM EMPLOYEE E, EMPLOYEE M, DEPARTMENT D WHERE E.SALARY > M.SALARY AND E.DNO=D.NUMBER AND D.MGRSSN=M.SSN)) SQL Triggers Objective: to monitor a database and take initiate action when a condition occurs Triggers are expressed in a syntax similar to assertions and include the following:event Such as an insert, deleted, or update operation Condition Action To be taken when the condition is satisfied SQL Triggers: An Example A trigger to compare an employee s salary to his/her supervisor during insert or update operations: CREATE TRIGGER INFORM_SUPERVISOR BEFORE INSERT OR UPDATE OF SALARY, SUPERVISOR_SSN ON EMPLOYEE FOR EACH ROW WHEN (NEW.SALARY> (SELECT SALARY FROM EMPLOYEE WHERE SSN=NEW.SUPERVISOR_SSN)) INFORM_SUPERVISOR (NEW.SUPERVISOR_SSN,NEW.SSN); VTU-EDUSAT Page 12