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



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

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

Conceptual Design Using the Entity-Relationship (ER) Model

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

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

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

Review: Participation Constraints

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

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

2. Conceptual Modeling using the Entity-Relationship Model

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

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

The Entity-Relationship Model

Lecture 6. SQL, Logical DB Design

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

Data Modeling. Database Systems: The Complete Book Ch ,

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

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

The Entity-Relationship Model

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

Entity Relationship Diagram

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

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

Modern Systems Analysis and Design

Database Design Process

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

IT2305 Database Systems I (Compulsory)

Exercise 1: Relational Model

Databases and BigData

IT2304: Database Systems 1 (DBS 1)

Database Design Process

The Entity-Relationship Model

Databases What the Specification Says

SQL. Ilchul Yoon Assistant Professor State University of New York, Korea. on tables. describing schema. CSE 532 Theory of Database Systems

Winter Winter

The Relational Data Model and Relational Database Constraints

DATABASE MANAGEMENT SYSTEMS. Question Bank:

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

The Relational Data Model: Structure

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

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

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Entity-Relationship Model

Lecture 12: Entity Relationship Modelling

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

XV. The Entity-Relationship Model

IV. The (Extended) Entity-Relationship Model

SQL NULL s, Constraints, Triggers

CSC 443 Fall 2011 Dr. R. M. Siegfried. Answers to Assignment #1

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

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

Data Modeling Basics

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

ER & EER to Relational Mapping. Chapter 9 1

CSC 742 Database Management Systems

Chapter 2: Entity-Relationship Model

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

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

three Entity-Relationship Modeling chapter OVERVIEW CHAPTER

Database Management Systems

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

CSC 443 Data Base Management Systems. Basic SQL

CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL


2. Supports eæcient access to very large amounts

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

Part 7: Object Oriented Databases

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

The Relational Model. Why Study the Relational Model?

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Database Design and Database Programming with SQL - 5 Day In Class Event Day 1 Activity Start Time Length

Theory of Relational Database Design and Normalization

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Entity - Relationship Modelling

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Database Design Process. ER Model. Goals. Relational Model. SQL - The Language of Databases. IT420: Database Management and Organization

Object-Oriented Databases

EECS 647: Introduction to Database Systems

Chapter 6: Integrity Constraints

Designing a Database Schema

Relational Foundations for Functorial Data Migration

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

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

Database Management Systems. Redundancy and Other Problems. Redundancy

ECS 165A: Introduction to Database Systems

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

How To Write A Diagram

Basic Concepts of Database Systems

Chapter 8 The Enhanced Entity- Relationship (EER) Model

Preview DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL

CMPT 354 Database Systems. Simon Fraser University Summer Instructor: Oliver Schulte

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

7.1 The Information system

CS411 Database Systems

The core theory of relational databases. Bibliography

Introduction Decomposition Simple Synthesis Bernstein Synthesis and Beyond. 6. Normalization. Stéphane Bressan. January 28, 2015

Conceptual Design: Entity Relationship Models. Objectives. Overview

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Transcription:

Database Design Database Design I: The Entity-Relationship Model Chapter 4 Goal: specification of database schema Methodology: Use E-R R model to get a high-level graphical view of essential components of enterprise and how they are related Convert E-R diagram to DDL E-R R Model: enterprise is viewed as a set of Entities Relationships among entities 1 2 Entities Entity: an object that is involved in the enterprise Ex: John, CSE305 Entity Type: set of similar objects Ex: students, courses Attribute: describes one aspect of an entity type Ex: name, maximum enrollment Entity Type Entity type described by set of attributes Person:, Name, Address, Hobbies Domain: possible values of an attribute Value can be a set (in contrast to relational model) (111111, John, 123 Main St, {stamps, coins}) Key: minimum set of attributes that uniquely identifies an entity (candidate key) Entity Schema: entity type name, attributes (and associated domain), key constraints 3 4 Entity Type (con t) Graphical Representation in E-R diagram: Set valued Relationships Relationship: relates two or more entities John majors in Computer Science Relationship Type: set of similar relationships (entity type) related to (entity type) by MajorsIn (relationship type). Distinction: relation (relational model) - set of tuples relationship (E-R Model) describes relationship between entities of an enterprise Both entity types and relationship types (E-R model) may be represented as relations (in the relational model) 5 6 1

Attributes and Roles Attribute of a relationship type describes the relationship e.g., John majors in CS since 2000 John and CS are related 2000 describes relationship - value of SINCE attribute of MajorsIn relationship type Role of a relationship type names one of the related entities e.g., John is value of role, CS value of role of MajorsIn relationship type (John, CS; 2000) describes a relationship 7 Relationship Type Described by set of attributes and roles e.g., MajorsIn:,, Since Here we have used as the role name () the name of the entity type () of the participant in the relationship, but... 8 Roles Problem: relationship can relate elements of same entity type e.g., ReportsTo relationship type relates two elements of Employee entity type: Bob reports to Mary since 2000 We do not have distinct names for the roles It is not clear who reports to whom Roles (con t) Solution: role name of relationship type need not be same as name of entity type from which participants are drawn ReportsTo has roles Subordinate and Supervisor and attribute Since Values of Subordinate and Supervisor both drawn from entity type Employee 9 10 Schema of a Relationship Type Role names, R i, and their corresponding entity sets. Roles must be single valued (number of roles = degree of relationship) Attribute names, A j, and their corresponding domains. Attributes may be set valued Key: Minimum set of roles and attributes that uniquely identify a relationship Relationship: <e 1, e n ; a 1, a k > e i is an entity, a value from R i s entity set a j is a set of attribute values with elements from Graphical Representation Roles are edges labeled with role names (omitted if role name = name of entity set). Most attributes have been omitted. domain of A j 11 12 2

Single-role Key Constraint If, for a particular participant entity type, each entity participates in at most one relationship, corresponding role is a key of relationship type E.g., role is unique in Representation in E-R diagram: arrow Entity Type Hierarchies One entity type might be subtype of another Freshman is a subtype of A relationship exists between a Freshman entity and the corresponding entity e.g., Freshman John is related to John This relationship is called IsA Freshman IsA The two entities related by IsA are always descriptions of the same real-world object 13 14 Freshman Sophmore IsA IsA Junior Represents 4 relationship types Senior Properties of IsA Inheritance - Attributes of supertype apply to subtype. E.g., GPA attribute of applies to Freshman Subtype inherits all attributes of supertype. Key of supertype is key of subtype Transitivity - Hierarchy of IsA is subtype of Person, Freshman is subtype of, so Freshman is also a subtype of 15 16 Advantages of IsA IsA Hierarchy - Example Can create a more concise and readable E-R diagram Attributes common to different entity sets need not be repeated They can be grouped in one place as attributes of supertype Attributes of (sibling) subtypes can be different 17 18 3

Constraints on Type Hierarchies Might have associated constraints: Covering constraint: Union of subtype entities is equal to set of supertype entities Employee is either a secretary or a technician (or both) Disjointness constraint: Sets of subtype entities are disjoint from one another Freshman, Sophomore, Junior, Senior are disjoint set Participation Constraint If every entity participates in at least one relationship, a participation constraint holds: A participation constraint of entity type E having role in relationship type R states that for e in E there is an r in R such that (r) = e. e.g., every professor works in at least one department Reprsentation in E-R 19 20 Participation and Key Constraint If every entity participates in exactly one relationship, both a participation and a key constraint hold: e.g., every professor works in exactly one department E-R representation: thick line 21 Representation of Entity Types in the An entity type corresponds to a relation Relation s attributes = entity type s attributes Problem: entity type can have set valued attributes, e.g., Person:, Name, Address, Hobbies Solution: Use several rows to represent a single entity (111111, John, 123 Main St, stamps) (111111, John, 123 Main St, coins) Problems with this solution: Redundancy Key of entity type () not key of relation Hence, the resulting relation must be further transformed (Chapter 6) 22 Representation of Relationship Types in the Typically, a relationship becomes a relation in the relational model Attributes of the corresponding relation are Attributes of relationship type For each role, the primary key of the entity type associated with that role Example: SectNo CrsCode S2000Courses Enroll RoomNo Teaching TAs S2000Courses (CrsCode, SectNo, Enroll) (, Dept, Name) Teaching (CrsCode, SecNo,, RoomNo, TAs) Dept Name 23 Representation of Relationship Types in the Candidate key of corresponding table = candidate key of relation Except when there are set valued attributes Example: Teaching (CrsCode, SectNo,, RoomNo, TAs) Key of relationship type = (CrsCode, SectNo) Key of relation = (CrsCode, SectNo, TAs) CrsCode SectNo RoomNo TAs CSE305 1 1234 Hum 22 Joe CSE305 1 1234 Hum 22 Mary Set valued 24 4

Representation in SQL Each role of relationship type produces a foreign key in corresponding relation Foreign key references table corresponding to entity type from which role values are drawn Since Example 1 Status CREATE TABLE ( Since DATE, -- attribute Status CHAR (10), -- attribute Prof INTEGER, -- role (key of ) Dept CHAR (4), -- role (key of ) PRIMARY KEY (Prof), -- since a professor works in at most one department FOREIGN KEY (Prof) REFERENCES (), FOREIGN KEY (Dept) REFERENCES ) 25 26 Project Date Example 2 Sold Supplier Price CREATE TABLE Sold ( Price INTEGER, -- attribute Date DATE, -- attribute Proj INTEGER, -- role Supplier INTEGER, -- role PartNumber INTEGER, -- role PRIMARY KEY (Proj, Supplier, PartNumber, Date), FOREIGN KEY (Proj) REFERENCES Project, FOREIGN KEY (Supplier) REFERENCES Supplier (), FOREIGN KEY (PartNumber) REFERENCES Part (Number) ) Part 27 Representation of Single Role Key Constraints in the Relational model representation: key of the relation corresponding to the entity type is key of the relation corresponding to the relationship type is primary key of ; Prof is key of. 4100 does not participate in the relationship. Cannot use foreign key in to refer to since some professors may not work in any dept. (But Prof is a foreign key in that refers to.) 1123 4100 3216 Prof 1123 CSE 3216 AMS Key 28 Representing Type Hierarchies in the Supertypes and subtypes can be realized as separate relations Need a way of identifying subtype entity with its (unique) related supertype entity Choose a candidate key and make it an attribute of all entity types in hierarchy Type Hierarchies and the Translated by adding the primary key of supertype to all subtypes. Plus foreign key from subtypes to the supertype. attribs0 attribs1 attribs2 attribs3 attribs4 Freshman Sophmore Junior Senior FOREIGN KEY REFERENCES 29 in Freshman, Sophomore, Sunior, Senior 30 5

Type Hierarchies and the Redundancy eliminated if IsA is not disjoint For individuals who are both employees and students, Name and DOB are stored only once Type Hierarchies and the Other representations are possible in special cases, such as when all subtypes are disjoint See in the book Person Employee SSN Name DOB SSN Salary SSN GPA StartDate 1234 Mary 1950 1234 Accounting 35000 1234 3.5 1997 31 32 Representing Participation Constraints in the Inclusion dependency: Every professor works in at least one dep t. in the relational model: (easy) () references (Prof) in SQL: Simple case: If Prof is a key in (i.e., every professor works in exactly one department) then it is easy: FOREIGN KEY REFERENCES (Prof) General case Prof is not a key in, so can t use foreign key constraint (not so easy): CREATE ASSERTION ProfsInDepts CHECK ( NOT EXISTS ( SELECT * FROM P WHERE NOT EXISTS ( SELECT * FROM W WHERE P. = W.Prof ) ) ) 33 Representing Participation Constraint in the Example (can t use foreign key in if Prof is not a candidate key in ) 1123 4100 3216 Prof Prof not a candidate key 1123 CSE 1123 AMS 4100 ECO 3216 AMS 34 Representing Participation and Key Constraint in SQL If both participation and key constraints apply, use foreign key constraint in entity table (but beware: if candidate key in entity table is not primary, presence of nulls violates participation constraint). CREATE TABLE ( INTEGER, PRIMARY KEY (), -- can t be null FOREIGN KEY () REFERENCES (Prof) --all professors participate ) Participation and Key Constraint in the Example: xxxxxx 1123 yyyyyy 4100 zzzzzzz 3216 Prof 1123 CSE 4100 ECO 3216 AMS 35 36 6

Participation and Key Constraint in (again) Alternative solution if both key and participation constraints apply: merge the tables representing the entity and relationship sets Since there is a 1-1 and onto relationship between the rows of the entity set and the relationship sets, might as well put all the attributes in one table Participation and Key Constraint in Example Name Dept xxxxxxx 1123 CSE yyyyyyy 4100 ECO zzzzzzzz 3216 AMS Prof_ 37 38 Entity or Attribute? Sometimes information can be represented as either an entity or an attribute. Entity or Relationship? Transcript Course Grade Semester Transcript Course Semester Grade Appropriate if Semester has attributes (next slide) 39 40 (Non-) Equivalence of Diagrams Transformations between binary and ternary relationships. Date Part Project Sold Price Supplier 41 7

This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.