Exercise 1.2. Exercise 1.2. Exercise 1.3. Exercise 1.5. Exercise 1.4. Relational Database Systems 1. What is a Database (DB)?

Similar documents
Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

Data Analysis 1. SET08104 Database Systems. Napier University

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

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

The Entity-Relationship Model

Entity-Relationship Model

Foundations of Information Management

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

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

2. Conceptual Modeling using the Entity-Relationship Model

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Lesson 8: Introduction to Databases E-R Data Modeling

Lecture 12: Entity Relationship Modelling

ER modelling, Weak Entities, Class Hierarchies, Aggregation

XV. The Entity-Relationship Model

A brief overview of developing a conceptual data model as the first step in creating a relational database.

7.1 The Information system

three Entity-Relationship Modeling chapter OVERVIEW CHAPTER

Data Modeling Basics

Database Management Systems

Chapter 2: Entity-Relationship Model. E-R R Diagrams

DATABASE DESIGN. - Developing database and information systems is performed using a development lifecycle, which consists of a series of steps.

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

Databases and BigData

Chapter 2: Entity-Relationship Model

DATABASE INTRODUCTION

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

IV. The (Extended) Entity-Relationship Model

Concepts of Database Management Seventh Edition. Chapter 6 Database Design 2: Design Method

Fundamentals of Database Design

Data Modeling: Part 1. Entity Relationship (ER) Model

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Chapter 2. Data Model. Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel

Database Systems. Session 3 Main Theme. Enterprise Data Modeling Using The Entity/Relationship (ER) Model. Dr. Jean-Claude Franchitti

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

IT2305 Database Systems I (Compulsory)

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

1 Class Diagrams and Entity Relationship Diagrams (ERD)

Foundations of Information Management

Requirement Analysis & Conceptual Database Design. Problem analysis Entity Relationship notation Integrity constraints Generalization


Entity Relationship Diagram

Designing Databases. Introduction

Relational Database Systems 2 1. System Architecture

Data Modeling. Database Systems: The Complete Book Ch ,

TIM 50 - Business Information Systems

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Announcements. SE 1: Software Requirements Specification and Analysis. Review: Use Case Descriptions

The E-R èentity-relationshipè data model views the real world as a set of basic objects èentitiesè and

Conceptual Design: Entity Relationship Models. Objectives. Overview

Chapter 10 Practical Database Design Methodology and Use of UML Diagrams

IT2304: Database Systems 1 (DBS 1)

Why & How: Business Data Modelling. It should be a requirement of the job that business analysts document process AND data requirements

Exercise 1: Relational Model

Information Systems Modelling Information Systems I: Databases

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

The Entity-Relationship Model

Modern Systems Analysis and Design

Select the Crow s Foot entity relationship diagram (ERD) option. Create the entities and define their components.

How To Write A Diagram

æ A collection of interrelated and persistent data èusually referred to as the database èdbèè.

A technical discussion of UML 06/11/03 Relational Modeling with UML

Preview DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

BİL 354 Veritabanı Sistemleri. Entity-Relationship Model

Entity - Relationship Modelling

Database Fundamentals: 1

Database Design Process

Lecture Notes INFORMATION RESOURCES

Relational Database Concepts

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Designing a Database Schema

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Entity-Relationship Model

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

2. Basic Relational Data Model

EXTENDED LEARNING MODULE A

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Collated Food Requirements. Received orders. Resolved orders. 4 Check for discrepancies * Unmatched orders

Developing Entity Relationship Diagrams (ERDs)

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

A Comparative Analysis of Entity-Relationship Diagrams 1

A technical discussion on modeling with UML 06/11/03 Entity Relationship Modeling with UML

AS LEVEL Computer Application Databases

Doing database design with MySQL

Relational Database Basics Review

Relational Databases

Chapter 1 Databases and Database Users

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

Introduction to Database Systems

Basics of Dimensional Modeling

Conceptual Design Using the Entity-Relationship (ER) Model

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 1 Outline

11 November

Business Database Systems

Database IST400/600. Jian Qin. A collection of data? A computer system? Everything you collected for your group project?

Transcription:

Exercise.2 Relational Database Systems Wolf-Tilo Balke Joachim Selke Christoph Lofi Institut für Informationssysteme Technische Universität Braunschweig www.ifis.cs.tu-bs.de What is a Database (DB)? Collection of related data Represents some aspects of the real world Data is logically coherent Is proved for an intended group of users and applications Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 2 Exercise.2 What is a DBMS? What do you use it for? A collection of programs to maintain a database Used for: Definition of Data and Structure Physical Construction Manipulation Sharing/Protecting Persistence/Recovery Example scenarios? Selling tickets, managing a course of study, Exercise.3. Are the following features proved by a FS, a DB or both? Simple and fast data access: FS, DB Controlled redundancy: DB Sophisticated enforcement of standards: DB Backup and recovery: DB Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 4 Exercise.4. What is redundancy? The same information is stored several times Stored information could be derived from already existing data 2. What are the two main disadvantages of redundancy? Waste of storage space Problems in consistently updating data 3. What is the advantage of redundancy? Speed up data access Use case: For each railroad station and train, precompute the list of all reasonable connecting trains! (This information will be accessed very often but changes rarely) Exercise.5 Which users groups interact with a running DBMS? Database administrators Database designers Application programmers DBMS designers and implementers Tool developers Operators and maintenance personnel End users (naïve, sophisticated, casual) Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 6

Exercise.6 Briefly define the following terms: Declarative Querying Specify what you want, not how and from where to get it o need to know position of files etc. o need to know implementation details View Create a different perspective of the data by Restricting the accessible information Deriving additional, virtual information This allows for customization of the accessible data for specific user-groups Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 7 Exercise.6 Briefly define the following terms: Data Model: A data model is an abstract model that describes how data is represented and accessed Three parts: Integrity Structure Manipulation Usually represented by three schemas (each schema respecting the three model parts) Logical Schema Conceptual Schema Physical Schema Well defined structures support understanding/communication The use of a complete model makes sure the designed system can be implemented Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 8 Data Modeling Introduction Basic ER Modeling Chen notation Alternative notations Example. Database Applications Database applications consist of Database instances with their respective DBMS associated application programs interfacing with the users App2 App DBMS App3 DB DB2 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 9 E 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 0. Database Applications. Universe of Discourse Planning and developing application programs traditionally is a software engineering problem Requirements Engineering Conceptional Design Application Design Software engineers and data engineers cooperate tightly in planning the need, use and flow of data Data modeling Database design DB Design models a miniworld into a formal representations Restricted view on the real world with respect to the problems that the current application should solve Miniworld Information Dependencies Things Facts Relationships Properties Database Operations E 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 2

. Phases of DB Design. Phases of DB Design DBMS independent DBMS dependent Functional Analysis Application Program Design Transaction Implementation Functional Requirements High Level Transaction Specification Internal Schema Application Programs Miniworld Requirements Analysis Conceptual Design Logical Design Physical Design Data Requirements Conceptual Schema Logical Schema this lecture Requirements Analysis Database designers interview prospective users and stakeholders Data requirements describe what kind of data is needed Functional requirements describe the operations performed on the data Functional Analysis Concentrates on describing high-level user operations and transactions Does also not contain implementation details Should be matched versus conceptual model E 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 3 E 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 4. Phases of DB Design. Phases of DB Design Conceptual Design Transforms data requirements to conceptual model Conceptual model describes data entities, relationships, constraints, etc. on high-level Does not contain any implementation details Independent of used software and hardware Logical Design Maps the conceptual data model to the logical data model used by the DBMS e.g. relational model, hierarchical model, Technology independent conceptual model is adapted to the used DBMS software Physical Design Creates internal structures needed to efficiently store/manage data Table spaces, indexes, access paths, Depends on used hardware and DBMS software While modeling the data, design phases have to be completed The result of one phases serves as input for the next phase Often, automatic transition is possible with some additional designer feedback conceptual design ERdiagram UML, logical design tables, columns, physical design tablespaces, Indexes, E 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 6 2. ER Modeling 2. ER - Entities Traditional approach to Conceptual Modeling Entity-Relationship Models (ER-Models) Also known as Entity-Relationship Diagrams (ERD) Introduced in976 by Peter Chen Graphical representation Top-Down-Approach for modeling Entities and Attributes Relationships Constraints Some derivates became popular ER Crow s Foot otation (Bachman otation) ER Baker otation Later: Unified Modeling Language (UML) Entities An entity represents a thing in the real world with an independent existence An entity has an own entity and represents just one thing Example: a car, a savings account, my neighbor s house, the cat Snowflake, a product, Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 7 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 8

2. ER - Attributes Attributes A property of an entity, entity type or a relationship type. Example: of an employee, color of a car, balance of an account, location of a house, Attributes can be classified as being: simple or composite single-valued or multi-valued stored or derived Example: of a cat is simple, single-valued, and stored 2. ER Entity Types Entity Types are sets of entities sharing the same characteristics or attributes Each entity within the set has its own values Each entity type is described by its and attributes Each entity is an instance of an entity type Describes the so called schema or intension of similar entities Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 9 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 20 2. ER Entity Sets 2. ER Diagrams An Entity Set is the collection of all entities of a given entity type Entity sets often have the same as the entity type Cat may refer to the entity type as well as to the set of all Cat entities (sometimes also plural for the set: Cats) Also called the extension of an entity type (or instance) ER diagrams represent entity types and relationships among them, not single entities Graphical Representation Entity Type EntityType Attributes Rectangle labeled with the of the entity Usually, starts with capital letters attribute attribute n EntityType Oval labeled with the of the attribute Usually, starts with lower case letters Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 2 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 22 2. ER Diagrams 2. ER Composite Attributes Textual Representation Entity Types Written as: Entityame (attribute, attribute2, ) Entity Written as: (value of attribute, value of attribute2, ) Example Entity Type Cat Cat Cat (, color) color Entity Set Cats (Fluffy, black-white) (Snowflake, white) (Captain Hook, red) Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 23 Simple Attribute: Attribute composed of a single component with an independent existence Example: of a cat, salary of an employee, Cat (), Employee(salary), Composite Attribute: Attribute composed of multiple components, each with an independent existence Graphically represented by connecting sub-attributes to main attribute Textually represented by grouping sub-attributes in () Example: address attribute of a company (is composed of street, house, ZIP, city, and country) street Company (address(street, houseo, ZIP, city)) Cat Company address Simple Composite houseo Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 24 city ZIP

2. ER Multi-Valued Attributes Single-Valued Attribute Attribute holding a single value for each occurrence of an entity type Example: of a cat, registrationo. of a student Multi-Valued Attributes (lists) Attribute holding (possibly) multiple values for each occurrence of an entity type. Graphically indicated by a double-bordered oval Textually represented by enclosing in {} Example: telephoneo. of a student ({phoneo}) 2. ER Derived Attributes Stored Attribute The attribute is directly stored in the database Derived Attribute The attribute is (usually) not stored in the DB but derived from an other, stored attribute In special cases, it might also be stored for read performance reasons Indicated by dashed oval Example: Age can be derived from birth date, average grade can be derived by aggregating all stored grades birth date Cat phoneo Cat Single Valued Multi-Valued Stored Derived age Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 25 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 26 2. ER - Keys 2. ER - Keys Entities are only described by attribute values Two entities with entical values cannot be distinguished (no OIDs, row IDs, etc.) Entities (usually) must be distinguishable Identification of entities with key attributes Value combination of key attributes is unique within all possible extensions of the entity types Key attributes are indicated by underlining the attribute Key attribute examples Single key attribute (registratio, ) (43245, Hans Müller) Composite key (multiple key attributes) Car (licenseplate(districtid, letterid, numericid), brand, year) ((BS,CL,797),VW,998) Please note that each key attribute itself is not unique! Car license Plate brand registration umber districtid letterid numericid year Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 27 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 28 Example Entity Type Book (isbn, {author(firstame, lastame)},, sub, publisher(,city, country), {revision(no, year)} ) (032204484, {(Ramez, Elmasri), (Shamkant, avathe)}, Fundamentals of Database Systems, (Pearson, Boston, US), {(4,2004),(2, 994)}) isbn 2. ER Modeling Book revision author no firstame lastame publisher city 2. ER - Domains Attributes cannot have arbitrary values: they are restricted by the attribute value sets (domains) Zip Codes may be restricted to integer values between 0 and 99999 ames may be restricted to character strings with maximum length of 20 Domains are not displayed in ER diagrams Usually, popular data types are used to describe domains in data modeling e.g. integer, float, string,. year country Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 29 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 30

2. ER - Domains Commonly used data types ame Syntax description integer integer 32-Bit signed integer values between -2 3 and 2 3 double double 64-Bit floating point values of approximate precision numeric numeric(p, s) A with p digit before the decimal and s digitals after the decimal character char(x) A textual string of the exact length x varying character varchar(x) A textual string of the maximum length x date date Stores year, month, and day time time Stores hour, minute, and second values 2. ER - Domains Using data types for modeling domains is actually a crutch The original intention of domains was modeling all val values for an attribute Colors: {Red, Blue, Green, Yellow} Using data types is very coarse and more a convenient solution Colors: varchar(30)??? To compensate for the lacking precision, often restrictions are used Colors: varchar(30) restricted to {Red, Blue, Green, Yellow} Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 32 2. ER ULL Values Sometimes, an attribute value is not known or an attribute does not apply for an entity This is denoted by the special value ULL So called ULL-value Example: Attribute universitydegree of entity Heinz Müller may be ULL, if he does not have a degree ULL is usually always allowed for any domain or data type unless explicitly excluded 2. ER ULL Values What does it mean when you encounter a ULLvalue? Attribute is not applicable e.g. attribute maen when you don t have one Value is not known Value will be filled in later Value is not important for the current entity Value was just forgotten to set Actually there are more than 30 possible interpretations Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 33 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 34 ER Relationships ER Relationships Entities are not enough to model a miniworld The power to model dependencies and relationships is needed In ER, there can be relationships between entities Each relationship instance has a degree i.e. the of entities is relates to A relationship instance may have attributes Similar to entities, ERDs do not model indivual relationships, but relationship types Relationship type amed set of all similar relationships with the same attributes and relating to the same entity types Diamond labeled with the of the relationship type Usually, starts with lower-case letters Relationship set Set of all relationship instances of a certain relationship type E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 35 E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 36

ER Relationships Relationships relate entities within the entity sets involved in the relationship type to each other Relationship Type R Entity Type B A R B ER Relationships Example: There is an ownership relation between cats and persons owns Cat Entity A Relationship Instance R Relationship Set R A R A2 R B B A A3 B2 A4 R2 A6 A5 R3 B4 Entity Set B B3 But more modeling detail is needed Does every person own a cat? Does every cat have an owner? Can a cat have multiple owners or a person own multiple cats? Since when does a person own some cat? Who owns whom? Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 37 E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 38 ER Relationship Cardinality ER Relationship Cardinality Additionally, restrictions on the combinations of entities participating in an entity set are needed Example: Relationship type married to married to Unless living in Utah, a restriction should be modeled that each person can only be married to single person at a time i.e. each person entity may only appear once in the married to relationship set Cardinality annotations are used for this Relationship types referring to just one entity type are called recursive Cardinality annotations One cardinality annotation per entity type / relationship end Minimum and maximum constrains possible cardinality Common Cardinality Expressions: (0, ) : Zero to one instances are bound by the relationship (i.e. relationship end is optional) (, ) : Exactly one instance is bound (0, *) : Any of instances may be bound (, *) : At least one instance is bound (at least one instance up to any ) o annotation is usually interpreted as (0, *) If only one symbol / s is used, this is interpreted as (0, s) * = (0, *); 4 = (0, 4) Sometimes, or M are used instead of * Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 39 E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 40 ER Relationship Cardinality ER Relationships Cardinalities express how often a specific entity may appear within a relationship set To each entity of type B, one or two entities of type A are related A (0, ) (, 2) r A specific entity of type A may appear up to once in the relationship set, an entity of type B appears at least once and at most twice This means: Up to two entities of type A may relate to one entity of type B. Some entities in A are not related to any in B. All entities in B are related to at least one in A. B A A A A4 A6 A5 A2 A3 (0, ) (, 2) r r R R2 R3 R4 B B B B2 B3 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 42

ER Relationship Cardinality ER Relationships Example: Each person can only be married to one other person married to married to Each entity can only appear in one instance of the married to entity set ote: following this model a person actually can marry him/herself P P4 P6 P5 P2 P3 married to R R2 E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 43 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 44 ER Relationship Cardinality ER Relationship Cardinality Example: A cat has up to 4 owners, but at least one. A person may own any of cats. (0, *) (, 4) owns Cat Lisa owns Snowball, Lisa owns Snowball II Example: A person may supervise any other of persons Drake Mallard supervises Launchpad McQuack Drake Mallard supervises Gosaly Mallard (0, *) super vises supervises (0, ) E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 45 E 3.4 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 46 ER Relationship Cardinality ER Relationship Roles Cardinalities for binary relationship types can be classified into common, more general cardinality types These cardinality types are also often found in other modeling paradigms : (One-To-One) Each entity of the first type can only relate to exactly one entity of the other type : (One-To-Many) Each entity of the first type can relate to multiple entities of the other type : (Many-To-One) Multiple entities of the first type can relate to exactly one entity of the second type :M (Many-To-Many) o restrictions. Any of entities of first type may relate to any of entities of second type. Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 47 Often, it is beneficial to clarify the role of an entity within a relationship Example: Relationship supervises super vises What is meant? Who is the supervisor? Who is the supervised person? Roles can be annotated on the relationship lines (0, ) (0, ) (0, *) (0, *) supervisor supervisee super vises Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 48

ER Relationship Degree Relationship instances involve multiple entities The of entities in each relationship instance is called relationship degree Degree=2 : Binary Relation owns Degree=3: Ternary Relation Supplier supplies Cat Customer ER Relationship Attributes Similar to entities, relationship types may even have attributes salary works for Company For : relationships, the relationship attribute may be migrated to any of the participating attributes For : relationships, the attribute may be only migrated to the entity type on the -se For :M relationships, no migration is possible Part Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 49 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 50 ER Total Participation To express that all entities of an entity type appear in a certain relationship set, the concept of total participation can be used The entity type which is totally participating is indicated by a double line Example: Each driver s license must belong to a person owns Drivers License ER Weak Entities Each entity needs to be entifiable by a set of key attributes Entities existing independently of the context are called strong entities A person exists whether it is married or not In contrast, there may be entities without an unique key called weak entities Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 5 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 52 ER Weak Entities ER Weak Entities Weak entities are entified by being related to strong entities The strong entities own the weak entity The weak one cannot exist without the strong ones The relationships relating the strong to the weak are called entifying relationships The weak entity is always totally participating in that relationship Weak entities have partial keys which are unique within the entifying relationship sets of their strong entities To be unique, the weak entity instance has to borrow the keys of the respective strong entity instances Weak entity types and entifying relationship types are depicted by double-lined rectangles Example: An online shopping order contains several order items ordero Order (0,*) is part of (,) OrderItem An order item can only exits within an order Each order item can be entified by the ordero of it s owning order and its itemline itemline Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 53 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 54

ER Overview ER Overview Entity Type Weak Entity Type Attribute Key Attribute Multi-valued Attribute Composite Attribute Derived Attribute Relationship Type Identifying Rel. Type ame ame Total participation of E2 in R E Cardinality An instance of E may relate to multiple instances of E2 E Specific cardinality with min and max An instance of E may relate to multiple instances of E2 E r (0, ) (0,) r r E2 E2 E2 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 55 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 56 ER Alternative otations ER Crow s Foot otation There is a plethora of alternative notations for ER diagrams Different styles for entities, relationships and attributes o standardization among them Also, notations are often freely mixed ER diagrams can look completely different depending on the used tool / book In the following, we introduce the (somewhat popular) crow s feet notation Crow s foot notation was initially developed by Gordon Everest Derivate of ERD notation Main Goal Consolate graphical representation Prove a better and faster overview Allow for easier layouting Wespread use in many current tools and documentations E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 57 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 58 ER Crow s Foot otation ER Crow s Foot otation Entity Types Entity Types are modeled with a d box Attribute s are written inse the box separated by a line Key attributes are marked with a leading asterisk Composite attributes are represented with indentation isbn Book author firstame lastame Book * isbn author firstame lastame Relationship Types Relationship types are modeled by lines connecting the entities Line is annotated with the of the relationship which is a verb Cardinalities are represented graphically (0, ) : Zero or one (, ) : Exactly one (0, *) : Zero or more (, *) : one or more ATTETIO: Cardinalities are written on the opposite se of the relationship (in contrast to classic ER ) E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 59 E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 60

ER Crow s Foot otation ER Crow s Foot otation (0, *) (, *) owns owns What happens to n-ary relationships or relationship attributes? Supplier Cat * * supplies Cat Costumer Problem -ary relationship types are not supported by crow s foot notation, neither are relationship attributes Workaround solution: Intermediate entities must be used -ary relationships are broken down in a series of binary relationship types anchoring on the intermediate entity A R C A R a R R B C * Part B R c B E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 6 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 62 ER Crow s Foot otation ER Crow s Foot otation Supplier Supplier * supplies * proves * Part Supplies Part contains is used Customer Customer Originally, ER diagrams were intended to be used on a conceptual level Model data in an abstract fashion independent of implementation Crow s foot notation sacrifices some conceptual expressiveness Model is closer to the logical model (i.e. the way the data is later really stored in a system) This is not always desirable and may obfuscate the intended semantics of the model E 3.5 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 63 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 64 ER Even more notations ER Even more notations Barker s notation Based on Crow s Feet otation Developed by Richard Barker for Oracle s CASE modeling books and tools in986 Cardinalities are represented differently (0, ) : Zero or one (, ) : Exactly one (0, ) : Zero or more (, ) : one or more Cardinalities position similar to Crow s Foot notation and opposite to classic ER Different notation of subtypes See next lecture Black Diamond otation Cardinalities are represented differently Cardinality annotation per relationship, not per relationship end : : :M Also, -ary relationships possible ternary M Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 65 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 66

2. ER Mathematical Model Mathematically, an attribute A of entity type E with domainv is a function from E to the power set P(V) A : E P(V) The power set P(V) of V is the set of all subsets of V The value of an attribute of the entity e is denoted as A(e) This definition covers null values (empty set) single-valued attributes (restricted to singleton sets) multi-valued attributes (no restrictions) For a composite attribute A(A, A 2,, A n ), V is defined as V = P(V ) P(V 2 ) P(V n ) 2. ER Mathematical Model A relationship type R among n entity types E, E 2,, E n defines a relationship set among instances of these entity types Each relationship instance r i within the relationship set R associates n indivual entities (e, e 2,, e n ), and each entity e j in r i is member of the entity type E j, j n Alternatively, the relationship type R can be seen as a subset of the Cartesian product of the entity types R E E 2, E n Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 67 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 68 We want to model a simple university database In our database, we have students. They have a, a registration, and a course of study. The university offers lectures. Each lecture may be part of some course of study in a certain. s may have other lectures as prerequisites. They have a, prove a specific of credits and have an unique ID Each year, some of these lectures are offered by a professor at a certain day at a fixed time in a specific room. s may register for that lecture. Professors have a and are member of a specific department. How to start? What to do? Find the basic entity types Find the attributes of entities Dece to which entity an attribute should be assigned Which attributes are key attributes? Some attributes are better modeled as own entities, which ones? Define the relationship types Which role do entities play? Do relationships require additional entity types? Are the relationships total? Identifying? Are weak entities involved? What are the cardinalities of the relationship type? Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 69 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 70 Which are our entity types? In our database, we have students. They have a, a registration and a course of study. The university offers lectures. Each lecture may be part of some course of study in a certain. s may have other lectures as prerequisites. They have a, prove a specific of credits and have unique ID Each year, some of these lectures are offered by a professor at a certain day at a fixed time in a specific room. s may attend that lecture. Professors have a and are member of a specific department. Professor What attributes are there? In our database, we have students. They have a, a registration and a course of study. The university offers lectures. Each lecture may be part of some course of study in a certain. s may have other lectures as prerequisites. They have a, prove a specific of credits and have unique ID Professors have a and are member of a specific department. Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 7 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 72

registration registration credits Professor credits Professor prereq. course of study course of study prerequisite lecture part of Course of Study curriculum First try Key is automatically generated and has no meaning bese unique entification Course of study is an entity type now Which entity types are additionally related? Prerequisite lecture also is not a good attribute Each year, some lectures of the pool of all lectures are offered by a professor at a certain day at a fixed time in a specific room. s may attend that lecture. Prerequisite lectures are also lectures. Use a relationship instead! Professor does not have key attributes 73 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig room day of week time registration attends Professor ot really intuitive Use an intermediate entity instead? curriculum Course of Study day of week room instance attends curriculum Course of Study Better? Add cardinalities Add total and entifying annotations Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 76 ote that the part of relationship had to use an intermediate entity Professor teaches instantiates prereq. The same example using Crow s Foot otation department part of 75 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig time credits enrolls part of Professor teaches instantiates prereq. department credits enrolls room instance attends instanciates day of week time registration teaches instanciate 74 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig Professors use a surrogate key now Used by student and lecture. Even worse, lecture refers to a course of study in a specific curriculum. Use additional entity type with relationships! registration department Second try This model is really crappy! Course of study does not seem to be an attribute curriculum enrolls department department credits enrolls +registratio prereq. part of curriculum Course of Study Better? Add cardinalities attends Instance teaches time dayofweek room Professor + department enrolls instanciates CourseOfStudy has + PartOf curriculumsemester has + credits hasprerequisite Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 77 Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 78

Modeling is not that simple Many possible (and also correct) ways of modeling the same miniworld Some are more elegant, some are less elegant Models alone are not enough, they need to be documented What are the meanings of the attributes? The meanings of the relationships? Relational Database Systems Wolf-Tilo Balke Institut für Informationssysteme TU Braunschweig 79