44271: Database Design & Implementation Logical Data Modelling (Avoiding Database Anomalies) Ian Perry Room: C49 Tel Ext.: 7287

Slides:



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

Database Systems: Design, Implementation, and Management Tenth Edition
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Monash University Week 7 Data Modelling Relational Database Theory IMS1907 Database Systems.
1 Basic DB Terms Data: Meaningful facts, text, graphics, images, sound, video segments –A collection of individual responses from a marketing research.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Week 2 Lecture 2 Structure of a database. External Schema Conceptual Schema Internal Schema Physical Schema.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
LOGICAL DATABASE DESIGN
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Chapter 14 & 15 Conceptual & Logical Database Design Methodology
Entity-Relationship Design
Database Design.  Define a table for each entity  Give the table the same name as the entity  Make the primary key the same as the identifier of the.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
44220: Database Design & Implementation Review & Assignment 1
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Module Title? DBMS E-R Model to Relational Model.
44220: Database Design & Implementation Logical Data Modelling Ian Perry Room: C48 Tel Ext.: 7287
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Week 6 Lecture Normalization
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
By: M.Nadeem Akhtar1 The Data Base Management System (DBMS) Ch # 09.
Introduction to Normalization CPSC 356 Database Ellen Walker Hiram College.
Web-Enabled Decision Support Systems
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Introduction to SQL Steve Perry
Concepts and Terminology Introduction to Database.
44220: Database Design & Implementation Review & Assignment 2 Ian Perry Room: C49 Tel Ext.: 7287
MIS 301 Information Systems in Organizations Dave Salisbury ( )
CODD’s 12 RULES OF RELATIONAL DATABASE
44220: Database Design & Implementation Implementing Physical Domains Ian Perry Room: C49 Tel Ext.: 7287
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
44220: Database Design & Implementation Modelling the ‘Real’ World Ian Perry Room: C41C Ext.: 7287
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
IE 423 – Design of Decision Support Systems Data modeling and database development.
Unit 4 Object Relational Modeling. Key Concepts Object-Relational Modeling outcomes and process Relational data model Normalization Anomalies Functional.
M1G Introduction to Database Development 4. Improving the database design.
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
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.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
44220: Database Design & Implementation Conceptual Data Modelling Ian Perry Room: C49 Tel Ext.: 7287
Agenda  TMA01  M876 Block 2 Relational Theory. Data Modeling.
44220: Database Design & Implementation Introduction to Module Ian Perry Room: C49 Ext.: 7287
Database Systems Avoiding Database Anomalies Tutor:Ian Perry Tel: Web:
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.
IE 423 – Design of Decision Support Systems Data modeling and database development.
The relational model1 The relational model Mathematical basis for relational databases.
Lecture 4: Logical Database Design and the Relational Model 1.
Logical Database Design and Relation Data Model Muhammad Nasir
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
44220: Database Design & Implementation Introduction to Module Ian Perry Room: C41C Ext.: 7287
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
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.
Logical Database Design and the Rational Model
Chapter 4 Relational Databases
The Relational Database Model
Presentation transcript:

44271: Database Design & Implementation Logical Data Modelling (Avoiding Database Anomalies) Ian Perry Room: C49 Tel Ext.:

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling What is a Logical Data Model? A ‘robust’ representation of the initial decisions made when building our Conceptual Data Model, which was composed of: Entities Attributes Relationships When I say ‘robust’ I mean that this model MUST ‘perform’ well with respect to a specific style/type of software.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Database Theories & Software Hardware independent, the match to ‘type’ of software is only concern, e.g.: Hierarchical DBMS Relational DBMS Object-based DBMS Each Database Theory addresses: Data Structure Data Integrity Data Manipulation

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Database Theory = Relational Model First proposed by Dr. E. F. Codd in June Codd E F, (1970), A Relational Model of Data for Large Shared Data Banks, Communications of the ACM, Vol. 13, No. 6, Pgs 377 – 387. Codd's model is now accepted as the definitive model for relational database management systems (RDBMS). Structured English QUEry Language ("SEQUEL") was developed by IBM Corporation, Inc., to use Codd's model. SEQUEL later became SQL. In 1979, Relational Software, Inc. (now Oracle Corporation) introduced the first commercial implementation of SQL. SQL is the most widely used RDBMS manipulation language.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Relations look like Entities, but … Entity Staff(SCode, Name, Address, DoB, …) May discover requirement for ‘extra’ Attributes, and also need to ‘complete’ our list of Attributes for each Relation. Relation Staff(SCode, Name, Address, DoB, DoE) Entity Contract(CCode, Site, Begin, End, …) Can’t draw relationship lines, so need to ‘add’ extra attributes to Relations at the ‘M’ end of any ‘1:M’ relationships; e.g. 1 Staff “take part in” M Contract. Relation Contract(CCode, Site, Begin, End, SCode)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Use Tables to ‘flesh-out’ your Logical Model Staff(SCode, Name, Address, DoB, DoE)  Contract (CCode, Site, Begin, End, SCode)  NB. Tables ARE NOT Relations!

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Primary & Foreign Keys Most important Attributes in a Relation are know as ‘Keys’: of which there are two types. Primary Key: One, or more, Attribute(s) that identify a unique occurrence of the ‘Entity’ that this ‘Relation’ represents. Foreign Key: Attributes used (i.e. instead of the lines of an ER Diagram) to represent the presence of relationships. Often referred to as: The Primary/Foreign Key Mechanism.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Attributes, Domains & Relationships Attribute Values should be atomic (i.e. simple/single values only); e.g.: ‘address’ should be separated into ‘street’ & ‘town’ & ‘postcode’. Set of eligible Attribute Values is known as an Attribute’s Domain; e.g.: if we only have 100 members of staff, then the Domain of the ‘SCode’ Attribute could be “whole numbers between 1 & 100”. The Relational Model is weak at explicitly modelling relationships: Attributes in different Relations MUST HAVE same Attribute Domain for relationship to be possible.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Codd’s Rules Each Tuple (i.e. row) MUST BE unique, i.e.: need a way to discriminate between Tuples. Therefore: each Relation MUST HAVE a Primary Key. There may be many Candidates for the job of Primary Key, so select on basis of: uniqueness AND/OR minimality. Keys with more than one Attribute: are know as composite keys.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Rules for Integrity No Attribute that is part of the Primary Key can assume a ‘null’ value, else: how could we discriminate between Tuples? Foreign Key Attributes must take values that are either ‘null’, or from same Domain as the Primary Key Attribute to which they are logically linked, else: we will lose the possibility of making relationships.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Avoiding Database Anomalies 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. What we want to achieve is a ‘robust’ Logical Data Model; i.e. by: Transforming a Conceptual Data Model into a set of Relations. Checking these Relations for any Anomalies. Documenting them as a Database Schema.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling What is an Anomaly? Anything we try to do with a database that may lead to unexpected and/or unpredictable results. Three types of Anomaly; i.e.: insert delete update Need to check your database design carefully: the only good database is an anomaly free database.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Insert Anomaly When we want to enter a value into a data cell but the attempt is prevented, as the primary key 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 (so we don’t have a CoNo value).

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling 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: Logical Data Modelling 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: Logical Data Modelling Conceptual Model & Translation Process Conceptual Model: Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB,...) Student(Enrol-No, Name, Address, OLevelPoints,...) Course(CourseCode, Name, Duration,...) Staff Course Student 1MMM  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: Logical Data Modelling The ‘Staff’ & ‘Student’ Relations Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB,...) becomes: Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB) Student(Enrol-No, Name, Address, OLevelPoints,...) becomes: Student(Enrol-No, Name, Address, OLevelPoints, Tutor) NB. Foreign Key Tutor references Staff.Staff-ID

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling The ‘Staff’ & ‘Course’ Relations Course(CourseCode, Name, Duration,...) becomes: Course(CourseCode, Name, Duration) NB.Can’t ‘simply’ add extra attributes to act as Foreign Keys; 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(Staff-ID, Name, ScalePoint, RateOfPay, DOB)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling ‘ Staff’, ‘Course’ & ‘Team’ Relations NB.In the ‘artificial’ Team Relation: Primary Key is a ‘composite’ of CourseCode & Staff-ID Foreign Key CourseCode references Course.CourseCode Foreign Key Staff-ID references Staff.Staff-ID Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB) Course(CourseCode, Name, Duration) Team(Staff-ID, CourseCode)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling 4 Relations from 3 Entities? OK, BUT are they anomaly free? Is every Tuple unique? i.e. is there a Primary Key. Are the Attributes Atomic? i.e. do they store only ONE item of data. Does every Attribute within each Relation ‘depend’ upon the Primary Key? Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB) Course(CourseCode, Name, Duration) Team(Staff-ID, CourseCode) Student(Enrol-No, Name, Address, OLevelPoints, Tutor)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling 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: Logical Data Modelling Are they Anomaly Free? Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB) Course(CourseCode, Name, Duration) Team(Staff-ID, CourseCode) Student(Enrol-No, Name, Address, OLevelPoints, Tutor) NOT Dependent upon Staff-ID; Requires a slightly more complex ‘solution’. NOT very Atomic; Could easily be split into ‘Street’, ‘Town’ & ‘PostCode’.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling ‘Fixing’ the Dependency ‘Problem’ The Attribute ‘RateOfPay’ depends upon ‘ScalePoint’ NOT ‘Staff-ID’. So, we MUST remove ‘RateOfPay’ from the ‘Staff’ Relation, like this: NB. In the ‘Staff’ Relation: Foreign Key ScalePoint references Pay.ScalePoint Staff(Staff-ID, Name, ScalePoint, RateOfPay, DOB) Staff(Staff-ID, Name, ScalePoint, DOB) Pay(ScalePoint, RateOfPay)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling 5 Relations from 3 Entities Now all we need to do: Is to document our ‘Anomaly Free’ Relations as a Database Schema. Staff(Staff-ID, Name, ScalePoint, DOB) Course(CourseCode, Name, Duration) Team(Staff-ID, CourseCode) Student(Enrol-No, Name, Street, Town, PostCode, OLevelPoints, Tutor) Pay(ScalePoint, RateOfPay)

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling 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 may/should have ‘discovered’ a number of constraints during our analysis of the Business situation, e.g: the College only delivers 10 Courses. there are only 12 Points on the Pay Scale. Staff MUST be at least 21 Years Old. These constraints can/should be expressed as the ‘Domains’ of the Database Schema.

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Logical Schema 1 - Domains Schema College Domains StudentIdentifiers = ; StaffIdentifiers = ; GeneralNames = TextString (15 Characters); Addresses = TextString (20 Characters); PostCodes = TextString (7 or 8 Characters); CourseIdentifiers = ; OLevelPoints = ; ScalePoints = ; StaffBirthDates = Date (dd/mm/yyyy), >21 Years before Today;

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Logical Schema 2 - Relations Relation Student Enrol-No: StudentIdentifiers; Name: GeneralNames; Street: Addresses; Town: Addresses; PostCode: PostCodes; OLevelPoints: OLevelPoints; Tutor: StaffIdentifiers; Primary Key: Enrol-No Foreign Key Tutor references Staff.Staff-ID

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Logical Schema 3 - Relations Relation Staff Staff-ID: StaffIdentifiers; Name: GeneralNames; ScalePoint: ScalePoints; DOB: StaffBirthDates; Primary Key: Staff-ID Foreign Key ScalePoint references Pay.ScalePoint

Ian PerrySlide : Database Design & Implementation: Logical Data Modelling Logical Schema... Relation Course CourseCode: CourseIdentifiers; Name: GeneralNames; … etc. Continue to define each of the Relations in a similar manner. NB. 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: Logical Data Modelling This Week’s Workshop The purpose of this week’s Workshop is to practice developing ‘robust’ logical data models that conform to the ‘rules’ of Codd’s Relational Model. Exploring the ‘definition’ of Relations. Identifying potential anomalies in a Table of data, and ‘solving’ these ‘problems’. Documenting a Database Schema (i.e. a Logical Model), in the format required by Part 2 of the Assignment.