Database Design and the Entity-Relationship Model



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

Database Management Systems

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

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Chapter 2: Entity-Relationship Model

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

Lecture 12: Entity Relationship Modelling

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

2. Conceptual Modeling using the Entity-Relationship Model

XV. The Entity-Relationship Model

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

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

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

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

Entity Relationship Diagram

Data Analysis 1. SET08104 Database Systems. Napier University

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

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

The Entity-Relationship Model

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

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

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

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

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

Foundations of Information Management

Lesson 8: Introduction to Databases E-R Data Modeling

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

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

Entity-Relationship Model

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

three Entity-Relationship Modeling chapter OVERVIEW CHAPTER

7.1 The Information system

SCHEMAS AND STATE OF THE DATABASE

Developing Entity Relationship Diagrams (ERDs)

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

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

Modern Systems Analysis and Design

IV. The (Extended) Entity-Relationship Model

The Relational Data Model: Structure

Database Fundamentals: 1

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

Exercise 1: Relational Model

Database Design Process

Foundations of Information Management

Database Design Process

1 Class Diagrams and Entity Relationship Diagrams (ERD)

Entity-Relationship Model. Purpose of E/R Model. Entity Sets

2. Supports eæcient access to very large amounts

Converting E-R Diagrams to Relational Model. Winter Lecture 17

Designing Databases. Introduction

Conceptual Design: Entity Relationship Models. Objectives. Overview

Designing a Database Schema

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

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

EXTENDED LEARNING MODULE A

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Entity - Relationship Modelling

Fundamentals of Database System

Databases What the Specification Says

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

The Entity-Relationship Model

Data Modeling. Database Systems: The Complete Book Ch ,

CSC 742 Database Management Systems

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Introduction to Databases and Data Mining


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

Data Modelling and E-R Diagrams

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Lecture 6. SQL, Logical DB Design

OVERVIEW 1.1 DATABASE MANAGEMENT SYSTEM (DBMS) DEFINITION:-

Introduction to normalization. Introduction to normalization

Relational Schema Design

Introduction to Database Systems CS4320/CS5320. CS4320/4321: Introduction to Database Systems. CS4320/4321: Introduction to Database Systems

DATABASE INTRODUCTION

Access Tutorial 3: Relationships

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

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

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

A Tool for Generating Relational Database Schema from EER Diagram

Faculty Online Services. Spring 2012

A Comparative Analysis of Entity-Relationship Diagrams 1

There are five fields or columns, with names and types as shown above.

Lecture Notes INFORMATION RESOURCES

Data Modeling with Entity-Relationship Diagrams

Databases and BigData

Using Rational Rose to Create Object-Oriented Diagrams

The Entity-Relationship Model

Relational Database Concepts

AS LEVEL Computer Application Databases

IT2305 Database Systems I (Compulsory)

2. Basic Relational Data Model

How To Write A Diagram

Data Modeling Basics

Doing database design with MySQL

Database Design and the E-R Model

Basic Concepts. Chapter A: Network Model. Cont.) Data-Structure Diagrams (Cont( Data-Structure Diagrams. General Relationships. The DBTG CODASYL Model

An Example: Video Rental System

Transcription:

Database Design and the Entity-Relationship Model Computer Science 460/660 Boston University Fall 2013 David G. Sullivan, Ph.D. Database Design In database design, we determine: which data fields to include how they are related how they should be grouped/decomposed End result: a logical schema for the database describes the contents and structure of the database

ER Models An entity-relationship (ER) model is a tool for database design. graphical implementation-neutral ER models specify: the relevant entities ( things ) in a given domain the relationships between them Want to store data about: employees students courses departments Sample Domain: A University How many tables do you think we ll need? can be hard to tell before doing the design in particular, hard to determine which tables are needed to encode relationships between data items

Entities: the Things Represented using rectangles. Examples: Student Employee It can sometimes make sense to combine seemingly distinct types of entities. example: Student Employee because an employee can also be a student why might it beneficial to combine them? Entities: the Things (cont.) Strictly speaking, each rectangle represents an entity set, which is a collection of individual entities. Student Employee CSCI E-119 Jill Jones Drew Faust English 101 Alan Turing Dave Sullivan CSCI E-268 Jose Delgado Margo Seltzer

Attributes Associated with entities are attributes that describe them. represented as ovals connected to the entity by a line double oval = attribute that can have multiple values dotted oval = attribute that can be derived from other attributes exam dates room start time end time length = end time start time Keys A key is an attribute or collection of attributes that can be used to uniquely identify each entity in an entity set. An entity set may have more than one possible key. example: id dob email possible keys include:

Candidate Key A candidate key is a minimal collection of attributes that is a key. minimal = no unnecessary attributes are included not the same as minimum Example: consider again our entity set (, dob) is a minimal key if we need both attributes to uniquely identify a person (id, email) is a key, but it is not minimal, because just one of these attributes is sufficient Candidate Key (cont.) Consider an entity set for books: Book (assume that an author does not write two books with the same title) isbn author title key? candidate key? author author, title isbn, author

Primary Key When defining a relation, we typically choose one of the candidate keys as the primary key. The records are arranged on disk to allow for quick retrieval using the value of the primary key. In an ER diagram, we underline the primary key attribute(s). exam dates room start time end time length Relationships Between Entities Relationships between entities are represented using diamonds that are connected to the relevant entity sets. For example: students are enrolled in courses Enrolled Another example: courses meet in rooms Meets In Room

Relationships Between Entities (cont.) Strictly speaking, each diamond represents a relationship set, which is a collection of relationships between individual entities. Meets In Room CS 105 CAS 315 CS 111 CAS 314 CS 460 MCS 205 CS 510 In a given set of relationships: an individual entity may appear 0, 1, or multiple times a given combination of entities may appear at most once example: the combination (CS 105, CAS 315) may appear at most once Attributes of Relationships A relationship set can also have attributes. they specify info. associated with the relationships in the set Example: Enrolled credit status Can you think of an attribute for Meets In? Meets In Room?

Picturing a Relationship Set with Attributes Enrolled id credit status 12345678 45678900 33566891 25252525 grad grad non-credit ugrad ugrad CS 111 CS 105 CS 460 CS 510 What courses is student 45678900 enrolled in, and for what credit status? Note: For a given combination of entities, there can be at most one value for each relationship-set attribute. Key of a Relationship Set A key of a relationship set can be formed by taking the union of the primary keys of its participating entities. example: (person.id, course.) is a key of enrolled person enrolled course id credit status The resulting key may or may not be a primary key. Why?

Degree of a Relationship Set enrolled is a binary relationship set: it connects two entity sets. degree = 2 Enrolled It's also possible to have higher-degree relationship sets. A ternary relationship set connects three relationship sets. degree = 3 Study Group Studies In Relationships with Role Indicators It s possible for a relationship set to involve more than one entity from the same entity set. For example: every student has a faculty advisor, where students and faculty members are both members of the entity set. advisor advisee Advises In such cases, we use role indicators (labels on the lines) to distinguish the roles of the entities in the relationship. Relationships like this one are referred to as recursive relationships.

Cardinality (or Key) Constraints A cardinality constraint (or key constraint) limits the number of times that a given entity can appear in a relationship set. Example: each course meets in at most one room Meets In Room A key constraint specifies a functional mapping from one entity set to another. each course is mapped to at most one room (course room) as a result, each course appears in at most one relationship in the meets in relationship set The arrow in the ER diagram has same direction as the mapping. note: the R&G book uses a different convention for the arrows Cardinality Constraints (cont.) The presence or absence of cardinality constraints divides relationships into three types: many-to-one one-to-one many-to-many We'll now look at each type of relationship.

Many-to-One Relationships Meets In Room Meets In is an example of a many-to-one relationship. We need to specify a direction for this type of relationship. example: Meets In is many-to-one from to Room In general, in a many-to-one relationship from A to B: A R B an entity in A can be related to at most one entity in B an entity in B can be related to an arbitrary number of entities in A (0 or more) Picturing a Many-to-One Relationship Meets In Room CS 105 CAS 315 CS 111 CAS 314 CS 460 MCS 205 CS 510 CS 610 Each course participates in at most one relationship, because it can meet in at most one room. Because the constraint only specifies a maximum (at most one), it's possible for a course to not meet in any room (e.g., CS 610).

Another Example of a Many-to-One Relationship Borrows Book The diagram above says that: a given book can be borrowed by at most one person a given person can borrow an arbitrary number of books Borrows is a many-to-one relationship from Book to. We could also say that Borrows is a one-to-many relationship from to Book. one-to-many is the same thing as many-to-one, but the direction is reversed One-to-One Relationships In a one-to-one relationship involving A and B: [not from A to B] an entity in A can be related to at most one entity in B an entity in B can be related to at most one entity in A We indicate a one-to-one relationship by putting an arrow on both sides of the relationship: A R B Example: each department has at most one chairperson, and each person chairs at most one department. Chairs Department

Many-to-Many Relationships In a many-to-many relationship involving A and B: an entity in A can be related to an arbitrary number of entities in B (0 or more) an entity in B can be related to an arbitrary number of entities in A (0 or more) If a relationship has no cardinality constraints specified (i.e., if there are no arrows on the connecting lines), it is assumed to be many-to-many. A R B Other Examples How can we indicate that each student has at most one major? Majors In Department Majors In is what type of relationship in this case?

Other Examples (cont.) What if each student can have more than one major? Majors In Department Majors In is what type of relationship in this case? Other Examples (cont.) How can we indicate that each student has at most one advisor? advisor advisee Advises Advises is what type of relationship?

Review: Cardinality Constraints many-to-one relationship Majors In Department one-to-one relationship Chairs Department many-to-many relationship Enrolled Cardinality Constraints and Ternary Relationship Sets study group person studies in course The arrow into study group encodes the following constraint: a student studies in at most one study group for a given course. In other words, a given (student, course) combination is mapped to at most one study group. thus, a given (student, course) combination can appear in at most one row of the corresponding table a given student or course can itself appear in multiple rows

Other Details of Cardinality Constraints For ternary and higher-degree rel. sets, we limit ourselves to a single arrow, since otherwise the meaning can be ambiguous. study group person studies in course For example, the diagram above could mean: 1) person is mapped to at most one (course, study group) combo 2) each (person, course) combo is mapped to at most one study group and each (person, study group) combo is mapped to at most one course Participation Constraints Cardinality constraints allow us to specify that each entity will appear at most once in a given relationship set. Participation constraints allow us to specify that each entity will appear at least once. indicate using a thick line (or double line) Example: each department must have at least one chairperson. Chairs Department omitting the cardinality constraints for now We say Department has total participation in Chairs. by contrast, has partial participation

Participation Constraints (cont.) We can combine cardinality and participation constraints. Chairs Department a person chairs at most one department specified by which arrow? a department has exactly one person as a chair arrow into specifies at most one thick line from Dept to Chairs specifies at least one at most one + at least one = exactly one Design Issue: Attribute or Entity Set? It can sometimes be hard to decide if something should be treated as an attribute or an entity set. Example: room start time end time Meets In Room start time end time capacity Indications that you should use an entity set: if it has attributes of its own that you wish to capture if, as an attribute, it could have multiple values you could potentially use a multi-valued attribute, but you end up treating it as an entity set when converting to a relational model

Design Issue: Relationship Set or Entity Set? Example: students belong to study groups for courses time location Study Group time group-id Study Group Studies In location Which design is better? Why? Rule of thumb: use relationship sets for actions between entities. Design Issue: Relationship Set or Entity Set? (cont.) What if a student can belong to more than one study group for a given course? time location Study Group time group-id Study Group Studies In location

id Advises advisor advisee Borrows isbn Book author title Chairs Department office Majors In credit status Enrolled Study Group Studies In Meets In group-id time location Room start time end time capacity