The Entity-Relationship Data Model

Slides:



Advertisements
Similar presentations
Banking Business Scenario
Advertisements

Exercise 1 Consider the ER diagram below. Assume that an employee may work in up to two departments or may not be assigned to any department. Assume that.
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
High-Level Database Models Spring 2011 Instructor: Hassan Khosravi.
Constraints in Entity-Relationship Models Zaki Malik September 18, 2008.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 6 A First Course in Database Systems.
Functional Dependencies - Example
1 Entity-Relationship Model Diagrams Class hierarchies Weak entity sets.
Design Principles: Faithfulness
Weak Entity Sets. Occasionally, entities of an entity set need “help” to identify them uniquely. Example. Crews might have a number and some description,
Weak Entity Sets. Occasionally, entities of an entity set need “help” to identify them uniquely. Entity set E is weak if in order to identify entities.
Design Principles: Faithfulness
A step-by-step application development Develop a database recording information about teams, players, and their fans, including –For each team, its name,
Entity-Relationship Data Model CS 157A Professor Sin-Min Lee Student: Yen-Chu Pan.
Entity-Relationship Model
A four-way Relationship
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Entity-Relationship Model Database Management Systems I Alex Coman, Winter.
1 The Entity-Relationship Data Model Chapter 2 (Database Design)
CS411 Database Systems Kazuhiro Minami
Entity Relationship Model Chapter 6. Basic Elements of E-R Model Entity Object of the real world that stores data. Eg. Customer, State, Project, Supplier,
Data Modeling Using the Entity-Relationship Model
the Entity-Relationship Model
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Database Systems The Entity-Relationship Model
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
Database Systems Lecture # 7 8 th Feb, Conceptual and Logical Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 3 Introduction to a First Course in Database Systems.
Databases : Entity-Relationship Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
ER Data Models Ctd. CSET 3300.
Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Computing & Information Sciences Kansas State University Wednesday, 24 Sep 2008CIS 560: Database System Concepts Lecture 12 of 42 Wednesday, 24 September.
 Entity-relationship models (ERM) Entity-relationship models (ERM)  Simple E-R Diagram Simple E-R Diagram  Weak Entity Weak Entity  Strong Entity.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
SAnta Clara UniversityHolliday – COEN 1782–1 Today’s Topic Today: u Constraints, Weak Entity Sets, Entity- Relationship Design. u Read Sections
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 2 Introduction to a First Course in Database Systems.
Home Work. Design Principles and Weak Entity Sets.
advanced data modeling
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 4 Introduction to a First Course in Database Systems.
Data Modeling Using the Entity-Relationship (ER) Data Model.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
A short revision on entity- relationship modelling.
Modeling: Entity-Relationship Diagrams
A short review on entity- relationship modelling.
1 Database Modeling (Semantic data modeling) ER Data Model –A high-level conceptual data model –Proposed by P. Chen (1976) –Widely used in DB design process.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
The Entity-Relationship Diagram for Data Modeling
ER Diagrams and Relational Model CS 174a (Winter 2015)
Entity-Relationship Data Model
COP Introduction to Database Structures
Entity-Relationship Model
COP Introduction to Database Structures
RELATION.
Constraints in Entity-Relationship Models
Constraints AND Examples
Chapter 7: Entity-Relationship Model
Constraints AND Examples
Entity-Relationship Data Model
Session 5: Weak Entity Sets and ER Model to Relational ( )
Presentation transcript:

The Entity-Relationship Data Model (Modeling Constraints & Weak Entity Sets)

Constraints Additional information about the data Often not about the structure of the data but the relationship among the data

Types of Constraints Key constraint: set of attributes that uniquely determined an entity within an entity set. SSN of a person in the US Single-value constraint: uniqueness of a value in certain context. Key requires uniqueness of value Referential integrity constraint: existence of a value referred to by some other objects. Movie should exist if it is owned by some studio

Types of Constraints Domain constraint: value of an attribute must be drawn from a specific set of values Year in Movies should be an integer who value is greater than or equal 1900 General constraint: assertions that are required to hold in the database (customer’s need) No more than 10 stars for one movie are listed in the database (Lower ranking stars are not interested )

Keys Definition: A set of attributes K is a key for an entity set E means that for every pair of two distinct entities e and f of E, e and f cannot have the same value for every attributes belonging to K. Key can contain more than one attribute. An entity set might have more than one key. For isa relation we require that the root entity set has all the attributes of the key the key for each entity is found from its component in the root entity set

Example What should be the key for Movies, Stars, and Studios? name name and address? name address title year length film type Stars Stars_in Movies name Owns Studios title and year? address name

What should be a key? Key can be determined by the given attributes of the entity set. Key can be created if needed when the set of attributes of the entity set does not yied a key: Student ID: not necessary SSN Employee ID: not SSN

Key in E/R diagram only one primary key: underline all attributes belonging to this key; others? name address title year length film type Stars Stars_in Movies name Owns Studios address

Single-value Important in database design: Single value allows us to associated role with data: Attributes are single-value: each attribute represents a property of the entity, e.g., for each entity m belonging to an entity set Movies, m can have only one title. Attributes different than keys can have null value (also called unknown): the length of a movie can be missing Many-one relationship imposes a single-value constraint: R many-one from E to F: for each entity e in E there is at most one associated entity f in F.

Referential Integrity Commonly used to refer to relationship among entity sets Requires that the referenced value must exists: Owns: many-one relationship from Movies to Studios requires a movie cannot be owned by more than one studio NOT: for each movie there is a studio who owns it – this is required by the referential integrity constraint on the relationship Owns How to enforce referential integrity constraint? Forbid the deletion of referenced entity (do not allow a studio to be deleted) unless it does not own a movie If a referenced entity is deleted then all entities that reference it will be deleted as well (delete studio implies deleting all the movies owned by that studio)

Referential Integrity in E/R Replace the arrow with a circle (in the book: rounded arrowhead) title year length film type name Movies Owns Studios address

Others Domain constraints General constraints place a notation described the domain next to the attribute General constraints no specific notation for representing this type of constraints in E/R model but could be done by placing a notation on the link (of a relationship) or next to an attribute

Weak Entity Sets Definition: An entity set whose key is composed of attributes some or all belong to another entity set is a weak entity set. Example: The Cartoons entity set in the Movies database: a movie is identified by its title and year, both attributes belong to the Movies entity set

Example name Crews Unit_of Studios address number A studio has several crews, they are numbering 1, 2, 3,. Other studios also use the same numeral system Key for Crews need to include the studio’s name  Crews is a weak entity set (below: E/R diagram) name Crews Unit_of Studios address number

Representing in E/R diagram A studio has several crews, they are numbering 1, 2, 3,. Other studios also use the same numeral system Key for Crews need to include the studio’s name  in E/R diagram: double border for the Crews entity set and the Unit_of relationship name Crews Unit_of Studios address number

Example A database about species and genus. A species is designated by its genus and species names  key of Species is its name and the name of the Genus of which is belonged to. name Species Belongs_to Genus name

Another example Stars Movies Contracts Studios Star_of Movie_of Studio_of

Sources of Weak Entity Sets isa hierarchy: part of the key is from the ‘parent’ entity set. Connecting entity sets that are generated when a multiway relationship is converted to binary relationships: all attributes of the key belong to other entity sets.

Key of Weak Entity Set If E is a weak entity set then its key consists of: Zero or more of its one attributes, and Key attributes from entity sets that are reached by certain many-one relationship from E to other entity sets. These many-one relationships are called supporting relationships for E.

Supporting Relationship Conditions for R, a relationship from E to F, to be a supporting relationship of a weak entity set of E: R: binary, many-one relationship from E to F Referential integrity from E to F over R The attributes of F that are supplied to be key attributes of E must be key attributes of F If F is weak, then the supplied attributes must be the key attributes of some other entity set that were supplied to be the key of F If there are several different supporting relationships from E to F, then each of these is used to supply a copy of the key attributes of F to create the key of E.

Illustrations name Crews Unit_of Studios address number What happens if Unit_of is many-many? What happens if no integrity constraint exists? (A crew without studio?) Can address help forming the key of Crews? What happens if Studios is ‘Divisions’?

E/R Notations Double border for weak entity set Double border for supporting relationship Underlining key attributes

Exercise 2.1.3 Give an E/R diagram for a database recording information about teams, players, and their fans, including For each team, its name, its players, its team captain (one of its players), and the colors of its uniform. For each players, his/her name. For each fan, his/her name, favorite teams, favorite players, and favorite colors.

Step 1 – Entity Sets Entity sets: Teams Players Fans Colors

Step 2 – Entity Sets and Attributes Teams: name Players: name Fans: name Colors: name

Step 3 – .. and Relationships Entity sets: Teams: name Players: name Fans: name Colors: name Relationships: Belongs_to: (Teams, Players) (1:m) Captain_of: (Teams, Players) (1:1) Uniform_of: (Teams, Colors) (1:m) Favorite_of: (Fans, Teams) (n:m) LikeP: (Fans, Players) (n:m) LikeC: (Fans, Colors) (n:m)

E/R diagram name name Fans Teams Colors Players name name Favorite_of LikeP LikeC Captain_of Belongs_to Uniform_of Colors Players name name

E/R diagram name name Fans Teams Colors Players name name Favorite_of LikeP LikeC Captain_of Belongs_to Uniform_of Colors Players name name

Homework name AccSets Has Customers Member_of Lives_at Accounts In Fig. 2.14 (see below) is an E/R diagram for a bank database involving customers and accounts. Since customers may have several accounts, and accounts may be held jointly by several customers, we associate with each customers an “account set”, and accounts are member of one or more account sets. Assuming the meaning of the various relationships and attributes are as expected given their names, criticize the design. What design rules are violated? Why? What modifications would you suggest? Fig. 2.14 AccSets Has owner address Customers name Accounts balance Lives_at Member_of Address number

Homework 2.4.4: Draw E/R diagram for the following situations involving weak entity sets. In each case indicate keys for entity sets. a. Entity sets Courses and Departments. A course is given by a unique department, but its only attribute is number. Different departments can offer courses with the same number. Each department has a unique name. b. Entity sets Leagues, Teams, and Players. League names are unique. No league has two teams with the same name. No team has two players with the same number. However, there can be players with the same number on different teams, and there can be teams with the same name in different leagues. 2.3.2: We can think of relationships in the E/R model as having keys, just as entity sets do. Let R be a relationship among the entity sets E1,…,En. Then a key for R is a set K of attributes chosen from the attributes of E1,…,En such that if the two tuples (e1,…,ek) and (f1,…,fk) are two entities of R then it is not possible for the two tuples to agree on every attributes belonging to K. Now suppose that R is a binary relationship. Let K1 and K2 be a key for the entity sets E1 and E2, respectively. In term of E1 and E2, give a smallest possible key for R under the assumption that a. R is many-many. b. R is many-one from E1 to E2. c. R is many-one from E2 to E1. d. R is one-one.