Cardinality constraints,n:m notation

Similar documents
2 Conceptual Database Design

Requirement Analysis & Conceptual Database Design

3. Schema Design: Logical Design using the Relational Data Model

Intro to DB CHAPTER 6

Chapter 7: Entity-Relationship Model

Conceptual Data Modeling

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

Chapter 2: Entity-Relationship Model

A l Ain University Of Science and Technology

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

Data Modeling Using the Entity-Relationship (ER) Model

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

Using High-Level Conceptual Data Models for Database Design A Sample Database Application Entity Types, Entity Sets, Attributes, and Keys

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

elements of a relation are called tuples. Every tuple represents an entity or a relationship. Country name code population area...

A l Ain University Of Science and Technology

Conceptual Database Design. COSC 304 Introduction to Database Systems. Entity-Relationship Modeling. Entity-Relationship Modeling

Enhanced Entity-Relationship (EER) Modeling

1/24/2012. Chapter 7 Outline. Chapter 7 Outline (cont d.) CS 440: Database Management Systems

COSC 304 Introduction to Database Systems. Entity-Relationship Modeling

Introduction to Databases (Winter Term 2017/2018) Deductive Databases (Summer Term 2018) (c) Prof Dr. Wolfgang May Universität Göttingen, Germany

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Entity Relationship Data Model. Slides by: Shree Jaswal

Overview of Database Design Process. Data Modeling Using the Entity- Relationship (ER) Model. Two main activities:

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

Chapter 2 Conceptual Modeling. Objectives

Context The Relational Data Model in a nutshell. 3.1 Logical schema design. Keep It simple, students KISS -

Chapter 6: Entity-Relationship Model

Conceptual Data Models for Database Design

Copyright 2016 Ramez Elmasr and Shamkant B. Navathei

The En'ty Rela'onship Model

Chapter 6: Entity-Relationship Model

COIS Databases

XV. The Entity-Relationship Model

KDI EER: The Extended ER Model

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

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

Conceptual Data Modeling and the Entity- Relationship Model. Department of Computer Science Northern Illinois University September 2014

ER to Relational Mapping

System Analysis And Design Methods ENTITY RELATIONSHIP DIAGRAM (ERD) Prof. Ali Khaleghi Eng. Hadi Haedar

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Database Design Process

Chapter 11 Object and Object- Relational Databases

Relational Database Systems Part 01. Karine Reis Ferreira

Entity Relationship Diagram (ERD): Basics

Chapter Outline. Note 1. Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Chapter 8: Enhanced ER Model

INTRODUCTION TO RELATIONAL DATABASE SYSTEMS

Chapter 4. Enhanced Entity- Relationship Modeling. Enhanced-ER (EER) Model Concepts. Subclasses and Superclasses (1)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

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

COMP Instructor: Dimitris Papadias WWW page:

COSC 304 Introduction to Database Systems Enhanced Entity-Relationship (EER) Modeling

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Lecture3: Data Modeling Using the Entity-Relationship Model.

High Level Database Models

Definition. 02. Data Modeling. Example ABC Company Database. Data Modeling Importance

DATABASE DESIGN I - 1DL300

Chapter 6. Advanced Data Modeling. Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

DATABASDESIGN FÖR INGENJÖRER F

Conceptual Modeling in ER and UML

DATABASE DESIGN I - 1DL300

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

Non-overlappingoverlapping. Final outcome of the worked example On pages R&C pages R&C page 157 Fig 3.52

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

Module 2 : Entity-Relationship Model 15

Unit1: Introduction. Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

2.2 Relational Model (RM)

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

3. Schema Design: Logical Design using the Relational Data Model

Objectives of logical design... Transforming the ERD diagram into relations. Relational database components. Mapping a composite attribute

Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model

MIS Database Systems Entity-Relationship Model.

Discussion Focus. Figure 1

Lecture 2: Entity Relationship Data Model 2. 1

Information Systems (Informationssysteme)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

Chapter 8 The Enhanced Entity- Relationship (EER) Model

Assignment 1: Entity-Relationship Model Solution

Unit I. By Prof.Sushila Aghav MIT

Database Systems. Overview - important points. Lecture 5. Some introductory information ERD diagrams Normalization Other stuff 08/03/2015

course: Database Systems (NDBI025) SS2017/18

Entity-Relationship Model. From Chapter 5, Kroenke book

EECS 647: Introduction to Database Systems

Database Applications (15-415)

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

Relational Database Systems 1

Relational Database Design Part I. Announcements (September 5) Relational model: review. CPS 116 Introduction to Database Systems

ER modeling. Lecture 4

LELCTURE 4: ENHANCED ENTITY-RELATIONSHIP MODELING (EER)

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

Relational Database Design Part I. Announcement. Relational model: review. CPS 116 Introduction to Database Systems

Chapter 6: Entity-Relationship Model

Data Analysis 1. Chapter 2.1 V3.1. Napier University Dr Gordon Russell

Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques. Fundamentals, Design, and Implementation, 9/e

Database Management

Transcription:

2 Conceptual Database Design 2.3 Integrity Constraints 2.3. Constraint types 2.3.2 Cardinality constraints 2.4 Extended ER Modeling 2.4. Inheritance / Generalization 2.4.2 Modeling historical data 2.4.3 N-ary Bernstein et al.: chap. 4; Elmasri, Navathe: chap 3 + chap 4; Kemper, Eickler: 2.7 2.3 Conceptual Design: case study is_neighbor Country L_ID: String GNP: Constraints l?? capital belongs-to name: Continent String City capitalof longitude: latitude: 03-DBS-Conceptual-2-2 2.3. Integrity Constraints They result from requirement analysis, context and common sense knowledge Formally stated in DB schema Case study From requirements "Names of regions are not necessarily unique" "A regions belongs to exactly one " Common sense knowledge "Population is always >= 0 - or unknown" "A has one and only one capital" Important concept Def.: An Integrity constraint is an invariant (assertion, restriction) of the state of a database. ICs are predicates, a database must fulfill during its lifetime. Constraint types Attribute constraints Attribute value restriction Attribute value must / may exist ([not] NULL] General constraints Relations may be symmetric e.g. neighbor-rel of countries Cardinality constraints How many entities of type E may be in relationship R to an entity of type E'? e.g. to how many countries can a region belong? How many regions can a have? 03-DBS-Conceptual-2-3 03-DBS-Conceptual-2-4 2.3.2 Cardinality constraints Important concept Def.: A cardinality constraint of a relationship R between entity types ', ' restricts the number of entities, participating R UML terminology: multiplicity Cardinality constraints,n:m notation Examples N : M City region continent contradicts : N, not allowed arbitrary binary relation : continent has capital city 03-DBS-Conceptual-2-5 03-DBS-Conceptual-2-6

:N relationship Graphical Notation with symbolic cardinalities R One -entity is related (R) to arbitrary many -entities, but one -entity is related (R) to only one -entity Traditional ER-M notation for cardinality constraints region city More M:N-Relationships every instance of may be related according to R to every instance of M N R R is M:N means: no restriction on the pairs of R :-Relationships every instance of may be related according to R to excactly one instance of and vice versa Formally: :: city -> region is a function R 03-DBS-Conceptual-2-7 03-DBS-Conceptual-2-8 (min,max) min,max)-notation More precise cardinality restrictions by specifying minimal and maximal number of entities Many cities one, at least one min=, max = * A has zero, one or many neighbors min=0, max = * (min,max) min,max)-notation Graphical notation (min,max) Rel (min2, max2) city (min,max)-cardinality constraint (multiplicity) notation also used in UML associations. Note :N notation characterizes relationship R. (min,max) characterizes entity and relationship R, in general different for and 03-DBS-Conceptual-2-9 03-DBS-Conceptual-2-0 CAVEAT: Misleading Notation Cardinality of weak entities Traditional ER-Model, (min,max)-notation does not conform to N:M-Notation 0,* has account UML-multiplicity conformant to :N notation has 0,* account Use (min,max) annotation which conforms to UML, min,max {0,,*} You find this in many text books, :N and (min,max) interchanged WE USE THIS NOTATION E' e is existentially dependent on e' Cardinality: (min,max) R (min2, max2) min = max = min2 = 0 max2 = * E 03-DBS-Conceptual-2-03-DBS-Conceptual-2-2 2

Weak entity: example Countries and regions Cardinality constraints: semantics Let R X be a relationship between entity sets and Country L_ID: String GNP: belongs_to r_id: String R is :N R is a function R: for all extensions of R e2 : {e e (e,e2) R } R is : is an injective function R is M:N R is a relation, but not a function Traditional ER-M notation! Orders and order items Order O_item OrderItem quantity:number. Sometimes an artificial key makes sense, not in this case -R has (min, max) cardinality for all extensions of R and for all y 0 min {x x (x,y 0 ) R } max -R has (min2, max2) for all extensions of R and for all x 0 min2 {y y (x 0,y) R } max2 min,max min2,max2 03-DBS-Conceptual-2-3 03-DBS-Conceptual-2-4 Cardinality constraints notations ERM / (UML) :N UML + mandatory/ multiple (,n) N or M..* k..j k optional/ multiple (0,n) N or M 0..* * 0.. k optional/ single (0,) 0.. mandatory/ single + : k and j are natural numbers; n, N,M in the ERM are literals Many more notations in use!, eg. Oracle 'crow's feet'-notation 2 Conceptual Database Design 2.3 Integrity Constraints 2.3. Constraint types 2.3.2 Cardinality constraints 2.4 Extended ER Modeling 2.4. Inheritance / Generalization 2.4.2 Modeling historical data 2.4.3 N-ary Bernstein et al.: chap. 4; Elmasri, Navathe: chap 3 + chap 4; Kemper, Eickler: 2.7 2.3 03-DBS-Conceptual-2-5 Conceptual Design: case study UML class diagram is_neighbor Country C_ID: String GNP: 0, 0,*,* numb belongs-to name: Continent String,*,* City capitalof No operations in conceptual DB model inheritance capital Antarctic does not have a longitude: latitude: 03-DBS-Conceptual-2-7 from Wikipedia (Klassendiagramm) 03-DBS-Conceptual-2-8 3

2.4 Extended ER ( EER) Example: Suppose two types of customers of a video-shop: - frequent customers - regular customers Generalization membership: er name: Name first_name: Name address: A_type {phone: Phone_Type} Freq membership: er name: Name,..., credit: Money address: A_type {phone: Phone_Type} Redundant: of has to be duplicated for Freq employ object oriented principle of generalization/ inheritance Generalization: Example membership: er name: Name first_name: Name address: A_type {phone: Phone_Type} Freq credit: Money paybackstatus:... 03-DBS-Conceptual-2-9 03-DBS-Conceptual-2-20 2.4. Generalization / specialization Factorize common attributes of different entities Book issn: String publisher: Name edition: er Publication internalid: String title: String {author: Name} {editor: Name} is-a Extended ERM Journal volume: er issue: er Standard relationship is-a between subtypes and super types 03-DBS-Conceptual-2-2 Generalization / Spezialization Semantics of generalization: type versus set Instances of A, B and C are different but share some attributes (OO-interpretation) All instances of B and of C are also instances of A (DB interpretation) B A and C A Def.: Specialization is called - disjoint iff C B = - complete iff A = B C, and every tuple is either B or C more general definition: n>2 specializations B s: T A # x: T0 y: T is-a C t: T2 No overwriting... why not? 03-DBS-Conceptual-2-22 Generalization Example: TeachAss semester... supervise Sem _Course #title date Employee has Payment record # x date y amount...... is-a Assistant project... sits_in Office #roomno computers.. Note: 'sits_in' only defined for the subset 'Assistant' of Employees, 'has' defined for all employees. 2.4. Modeling historical data Person parent_child rents or (0,)?? Child Bike Important Time invariant: a particular relationship between e and e2 will never change. Time variant: A particular relationship (c, v) may disappear, a new one may be established In many cases: History of time variant has to be recorded 03-DBS-Conceptual-2-23 03-DBS-Conceptual-2-24 4

Case study and historical data Keeping track of changes Use case: Bike rental rents A bike may be rented by many customers but not at the same time bike?? Conceptual Modeling: historical data Solution: rents Introduce a weak entity which keeps track of related entities over time (here: rental of each particular bike over time) c_r Bike bike t_r Rental Question: Why 'Rental' existentially dependent on bike, not customer? 03-DBS-Conceptual-2-25 03-DBS-Conceptual-2-26 2.4.2 N-aryN Motivation example Represent the following facts in a database: supplier X delivers part Y to project Z supplier A delivers part P to project Z supplier B delivers part Q to project S Supp can_supply Part used_by Wrong: Conceptual model does NOT represent the information given above N-ary Def.: A relationship is call n-ary relationship R, if more than 2 entity sets are involved in the R Supp supplies Part 03-DBS-Conceptual-2-27 03-DBS-Conceptual-2-28 N-ary relations and cardinalities (min,max) Def.: -R has (min, max) cardinality for all extensions of R and for all (y,z) X E3 min {x x (x,y,z) R } max -R, E3-R correspondingly. R E3 (min2,max2) (min3,max3) N-ary Example: Employees assigned to a project, work at one location for this project. Employees work for one project at a particular location At each location several employees may work for a particular project assigned_to (0,) (0,) Location Employee Question: May an employee work for different projects? Which constraints cannot be expressed? 03-DBS-Conceptual-2-29 03-DBS-Conceptual-2-30 5

N-ary by N binary P_A Proj_assignment E_A Employee L_A Location Extended ER: Aggregation Aggregate: different entity types form a new one Banking_data Telecommunication Adress_data UML notation Introduce a weak entity type for the relationship and binary to the other entity types. Different constraints expressed than n-ary relationship Not frequently used in database design No particular notation for composition as in UML 03-DBS-Conceptual-2-3 03-DBS-Conceptual-2-32 Conceptual Design View integration Def.: View integration is the process of integrating conceptual models, which are related but have been designed separately, into one single model. For big projects different "views" of the application make sense: model different, more or less independent parts of the "real world". (compare "partitioning approach" to "top down approach") Important: model data and processes the data are used for e.g. student administration, exams, teachers and human resources Integrate different partial designs into the conceptual design of the overall DB Running example: a) countries, cities... b) Organizations (Government, national / internat. organization c) geography: lakes, mountains, rivers... Not as easy as it sounds. 03-DBS-Conceptual-2-33 03-DBS-Conceptual-2-34 View integration: "Geography" Mountains, rivers, islands, lakes, deserts,... Mountain GPSlong: GPSlat: height: range: first_asc: Date Island GPSlong: GPSlat: IslGroup: String geo_mountain geo_island r_id: String position {N,W,S,E,Z..} belongs-to 03-DBS-Conceptual-2-35 DB design and constraints Constraints Restrict the state of the database Database should always be coherent with real world Types of constraints Value restriction Cardinality restriction :N notation imprecise but sufficient in many situations Uniform modeling "patterns" Historical / time related data N-ary : model with binary and a another entity type Generalization 03-DBS-Conceptual-2-36 6