The E-R Model CS 157A Lecture 4 Prof. Sin-Min Lee

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Advertisements

1–1 Students Entity/Relationship Model Diagrams to represent designs. Entity like object, = “thing.” Entity set like class = set of “similar” entities/objects.
Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 541: Database Systems S. Muthu Muthukrishnan. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.)  What are the entities.
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Text-Book Chapters (7 and 8) Entity-Relationship Model
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
CS157A Lecture 3 ER Diagram Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Entity-Relationship Data Model CS 157A Professor Sin-Min Lee Student: Yen-Chu Pan.
Entity-Relationship Model Lecture 2. Database Modeling and Implementation Process Ideas ER DesignRelational Schema Relational DBMS Implementation.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
Winter 2002Arthur Keller – CS 1801–1 Computer Science 180: Database Systems Arthur M. Keller (best way to reach me) Office: Baskin.
Fall 2001Arthur Keller – CS 1801–1 Computer Science 180: Database Systems Arthur M. Keller (best way to reach me) Office: Baskin.
Introduction to Database Design Entity Relationship Model.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Entity-Relationship Model Database Management Systems I Alex Coman, Winter.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Chapter 2: Entity-Relationship Model (Continued)
Database Management COP4540, SCS, FIU Database Modeling Using the Entity-Relationship Model (Chapter 3)
Entity-Relationship Model
What is a Database Management System? 1. Manages very large amounts of data. 2. Supports efficient access to very large amounts of data. 3. Supports concurrent.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
Entity-Relationship Model
Entity-Relationship Model
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Entity-Relationship.
Databases : Entity-Relationship Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 7 Database Design and The E–R Model. 2 Goals n Facilitate DB design and represent the overall logical structure of the DB. n Definition Entities.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 6: Entity-Relationship Model.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts DB Schema Design: the Entity-Relationship Model What’s the use of the E-R model? Entity Sets.
Entity-Relationship Model Using High-Level Conceptual Data Models for Database Design Entity Types, Sets, Attributes and Keys Relationship Types, Sets,
Computing & Information Sciences Kansas State University Wednesday, 24 Sep 2008CIS 560: Database System Concepts Lecture 12 of 42 Wednesday, 24 September.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
Entity-Relationship Model
Entity Relationship Diagram (2)
ITTelkom Entity Relationship Diagram (1) CS2343 Perancangan Basisdata Relasional.
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.
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
ICOM 5016 – Introduction to Database Systems Lecture 5 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Computing & Information Sciences Kansas State University Friday, 26 Sep 2008CIS 560: Database System Concepts Lecture 13 of 42 Friday, 26 September 2008.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Entity-Relation Model. E-R Model The Entity-Relationship (ER) model was originally proposed by Peter in 1976 ER model is a conceptual data model that.
 Design Process  Modeling  Constraints  E-R Diagram  Design Issues  Weak Entity Sets  Extended E-R Features  Design of the Bank Database  Reduction.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
Data Modeling Using the Entity-Relationship (ER) Data Model.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
CS157A Lecture 4 ER Model 2 Prof. Sin-Min Lee Department of Computer Science San Jose State University.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Lecture 26 Enterprise Systems Development ( CSC447 ) COMSATS Islamabad Muhammad Usman, Assistant Professor.
Topic 3: ER – Entity Relationship Model (ERM) 6/12/
A short review on entity- relationship modelling.
Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an.
COP Introduction to Database Structures
Entity Relationship Model
Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Chapter 6: Entity-Relationship Model
Presentation transcript:

The E-R Model CS 157A Lecture 4 Prof. Sin-Min Lee Department of Computer Science

Entity-Relationship (E-R) Model COURSE# CTITILE PROF SCHED ROOM COURSE ENROLL GRADE STUDENT SNAME CREDITS STUID MAJOR

Class Hierarchies * Sometimes it’s natural to classify the entities in an entity set into subclass, then we will use Class Hierarchies. name lot ssn Employees Hourly wage Hours worked ISA contractid Hourly Emps Contract Emps

Aggregation * A relationship set is an association between entity sets. Sometimes we have to model a relationship between a collection of entities and relationships, then we need to use aggregation. Aggregation name ssn lot Employees monitors until Started-on dname since pid pbudget did budget Sponsors Projects Department

Conceptual design using the ER model Should a concept be modeled as an entity or an attribute ? Should a concept be modeled as an entity or a relationship ? What are the relationships ? Should we use binary or ternary relationships ? Should we use aggregation ?

UNARY RELATIONSHIP Arthur Keller – CS 180 Winter 2002 Unary relationship : is an associate of 1 entity set. * Note : an entity set is a group of related entities. Dr. Lee Student * Entity set = * Relation = * Attribute =

BINARY RELATIONSHIP Binary relationship : is an associate of 2 entities sets . Works_In Employees Department ssn name lot dname budget did * Entity set = * Relation = * Attribute =

TERNARY RELATIONSHIP Ternary relationship : is an associate of 3 entities sets . Works_In Employees Department ssn name lot did budget dname Locations add cap * Entity set = * Relation = * Attribute =

QUARTERY RELATIONSHIP Quartery relationship : is an associate of 4 entities sets. Product Works_In Employees Department Locations * Entity set = * Relation = * Attribute =

Additional features of the ER model In the ER model allow us to draw important distinctions about the data. One of the features of the ER model is : Key Constraints Note : A key constraints is also known as Primary key. A primary key is a candidate key selected to uniquely identify all other attribute values in any given row, can not contain null entries.

An example of Key Constraints on Manage name Since dname budget did ssn lot Manages Department Employees ssn = Social Security Number. did = Department id.

Weak Entities name cost age ssn lot Policy Department Employees Pname --------- age ssn lot Policy Department Employees A weak entity : is an entity of which is existence depends on other entities.

Entity versus Attribute from to name dname budget did ssn lot Works-In2 Department Employees * Entity set = * Relation = * Attribute =

Entity versus Relationship dname name did budget ssn lot Manages Department Employees since apptnum Mgr-Appts dbudget

Binary versus Ternary Relationship name Pname --------- age ssn lot Covers Dependents Employees Policies policyid cost

Using a Ternary Relationship instead of Aggregation Started-on dname did budget pid pbudget Sponsors Departments Projects Employees lot ssn name

ONE TO MANY RELATIONSHIP customer-name customer-street loan-number amount customer-city customer-id borrower loan customer

MANY TO ONE RELATIONSHIP customer-name customer-street loan-number amount customer-city customer-id borrower loan customer

ONE TO ONE RELATIONSHIP customer-name customer-street loan-number amount customer-city customer-id borrower loan customer

E-R Diagram with Composite, Multivalued, and Derived Attributes street-name middle-name Street-number apartment-number last-name first-name street name city customer-id address state Customer zip-code age date-of-birth phone-number

WEAK ENTITY SETS An entity set may not have sufficient attributes to form a primary key. Such an entity set is termed a weak entity set. An entity set that has a primary key is termed a strong entity set. For a weak entity set to be meaningful, it must be associated with another entity set, called the identifying or owner entity set. The relationship associating the weak entity set with the identifying entity set is called the identifying relationship. The identifying relationship is many to one from the weak entity set to the identifying entity set, and the participation of the weak entity set in the relationship is total.

DISCRIMINATOR The discriminator of a weak entity set is a set of attributes that allows this distinction to be made. For example, the discriminator of a weak entity set payment is the attribute payment-number, since, for each loan a payment number uniquely identifies one single payment for that loan. The discriminator of a weak entity set is also called the partial key of the entity set. Note: although each payment entity is distinct, payments for different loans may share the same payment-number. Thus, payment entity set does not have a primary key; it is a weak entity set. The primary key of a weak entity set is formed by the primary key of the identifying entity set, plus the weak entity set’s discriminator.

E-R DIAGRAM WITH A WEAK ENTITY SET In a E-R diagrams, a doubly outlined box indicates a weak entity set, and a doubly outlined diamond indicates the corresponding identifying relationship. We underline the discriminator of a weak entity set with a dashed line. payment-date amount loan-number payment-number payment-amount loan-payment loan payment E-R diagram with a weak entity set

Entity/Relationship Model Diagrams to represent designs. Entity like object, = “thing.” Entity set like class = set of “similar” entities/objects. Attribute = property of entities in an entity set, similar to fields of a struct. In diagrams, entity set  rectangle; attribute  oval. name phone ID Students height

Relationships Connect two or more entity sets. Represented by diamonds. Taking Students Courses

Relationship Set Think of the “value” of a relationship set as a table. One column for each of the connected entity sets. One row for each list of entities, one from each set, that are connected by the relationship. Students Courses Sally CS180 Sally CS111 Joe CS180 … …

Multiway Relationships Usually binary relationships (connecting two E.S.) suffice. However, there are some cases where three or more E.S. must be connected by one relationship. Example: relationship among students, courses, TA's (and graders). Possibly, this E/R diagram is OK: Taking Students Courses Assisting TA/Graders

But what if students were divided into sections, each headed by a TA? Works in CS180, because each TA (or grader) is a TA of all students. Connection student-TA is only via the course. But what if students were divided into sections, each headed by a TA? Then, a student in CS180 would be related to only one of the TA's for CS180. Which one? Need a 3-way relationship to tell.

Students Courses TAs Ann CS180 Jan Sue CS180 Pat Bob CS180 Jan … … … Enrolls Students TAs Students Courses TAs Ann CS180 Jan Sue CS180 Pat Bob CS180 Jan … … …

Beers-Bars-Drinkers Example Our running example for the course. name addr license Frequents Serves Bars Likes Beers Drinkers name manf name addr

Multiplicity of Relationships Many-many Many-one One-one Representation of Many-One E/R: arrow pointing to “one.” Rounded arrow = “exactly one.”

Example: Drinkers Have Favorite Beers name addr license Frequents Serves Bars Likes Beers Drinkers Favorite name manf name addr

One-One Relationships Put arrows in both directions. Design Issue: Is the rounded arrow justified? Here, manufacturer is an E.S. In earlier diagrams it is an attribute. Which is right? Best- seller Manfs Beers

Attributes on Relationships price Sells Bars Beers Shorthand for 3-way relationship: price Prices Sells Bars Beers

A true 3-way relationship. Price depends jointly on beer and bar. Notice arrow convention for multiway relationships: “all other E.S. determine one of these.” Not sufficiently general to express any possibility. However, if price, say, depended only on the beer, then we could use two 2-way relationships: price-beer and beer-bar. Or better: just make price an attribute of beer.

Converting Multiway to 2-Way Baroque in E/R, but necessary in certain “object-oriented” models. Create a new connecting E.S. to represent rows of a relationship set. E.g., (Joe's Bar, Bud, $2.50) for the Sells relationship. Many-one relationships from the connecting E.S. to the others. BBP The- Bar The- Beer The- Price Bars Beers Price

Roles Sometimes an E.S. participates more than once in a relationship. Label edges with roles to distinguish. Married Husband Wife d1 d2 d3 d4 … … husband wife Drinkers

Notice Buddies is symmetric, Married not. Design Question Buddy1 Buddy2 d1 d2 d1 d3 d2 d1 d2 d4 … … Buddies 1 2 Drinkers Notice Buddies is symmetric, Married not. No way to say “symmetric” in E/R. Design Question Should we replace husband and wife by one relationship spouse?

More Design Issues 1. Subclasses. 2. Keys. 3. Weak entity sets. (Next class.)

Subclasses Subclass = special case = fewer entities = more properties. Example: Ales are a kind of beer. In addition to the properties (= attributes and relationships) of beers, there is a “color” attribute for ales.

E/R Subclasses Assume subclasses form a tree (no multiple inheritance). isa triangles indicate the subclass relation. Beers name manf isa Ales color

Different Subclass Viewpoints 1. E/R viewpoint: An entity has a component in each entity set to which it logically belongs. Its properties are the union of the properties of these E.S. 2. Contrasts with object-oriented viewpoint: An object (entity) belongs to exactly one class. It inherits properties of its superclasses. Beers name manf isa Pete’s Ale Ales color

Multiple Inheritance Theoretically, an E.S. could be a subclass of several other entity sets. name manf name manf Beers Wines isa isa Grape Beers

Problems How should conflicts be resolved? Example: manf means vintner for wines, bottler for beers. What does manf mean for “grape beers”? Need ad-hoc notation to resolve meanings. In practice, we shall assume a tree of entity sets connected by isa, with all “isas” pointing from child to parent.

Keys A key is a set of attributes whose values can belong to at most one entity. In E/R model, every E.S. must have a key. It could have more than one key, but one set of attributes is the “designated” key. In E/R diagrams, you should underline all attributes of the designated key.

Example Suppose name is key for Beers. Beer name is also key for ales. In general, key at root is key for all. Beers name manf isa Ales color

Example: A Multiattribute Key number hours Courses dept room Possibly, the combination of hours + room also forms a key, but we have not designated it as such.