Section 11ER Tables1 HSQ - DATABASES & SQL And Franchise Colleges 11 ER Tables By MANSHA NAWAZ.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

Chapter 5 Normalization of Database Tables
Chapter 5 Normalization of Database Tables
Designing tables from a data model (Chapter 6) One base table for each entity.
Section 09ER Decomposition Of Many To Many1 HSQ - DATABASES & SQL And Franchise Colleges 09 ER Decomposition of Many-to-Many.
DENORMALIZATION CSCI 6442 © Copyright 2015, David C. Roberts, all rights reserved.
Data Modeling (CB 12) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
ENTITY RELATIONSHIP MODELLING
Section 07 (a)DFD to ERD Link1 HSQ - DATABASES & SQL By MANSHA NAWAZ 07 (a) - DFD to ERD Link And Franchise Colleges.
Revised by Ivor Perry Sept Introduction to Data Modelling.
Topic Denormalisation S McKeever Advanced Databases 1.
ER Modelling III Example Digital Voice Systems Data Modelling Deriving Tables Types Mapping to SQL DDL.
Chapter 2 The Relational Database Model
The Relational Database Model:
LIS 557 Database Design and Management William Voon Michael Cole Spring '04.
Lecture 10 Conversion to tables Database Design Concepts INFO1408.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design Concepts Lecture 7 Introduction to E:R Modelling Identifying Entities.
LOGICAL DATABASE DESIGN
Entity/Relationship Modelling
Logical Database Design Nazife Dimililer. II - Logical Database Design Two stages –Building and validating local logical model –Building and validating.
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.
Section 07Entity Relationship Diagrams1 07 Entity Relationship Diagrams (ERD) A Data Modelling Case Tool HSQ - DATABASES & SQL And Franchise Colleges By.
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,
The Relational Database Model
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
IT 244 Database Management System Data Modeling 1 Ref: A First Course in Database System Jeffrey D Ullman & Jennifer Widom.
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.
Chapter 4 The Relational Model.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
Concepts and Terminology Introduction to Database.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
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.
In this chapter, you learn about the following: ❑ Anomalies ❑ Dependency and determinants ❑ Normalization ❑ A layman’s method of understanding normalization.
The Data in a Relation To consider atomic data in relations; To consider data types in a relation; To consider missing data & NULLs in relations. Objectives.
The Relational Database Model
Section 05Concepts Of DBMS1 HSQ - DATABASES & SQL And Franchise Colleges 05 Concepts of DBMS By MANSHA NAWAZ.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1.  An introduction to data modelling  The purpose of data modelling  Modelling data relationships 2.
M1G Introduction to Database Development 2. Creating a Database.
1. Objectives At the end of this chapter you should be able to:  Discuss the use and features of a data model  Define the terms entity and attribute.
Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company.
M1G Introduction to Database Development 5. Doing more with queries.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
M1G Introduction to Database Development 4. Improving the database design.
In this session, you will learn to: Map an ER diagram to a table Objectives.
Database Systems, 9th Edition 1.  In this chapter, students will learn: That the relational database model offers a logical view of data About the relational.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Dr Gordon Russell, Napier University Data Analysis 3 - V2.0 1 Data Analysis 3 Unit 2.3.
Data Analysis 3 Chapter 2.3 V3.0 Napier University Dr Gordon Russell.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
Home Work. Design Principles and Weak Entity Sets.
A337 - Reed Smith1 Structure What is a database? –Table of information Rows are referred to as records Columns are referred to as fields Record identifier.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Flat Files Relational Databases
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 2 © Akhilesh Bajaj, 2000, 2002, 2003, 2004,
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
Sample Table Standard Notation Entity name in uppercase
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
1 Entity Relationship Approach u Top-down approach to data modeling u Uses diagrams u Normalization - confirms technical soundness u Entity Relationship.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Year 12 > 13 Applied GCE ICT Unit 7 Using Database Software.
Decision Analysis Fall Term 2015 Marymount University School of Business Administration Professor Suydam Week 10 Access Basics – Tutorial B; Introduction.
The Relational Database Model
Relational Database Model
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
From conceptual to relational data model
Database Management system
Presentation transcript:

Section 11ER Tables1 HSQ - DATABASES & SQL And Franchise Colleges 11 ER Tables By MANSHA NAWAZ

Section 11ER Tables2 Introduction In this lecture we will explore how the structure of relational tables can be determined from an ERD. The tables produced from an ERD are said to be well-normalised. –This assumes a reasonable correctness of model. First we will look at the detail of determining table structure for various permutations of degree of association and membership class. Then look at a simple technique for deriving a set of tables from an large ERD.

Section 11ER Tables3 1:1 Obligatory:Obligatory Every employee works on exactly one machine, and every machine is worked on by exactly one employee –this can be collapsed into one table Emp (emp#, emp_name,….., machine#, machine_location……..) Basically avoid this pattern - it means the two entities are really the same thing usually - very rare anyway. EmployeeMachine works on 1 1 

Section 11ER Tables4 1:1 Non-Obligatory:Obligatory Since there may be employees without machines then Employee table must exist independently. However, since every machine has exactly one employee, then the relationship can be represented by a Foreign Key reference to Employee table within the Machine table Emp (emp#, …….) Machine (machine#, emp#, …...) This is called POSTING the Primary Key of Employee into Machine –Thus forming the Foreign Key EmployeeMachine works on 1 1   Post

Section 11ER Tables5 1:1 Non-Obligatory:Non-Obligatory Since there may be employees without machines and machines without employees, then both the Employee and Machines tables must exist independently Therefore, the relationship must be represented by a new table Emp (emp#, …….) Machine (machine#, …….., ) Works_on (emp#, machine#, ……..) or Works_on (emp#, machine#, ……..) Either can be the identifier. We can’t use POSTING. Employee Machine works on 11 

Section 11ER Tables6 1:M - many end obligatory The ‘one’ dot is irrelevant to the tables. However, since every Machine has exactly one Employee, the relationship can be represented by a Foreign Key reference to Employee table We can use POSTING.. Emp (emp#, …….) Machine (machine#, emp#, ……..) This is the most common pattern on any ERD. EmployeeMachine works on M 1   Post

Section 11ER Tables7 1:M - Many end Non-Obligatory The only thing that influences the number of tables to produce is the class of the “M” end of the relationship –When obligatory, then two tables needed –If non-obligatory, then three tables are required We can’t use POSTING so we need a relationship table. Put the Primary Keys from either end in the new table. Emp (emp#, …….) Machine: (machine#, ……..) Works_on (machine#, emp#, ……..) For a 1:m relationship table the many end always provides the Primary Key. –Why?(Clue - exactly 1) Employee Machine works on M 1  

Section 11ER Tables8 M:M Relationships Irrespective of the membership classes, three tables are always produced in these relationships However, all m:m relationships should have been dealt with during modelling. Refer to the lecture on Complex Entities. You should already have, for each complex entity: Name Primary Key Attributes Description Employee Machine works on MM  

Section 11ER Tables9 A Technique for Deriving Tables from an ERD Assuming we have already determined that the primary key for the complex entity Treatment is: Treatment(treatment-type#, admission#, date-time, …. We will use this ERD as an example for the technique. You need to assume we have just modelled a matching scenario. The observes relationship records a single staff observer for a subset of the operations.

Section 11ER Tables10 1. How many tables? The first stage is to find out how many tables are required. –Every entity requires a table. –Some of the relationships require a table. –Relationships which do not require a table are represented by POSTING. The following diagram shows how to determine the number of tables. You should already have determined the primary keys for any M:M (complex entity) before this stage. Your diagram should not show un-decomposed m:m relationships. The only dots (membership class) shown are those which affect the structure of the tables.

Section 11ER Tables11 2. Showing all the postings How many tables will we need? Seven entity tables and one relationship table (8 Tables)

Section 11ER Tables12 3. Which tables? Now we simply lay out the tables as below : Simple Entities: Admission ( Patient ( Staff ( Operation ( Operation-type ( Treatment-type ( Complex Entities: Treatment ( Relationships: Observes ( The order, simple entities, complex entities, relationships just makes the process easier.

Section 11ER Tables13 4. Identifiers The identifiers for the entity tables are usually easy. –We have often assigned a suitable identifier when we designed the entity. –At this stage we can often use a single code for an identifier. – It may be that at a later stage we change the single code identifier for something more appropriate. Simple Entities: Admission (admission#, Patient (patient#, Staff (staff#, Operation (operation#, Operation-type (op-type#, Treatment-type ( treatment-type#, Complex Entities: Treatment (treatment-type#, admission#, date-time, Relationships: Observes (

Section 11ER Tables14 4. Identifiers continued... Relationships: Observes ( The relationship table observes requires more thought. –A relationship table is created by inserting the identifying attributes from the entities involved in the relationship, in this case staff and operation. Observes(operation#, staff#,....) So what is the primary key of this table? –For a m:1 table the primary key is always the attribute or attributes contributed by the many end. Observes(operation#, staff#,....) Why is operation# an appropriate primary key?

Section 11ER Tables15 5. Postings This diagram shows all the posting (eight). The best way to carry out posting is to check each entity on the diagram and see if anything should be posted into its table. Count the postings and check you have posted everything at the end. It is very easy to miss postings when you are in a hurry. If we look at the admission entity we can see three postings into its table. –What are they? Admission(admission#, patient#, admitting.staff#, discharging.staff#,...) The prefixes sometimes are useful to indicated a primary key's role..

Section 11ER Tables16 5. Postings continued... Anything to post into Patient? –No. Anything to post into Treatment-type? –No. Anything to post into Staff? –No. Anything to post into Operation-type? –No. Anything to post into Operation? –Yes - what?. Operation (operation#, admission#, op-type#, staff#, ….) Anything to post into Treatment? –Yes but we already did that when we created the complex entity. Treatment(treatment-type#, admission#, date-time, …. From the previous slide. Admission(admission#, patient#, admitting.staff#, discharging.staff#,...) Have we done all the postings? - Count them...

Section 11ER Tables17 5. Completed posting Simple Entities: Admission (admission#, patient#, admitting.staff#, discharging.staff#....) Patient (patient#, …) Staff (staff#, …) Operation (operation#, op-type#, responsible.staff#, admission#,...) Operation-type (op-type#, …) Treatment-type (treatment-type#, …) Complex Entities: Treatment (treatment-type#, admission#, date-time, …) Relationships: Observes (operation#, staff#,....) - are these really postings too? The skeleton tables are complete.

Section 11ER Tables18 6. Assigning further attributes The technique we have just explored creates a structure into which remaining attributes can be placed. Is it easy to see where admission-date and operation-duration go? Admission (admission#, patient#, admitting.staff#, discharging.staff#....) Operation (operation#, op-type#, responsible.staff#, admission#,...) If you cannot place one or more attributes then your ERD is probably missing entities or relationships.

Section 11ER Tables19 There May Be A Need For Second Level Design Flexing first level ER Model to reflect aspects of processing and storage Three Methods: –flexing by table elimination –flexing by table splitting –flexing by introducing derived attributes Second Level is, ideally, independent of any particular implementation environment (e.g., particular DBMS such as Oracle) –no need to worry about idiosyncrasies –wasted effort where cannot support, or not using all maximum facilities available Implementation Independence

Section 11ER Tables20 Flexing by Table Elimination First level Design - tables? Treat the ward end as obligatory 10% null values, but probably reduced storage and greater transaction speeds for certain Transactions Eg: NurseWard supervises  % 95% Nurse# Name Number_years Wardname Capacity

Section 11ER Tables21 Treat both ends as obligatory Lots of null values and slower transactions in some cases, and higher storage possible, but some transactions quicker Or, something in between: –post the id of the entity and some of the attributes only –what is posted depends on the transactions required The last two flexes also apply to 1:1 non-obligatory relationships NurseWard supervises  % 95% Nurse# Name Number_years Wardname Capacity

Section 11ER Tables22 1:M Relationships First level Design - tables? Treat the M end as obligatory Null values, but probably reduced storage and greater transaction speeds for certain Transactions EmployeeProject works on  M 1 Emp# Name Number_years Proj# Description Expected_duration Hours_worked

Section 11ER Tables23 Post other attributes –Introduces more redundancy, but possibly quicker transaction speeds Treat both ends as obligatory and like a 1:1 relationship –best when close to 1:1 relationship, otherwise lots of redundancy

Section 11ER Tables24 Have a repeating group structure –Quicker transaction speeds, but relational systems do not support this traditionally. EmployeeProject works on  M 1 Emp# Name Number_years Proj# Description Expected_duration Hours_worked

Section 11ER Tables25 Fixed Number Relationships 1:M = 1:2 or 1:3 0r 1:4 –i.e.,always or of maximum fixed number e.g., there are always two members of a team: senior and junior Thus design tables as below. Project: (Proj#, ……, Senior_emp#, ….., Junior_emp#, ……)

Section 11ER Tables26 M:N Relationships First level Design - Tables? Post the identifier and possibly other attributes of the few into the many end –Problems with repeating groups PatientWard is on  M N Many Few

Section 11ER Tables27 Put attributes associated with the entities into the relationship –Redundant data, but greater transaction speeds for certain transactions If fixed maximum number then use columns for each one.

Section 11ER Tables28 Flexing by Table Splitting If certain attributes are required more than others, then could put the heavily used attributes into one table and the not so heavily used ones in another table. Group attributes according to reporting requirements NOK = Next of Kin Patient: (Patient#, Patient_name, Patient_address, …….., Patient_NOKname, Patient_NOKaddress, ……..) Becomes Patient: (Patient#, Patient_name, Patient_address, ……..) And Patient_NOK: (Patient#, Patient_NOKname, Patient_NOKaddress, ……..)

Section 11ER Tables29 Second Level Representation Great when transactions never require both sets of attributes together, but a little extra memory required for the link PatientNOK * has 1 1 

Section 11ER Tables30 Flexing by Introducing Derived Attributes Derived Attribute : An attribute whose value can be derived from a combination of one or more other attributes in the database E.g., –adding a total project time for each project, which can be derived from the individual times recorded for each employee. –Total_invoice_cost = sum of cost of invoice items

Section 11ER Tables31 Happy Chappie Kennels - a more complex example First Level Design:

Section 11ER Tables32 Happy Chappie Kennels Second level Design possibilities –Kennel Size only 3 rows: small, medium & large. Static, so could be a Domain rather than a separate table. –Confirmed Booking no additional Attributes, therefore not needed. –Special Diet one long text description, as don’t want to query individual aspects for a given dog.

Section 11ER Tables33 ERD SAMPLES Ascent Resources Ascent S/W and ERD Solutions Installing Ascent At Home Using Ascent - ER Modeling Library of Free Data Models

Section 11ER Tables34 End of Lecture