44220: Database Design & Implementation Avoiding Database Anomalies Ian Perry Room: C49 Tel Ext.: 7287

Slides:



Advertisements
Similar presentations
ER Model For a college DB
Advertisements

Relational data integrity
1 Term 2, 2004, Lecture 2, Normalisation - IntroductionMarian Ursu, Department of Computing, Goldsmiths College Normalisation Introduction.
Database Design: ER Modelling (Continued)
44220: Database Design & Implementation ER Diagramming
Conceptual Design using the Entity-Relationship Model
the Entity-Relationship (ER) Model
Chapter 2.1 V3.1 Napier University Dr Gordon Russell
44241: Dissertation Oral Presentation? Ian Perry
44212: Web-site Development What is a Web Development Plan? Ian Perry Room:C49 Extension:7287
44212: Web-site Development Planning & Building a Web-site Ian Perry Room:C48 Extension:7287
CSCI3170 Introduction to Database Systems
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 15 – RELATIONAL DATABASES SEAN J. TAYLOR.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Module 2 Designing a Logical Database Model. Module Overview Guidelines for Building a Logical Database Model Planning for OLTP Activity Evaluating Logical.
Normalisation Ensuring data integrity in database design 1.
Monash University Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Entity-Relationship Model and Diagrams (continued)
1 NORMALISATION. 2 Introduction Overview Objectives Intro. to Subject Why we normalise 1, 2 & 3 NF Normalisation Process Example Summary.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Project and Data Management Software
LOGICAL DATABASE DESIGN
Database Design & ER Diagrams
Chapter 14 & 15 Conceptual & Logical Database Design Methodology
Entity-Relationship Design
N. J. Taylor Database Management Systems (DBMS) 1.
Entity Relationship Model Chapter 6. Basic Elements of E-R Model Entity Object of the real world that stores data. Eg. Customer, State, Project, Supplier,
44220: Database Design & Implementation Review & Assignment 1
Daniel AdinugrohoDatabase Programming 1 DATABASE PROGRAMMING Lecture on 29 – 04 – 2005.
44220: Database Design & Implementation Logical Data Modelling Ian Perry Room: C48 Tel Ext.: 7287
Week 6 Lecture Normalization
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
CREATE THE DIFFERENCE Normalisation (special thanks to Janet Francis for this presentation)
Introduction to Normalization CPSC 356 Database Ellen Walker Hiram College.
CSCI 3140 Module 2 – Conceptual Database Design Theodore Chiasson Dalhousie University.
Introduction to Database Systems Mapping ER Models to Relational Schemas Irvanizam Zamanhuri, M.Sc Informatics (Computer Science) Study Program Syiah Kuala.
Concepts and Terminology Introduction to Database.
44220: Database Design & Implementation Review & Assignment 2 Ian Perry Room: C49 Tel Ext.: 7287
CBAD2103 Data Analysis and Modeling. Chapter 7 Conceptual Design Methodology.
44220: Database Design & Implementation Implementing Physical Domains Ian Perry Room: C49 Tel Ext.: 7287
Normalization (Codd, 1972) Practical Information For Real World Database Design.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Chapters 15 &16 Conceptual and Logical Database Design Methodology.
44220: Database Design & Implementation Modelling the ‘Real’ World Ian Perry Room: C41C Ext.: 7287
Database Systems Module Review
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
44220: Database Design & Implementation Review & Assignment 2 Ian Perry Room: C41C Tel Ext.: 7287
WXGE 6101 DATABASE CONCEPTS & IMPLEMENTATIONS. Lesson Overview The Relational Model Terminology of relational model. Properties of database relations.
44220: Database Design & Implementation Implementing Physical Domains Ian Perry Room: C41C Tel Ext.: 7287
Information Access Mgt09/12/971 Entity-Relationship Design Information Level Design.
44271: Database Design & Implementation Logical Data Modelling (Avoiding Database Anomalies) Ian Perry Room: C49 Tel Ext.: 7287
44220: Database Design & Implementation Conceptual Data Modelling Ian Perry Room: C49 Tel Ext.: 7287
Agenda  TMA01  M876 Block 2 Relational Theory. Data Modeling.
Database Systems Avoiding Database Anomalies Tutor:Ian Perry Tel: Web:
Conceptual Design to Logical Design Lecture 4. Aims  To introduce Business Rules  To identify what a Business Rule is  To Introduce Business Operations.
DBMS ER model-2 Week 6-7.
44271: Database Design & Implementation Physical Data Modelling Ian Perry Room: C49 Tel Ext.: 7287
Database Systems Logical Data Modelling Tutor:Ian Perry Tel: Web:
1 CS 430 Database Theory Winter 2005 Lecture 7: Designing a Database Logical Level.
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
44220: Database Design & Implementation Review & Assignment 2 Ian Perry Room: C41C Tel Ext.: 7287
April 20022/CS/3X1 Database Design Design method John Wordsworth Department of Computer Science The University of Reading Room.
Let try to identify the conectivity of these entity relationship
Translation of ER-diagram into Relational Schema
Entity-Relationship Model and Diagrams (continued)
Entity relationship diagrams
Database Management system
Database Management system
Presentation transcript:

44220: Database Design & Implementation Avoiding Database Anomalies Ian Perry Room: C49 Tel Ext.:

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Avoiding Database Anomalies This lecture concentrates upon building a ‘robust’ Logical Data Model. i.e.: Transforming a Conceptual Data Model into a set of Relations. Checking these Relations for any Anomalies. Documenting them as a Database Schema. Most Database books have a section describing a mathematically-based technique called Normalisation: I will show you a much easier way of achieving the same result, i.e. a robust database design.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies What is an Anomaly? Anything we try to do with a database that leads to unexpected and/or unpredictable results. Three types of Anomaly to guard against: insert delete update Need to check your database design carefully: the only good database is an anomaly free database.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Insert Anomaly When we want to enter a value into a data cell but the attempt is prevented, as another value is not known.  e.g. We have built a new Room (e.g. B123), but it has not yet been timetabled for any courses or members of staff.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Delete Anomaly When a value we want to delete also means we will delete values we wish to keep.  e.g. CoNo 351 has ended, but Room C320 will be used elsewhere.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Update Anomaly When we want to change a single data item value, but must update multiple entries  e.g. Room H940 has been improved, it is now of RSize = 500.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies A Conceptual Model Consider the following ‘simple’ conceptual data model: Staff(Staff-ID, Name, Address, ScalePoint, RateOfPay, DOB,...) Student(Enrol-No, Name, Address, OLevelPoints,...) Course(CourseCode, Name, Duration,...) Staff Course Student 1MMM

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies The ‘Translation’ Process Entities become Relations Attributes become Attributes(?) Key Attribute(s) become Primary Key(s) Relationships are represented by additional Foreign Key Attributes: for those Relations that are at the ‘M’ end of each 1:M Relationship.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies The ‘Staff’ & ‘Student’ Relations Staff(Staff-ID, Name, Address, ScalePoint, RateOfPay, DOB,...) becomes: Staff Student(Enrol-No, Name, Address, OLevelPoints,...) becomes: Student NB. Foreign Key Tutor references Staff.Staff-ID

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies The ‘Staff’ & ‘Course’ Relations Course(CourseCode, Name, Duration,...) becomes: Course NB. Can’t add a Foreign Key; as BOTH Relations have a ‘M’ end:  I warned you about leaving M:M relationships in your Conceptual Data Model.  Must create an ‘artificial’ linking Relation. Staff

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies ‘ Staff’, ‘Course’ & ‘Team’ Relations NB. In the ‘artificial’ Relation (i.e. Team): The Primary Key is a composite of CourseCode & Staff-ID Foreign Key CourseCode references Course.CourseCode Foreign Key Staff-ID references Staff.Staff-ID Team Course Staff

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies 4 Relations from 3 Entities? BUT - are they anomaly free? Student Team Course Staff

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Check Relations for Anomalies! every Tuple unique? no hidden meaning from location? data cells atomic? for Relations with single-attribute keys: every Attribute depends upon the Primary Key? for Relations with composite keys: every Attribute depends upon all of the Composite Key?

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies What if the checks fail? If any Relation fails ‘checks’: especially those checking dependency. we MUST split that Relation into multiple Relations: until they pass the tests. but MUST remember to leave behind a Foreign Key: to ‘point’ forwards to the Primary Key of the ‘new’ split-off Relation.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Are they Anomaly Free? Student Team Course Staff NOT this one! as RateOfPay does NOT depend upon Staff-ID

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Fixing this ‘Problem’ The Attribute ‘RateOfPay’ depends upon ‘ScalePoint’ NOT ‘Staff-ID’. So, we need to split this Relation: NB. Foreign Key ScalePoint references Pay.ScalePoint Staff Pay Staff

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies 5 Relations from 3 Entities Student Team Course Pay Staff an ‘artificial’ Relation - to ‘solve’ a M:M ‘problem’ a ‘split-off’ Relation - to ‘solve’ a Dependency ‘problem’

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Don’t change Conceptual Model Remember, we can chose from one of a range of Database Theories with which to build our Logical Data Model: Hierarchical Relational Object Each of these Database Theories may require different compromises (i.e. at the Logical Modelling stage); from the ‘pure’ meaning captured by your Conceptual Model.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Document Relations as a Database Schema A Database Schema: defines all Relations, lists all Attributes (with their Domains), and identifies all Primary & Foreign Keys. We should have ‘captured’ the Business situation (assumptions and constraints) in the Conceptual Data Model, e.g: a College only delivers 10 Courses. a Hospital only has 12 Wards. These assumptions and constraints need to be expressed as the Domains of the Database Schema.

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Logical Schema 1 - Domains Schema College Domains StudentIdentifiers = ; StaffIdentifiers = ; PersonNames = TextString (15 Characters); Addresses = TextString (25 Characters); CourseIdentifiers = ; CourseNames = Comp, IS, Law, Mkt,...; OLevelPoints = ; ScalePoints = ; PayRates = £14,005, £14,789, £15,407,...; StaffBirthDates = Date (dd/mm/yyyy), >21 Years before Today;

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Logical Schema 2 - Relations Relation Student Enrol-No: StudentIdentifiers; Name: PersonNames; Address: Addresses; OLevelPoints: OLevelPoints; Tutor: StaffIdentifiers; Primary Key: Enrol-No Foreign Key Tutor references Staff.Staff-ID

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Logical Schema 3 - Relations Relation Staff Staff-ID: StaffIdentifiers; Name: PersonNames; Address: Addresses; ScalePoint: ScalePoints; DOB: StaffBirthDates; Primary Key: Staff-ID Foreign Key ScalePoint references Pay.ScalePoint

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies Logical Schema... Relation Course CourseCode: CourseIdentifiers; Name: CourseNames; … etc. Continue to define each of the Relations in a similar manner. All Relations MUST have a Primary Key. Any Relation at the M-end of a 1:M Relationship MUST have a Foreign Key. Make sure that you define ALL of the Relations, including: ‘artificial’ ones (e.g. Team) ‘split-off’ ones (e.g. Pay)

Ian PerrySlide : Database Design & Implementation: Avoiding Database Anomalies This Week’s Workshop In this Workshops session we will; 1. test a logical data model; to ensure that it is anomaly free (i.e. robust), 2. practice documenting a Database Schema; based on a small conceptual model (as represented by an ER Diagram). 1.Examine a table of data: Explain the ‘potential’ for insert, delete & update anomalies in a table of data. Define what a ‘better’ set of tables (Relations?) to store the data look like? 2.Examine an ER Diagram: Identify suitable Attributes for each Relation; as a minimum those that will act as the Primary & Foreign Keys. Document as a Database Schema; starting with the Relations first, then coming back to document suitable Domains.