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.

Slides:



Advertisements
Similar presentations
The Entity-Relationship Model
Advertisements

Conceptual Design using the Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The 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.
1 Key Constraints Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager,
The Entity-Relationship (ER) Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The Entity-Relationship Model
Comp3300/fall021 The Entity-Relationship Model Chapter 2 What are the steps in designing a database ? Why is the ER model used to create an initial design?
The Entity-Relationship Model
The Entity-Relationship Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Conceptual Design and The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 176 Database Systems I The Entity-Relationship Model.
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.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
The Entity-Relationship Model
Conceptual Design Using the Entity-Relationship (ER) Model
The Entity- Relationship Model CS 186 Fall 2002: Lecture 2 R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move.
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
Introduction to Database Design Entity Relationship Model.
The Entity- Relationship Model R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move forward or it dies. And I.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
ER continued, and ER to Relational Mappings R&G Chapters 2, 3 Lecture 22.
Modeling Your Data Chapter 2. Part II Discussion of the Model: Good Design/ Bad Design?
1 The Entity-Relationship Model Chapter 2. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
ISOM MIS710 Module 1a Data and Process Modeling Arijit Sengupta.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
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.
1 The Entity-Relationship Model Chapter 6. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Chapter 2.  Conceptual design: (ER Model is used at this stage.) ◦ What are the entities and relationships in the enterprise? ◦ What information about.
CMPT 258 Database Systems The Entity-Relationship Model Part II (Chapter 2)
ICS 321 Spring 2011 High Level Database Models Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 2/7/20111Lipyeow.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
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.
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
Database Management Systems,1 Conceptual Design Using the Entity-Relationship (ER) Model.
1 Conceptual Design using the Entity- Relationship Model.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
CSC 411/511: DBMS Design 1 1 Dr. Nan WangCSC411_L2_ER Model 1 The Entity-Relationship Model (Chapter 2)
ER & Relational: Digging Deeper R &G - Chapters 2 & 3.
Modeling Your Data Chapter 2 cs5421. Part II Discussion of the Model: Good Design/ Bad Design? cs5422.
Database Management Systems 1 Raghu Ramakrishnan The Entity-Relationship (ER) Model Chpt 2 Instructor: Jianping Fan
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Design: Conceptual Modeling with ER Model CENG 351.
1 Introduction to Data Management Lecture #3 (Conceptual DB Design) Instructor: Chen Li.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
COP Introduction to Database Structures
The Entity-Relationship Model
Modeling Your Data Chapter 2 cs542
Instructor: Elke Rundensteiner
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship (ER) Model
Presentation transcript:

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 your database application, you need to collect the requirements, and build a conceptual model. ER model is a widely accepted standard for conceptual DB design.

title name age pname Dependents Employees ssn Policy cost AN Entity Relationship (ER) Diagram Looks Like This

ER Model Key concepts of ER model Entities Relationships Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes #Cengiz# Beykent University #DBMS_course# Your computer ….. Entity Set: A collection of similar entities. E.g. all employees. All entities in an entity set have the same set of attributes. Each entity has a key Each attribute has a domain

ER Model Entity Has attributes that describe it name address idid

ER Model Entity set: Is the set of entities that share the same properties Cengiz hc. Bülent hc. Talat hc. Necati hc. Instructors Courses DBMS DataMining Automata

ER Model Entity sets may overlap Example? Employees Managers

ER Model Relationships: Association among two or more entities Relate two or more entities (such as Serafettin is enrolled in DBMS) Relationship sets: Collection of all relationships with the same properties (all student enrollments) Relationships may also have attributes

ER Model Rectangles : Entity sets Ellipses : attributes student name sid

ER Model Rectangles : Entity sets Ellipses : attributes student Course name sid cid cname

ER Model Rectangles : Entity sets Diamonds : Relationship Sets Ellipses : attributes Enrolled student Course name sid cid cname

ER Model Each entity set has attributes Each attribute has a domain (domain is the set of permitted values) student name sid

ER Model Each entity set has attributes Each attribute has a domain (domain is the set of permitted values) Each entity set has a key Keys are denoted by underlining the attribute name in the ER diagram student name sid

ER Model Relationship sets also have attributes ER Model Enrolled student Course name sid cid cname

ER Model Relationship sets also have attributes We are going to talk about the key in a relationship set later on ER Model Enrolled student Course name semester sid cid cname

ER Model Degree of a relationship set is the number of entity sets that participate in a relationship Binary relationship sets involve two entity sets ER Model Enrolled student Course name semester sid cid cname

ER Model Ternary relationship sets involve three entity sets customer borrows loan branch

ER Model We may have relationships among the entities that belong to the same entity set each entity has a role in such a relationship student namesid helps students

ER Model We may have relationships among the entities that belong to the same entity set each entity has a role in such a relationship student namesid helps tutor tutee

ER Model We may have relationships among the entities that belong to the same entity set (each entity has a role in such a relationship) What is the degree of the following relationship set (2 or 1)? student namesid helps tutor tutee

ER Model employer enameeid

ER Model employer enameeid Reports_to

ER Model employer enameeid Reports_to supervisor

ER Model employer enameeid Reports_to supervisor subordinate

ER Model Ternary relationship sets customer loan branch

ER Model Ternary relationship sets customer borrows loan branch

Mapping cardinalities 1-to-1 One-to-One relationship (ex: marriage relationship set between husbands and wives)

Mapping cardinalities 1-to-11-to Many One-to-One (ex: marriage relationship set between husbands and wifes) One-to-Many (example?)

Mapping cardinalities 1-to-11-to ManyMany-to-1 One-to-One (ex: marriage relationship set between husbands and wifes) One-to-Many Many-to-One

Mapping cardinalities Many-to-Many 1-to-11-to ManyMany-to-1 One-to-One (ex: marriage relationship set between husbands and wifes) One-to-Many Many-to-One Many-to-Many

1-to-11-to ManyMany-to-1 Consider the works_in relationship If an employee can work in multiple departments and a department can have multiple employees What type of relationship is that? dname budget did since name Works_In DepartmentsEmployees ssn lot

Many-to-Many 1-to-11-to ManyMany-to-1 Consider the manages relationship If an employee can manage multiple departments but a department has only one manager What type of relationship is that? This is called a key constraint (denoted with an arrow) dname budget did since name Manages DepartmentsEmployees ssn lot

Participation Constraints If every department MUST have a manager, then there is a participation constraint The participation of Departments in Manages is total (otherwise it is partial). lot name dname budgetdid since name dname budgetdid since Manages since Departments Employees ssn Works_In

Participation Constraints If every department MUST have a manager, then there is a participation constraint The participation of Departments in Manages is total (otherwise it is partial). Participation constraints are denoted with a thick line (for example each department must participate in the manages relationship, therefore this is denoted with a thick line in the relationship) lot name dname budgetdid since name dname budgetdid since Manages since Departments Employees ssn Works_In

Participation Constraints If every employee MUST work in a department, then there is a participation constraint on employee entity set lot name dname budgetdid since name dname budgetdid since Manages since Departments Employees ssn Works_In

Participation Constraints Plus, if every department MUST have employee(s) working in that department, then there is a participation constraint on department entity set lot name dname budgetdid since name dname budgetdid since Manages since Departments Employees ssn Works_In

ISA (`is a’) Hierarchies Contract_Emps name ssn Employees lot hourly_wages Hourly_Emps contractid hours_worked

ISA (`is a’) Hierarchies Contract_Emps name ssn Employees lot hourly_wages ISA Hourly_Emps contractid hours_worked

ISA (`is a’) Hierarchies Contract_Emps name ssn Employees lot hourly_wages ISA Hourly_Emps contractid hours_worked Overlap constraints: Can Serafettin be an Hourly Employee as well as a Contract Employee? Covering constraints: Does every Employee also have to be an Hourly Employee or a Contract Employee? Reasons for using ISA : To add descriptive attributes specific to a subclass. To identify entities that participate in a relationship. Specialization vs. generalization

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. lot name age pname Dependents Employees ssn Policy cost

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. A weak entity set is denoted by a rectangle with thick lines lot name age pname Dependents Employees ssn Policy cost

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. A weak entity set is denoted by a rectangle with thick lines The relationship between a week entity and the owner entity is denoted by a diamond with thick lines. lot name age pname Dependents Employees ssn Policy cost

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. What can you say about the constraints on the indentifying relationship? (i.e., participation and key constraints) lot name age pname Dependents Employees ssn Policy cost

Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to- many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. lot name age pname Dependents Employees ssn Policy cost

Aggregation Used when we have to model a relationship involving (entitity sets and) a relationship set. Aggregation allows us to treat a relationship set as an entity set for purposes of participation in (other) relationships. * Aggregation vs. ternary relationship : Monitors is a distinct relationship, with a descriptive attribute. Also, can say that each sponsorship is monitored by at most one employee. budget did pid started_on pbudget dname until Departments Projects Sponsors Employees Monitors lot name ssn since

Conceptual Design Using the ER Model Design choices: Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? Constraints in the ER Model: A lot of data semantics can (and should) be captured. But some constraints cannot be captured in ER diagrams.

Entity vs. Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Depends upon the use we want to make of address information, and the semantics of the data: If we have several addresses per employee, address must be an entity (since attributes cannot be set-valued). If the structure (city, street, etc.) is important, e.g., we want to retrieve employees in a given city, address must be modeled as an entity (since attribute values are atomic).

Entity vs. Attribute (Contd.) Works_In2 does not allow an employee to work in a department for two or more periods. Similar to the problem of wanting to record several addresses for an employee: we want to record several values of the descriptive attributes for each instance of this relationship. name Employees ssn lot Works_In2 from to dname budget did Departments dname budget did name Departments ssn lot Employees Works_In3 Duration from to

Binary vs. Ternary Relationships If each policy is owned by just 1 employee: Key constraint on Policies would mean policy can only cover 1 dependent! age pname Dependents Covers name Employees ssn lot Policies policyid cost Beneficiary age pname Dependents policyid cost Policies Purchaser name Employees ssn lot Bad design Better design

Entity vs. Relationship First ER diagram OK if a manager gets a separate discretionary budget for each dept. What if a manager gets a discretionary budget that covers all managed depts? Redundancy of dbudget, which is stored for each dept managed by the manager. Misleading: suggests dbudget tied to managed dept. Manages2 name dname budget did Employees Departments ssn lot dbudget since Employees since name dname budget did Departments ssn lot Mgr_Appts Manages3 dbudget apptnum

Summary of Conceptual Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies, and aggregation. Note: There are many variations on ER model.

Summary of ER (Contd.) Several kinds of integrity constraints can be expressed in the ER model: key constraints, participation constraints, and overlap/covering constraints for ISA hierarchies. Some foreign key constraints are also implicit in the definition of a relationship set. Some constraints (notably, functional dependencies) cannot be expressed in the ER model. Constraints play an important role in determining the best database design for an enterprise.

Summary of ER (Contd.) ER design is subjective. There are often many ways to model a given scenario! Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, binary or n-ary relationship, whether or not to use ISA hierarchies, and whether or not to use aggregation. Ensuring good database design: resulting relational schema should be analyzed and refined further. FD information and normalization techniques are especially useful.