Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entity-Relationship Model Ch. 3

Similar presentations


Presentation on theme: "Entity-Relationship Model Ch. 3"— Presentation transcript:

1 Entity-Relationship Model Ch. 3
Mr John Ortiz

2 Overview of Database Design
Steps in building a database for an application Requirement analysis. Specify what need to be modeled in a real-world domain Conceptual design. Specify a high level schema using a database design model Logical design. Refine a conceptual design to a schema using the data model of a DBMS Physical design. Define the schema using the DDL of the DBMS Database creation. Load data into a database Lecture 2 Entity-Relationship Model

3 Overview of Database Design
Real-world domain Database design model (ER, OO) DBMS data model (relational, OO, OR) Design-to-DBMS step may be automated (e.g., ER-to-relational) Middle step sometimes skipped (directly to relational model) Lecture 2 Entity-Relationship Model

4 Entity-Relationship Model
Requirement Analysis Need to interact with domain experts Application specific Time consuming Very important Difficult to be thorough Lecture 2 Entity-Relationship Model

5 Entity-Relationship Model
A Sample Requirement Consider a regional hospital. There are doctors, patients, nurses, prescriptions, tests, … Each doctor has Id, Name, Specialty, Age, Sex, … Patients see doctors, doctors prescribe drugs to patients, … Each patient has one primary care physician, a nurse is assigned to at most 5 patients, … Lecture 2 Entity-Relationship Model

6 Entity-Relationship Model
Conceptual Design Design a high level schema based on requirements Why do we do a conceptual design? To communicate with domain experts (use concepts of the application domain). It is easier to set up a good model (focus on data content not structure) Flexible (system independent, hmm… ) How to describe a conceptual design? Use an ER Diagram (most popular) Lecture 2 Entity-Relationship Model

7 Entity-Relationship Model
Proposed by Peter Chen in 1976 Historically very popular Graphical Major concepts: entity type, relationship type, attribute, constraints, … Lecture 2 Entity-Relationship Model

8 Entity-Relationship Model
Entity Type Entity. A real-world object distinguishable from other objects. Each entity is described by a set of attributes (or properties). Entity Type. A definition of a collection of entities with identical set of attributes. Students ssn name gpa  Can informally think of entities as records Lecture 2 Entity-Relationship Model

9 Entity-Relationship Model
Relationship Type Relationship. An association between two or more entities (usually of different types). A relationship may also have attributes. Relationship Type. A definition of a collection of relationships with the identical set of attributes. gpa title credit cno grade name Enrolled Courses Students ssn Not every entity participates in a relationship Lecture 2 Entity-Relationship Model

10 Entity-Relationship Model
Attributes Domain of an attribute. The set of values the attribute may take. Many types of attributes. (simple vs composite, single-value vs multi-value, stored vs derived) Students ssn gpa name fname minit lname hobby bdate age Lecture 2 Entity-Relationship Model

11 Degree of Relationships
Degree. Number of entity types involved in a relationship type. (unary, binary, ternary, … ) Role. Part played by entities of a unary relationship. Reports_To lot name subor-dinate super-visor ssn Employees name city S# Suppliers P# color Parts Order Projects J# dept qty Lecture 2 Entity-Relationship Model

12 Entity-Relationship Model
Key Constraint Key Attribute(s). A set of attributes of an entity type whose values are unique for each entity of that type. Key Constraint. Every (almost!) entity type must have a key attribute(s). (e.g., ssn of Students) Lecture 2 Entity-Relationship Model

13 Participation Constraint
Participation Constraint. Whether or not every entity in an entity type participates in a type of relationship. Either total or partial. gpa grade name takes Students ssn title credit cno Courses Every course is taken by some students Lecture 2 Entity-Relationship Model

14 Cardinality Constraints
Cardinality Ratio. Whether or not an entity of a type may involve in a type of relationship with multiple entities of another type. One-to-one (1-to-1). Each entity in E1 is associated with 0 or one entity in E2, and vice versa. Employees manages Departments ssn dno name age since room 1 Other notation exists Lecture 2 Entity-Relationship Model

15 Cardinality Constraints
One-to-many (1-to-m). Each entity in E1 is associated with 0 or more entities in E2, and each entity in E2 is associated with 0 or one entity in E1. The reverse is many-to-one (m-to-1). Professors advises Students ssn name room gpa 1 m To determine for Student, fix a Professor, see how many students are advised by him. Lecture 2 Entity-Relationship Model

16 Cardinality Constraints
Many-to-many (m-to-n). Each entity in E1 is associated with 0 or more entities in E2, and vice versa. Students takes Courses ssn cno name gps title credit m n grade This is the default if not labeled Lecture 2 Entity-Relationship Model

17 Multiway Relationships
What does it say? Parts Suppliers Projects order m n r Pick an entity from each of the other 2 entity types, how many entities in the third entity type are associated with the pair? What if r = 1? What if both r =1 and n=1? Lecture 2 Entity-Relationship Model

18 Entity-Relationship Model
Weak Entity Type Weak Entity Type. An entity type without its own key. Typically have a partial key. Must totally participate in an identifying relationship with a strong entity type. The relationship must be m-to-1 or 1-to-1. Universities have Student_clubs name cname city size phone type 1 m How to refer to a weak entity? Lecture 2 Entity-Relationship Model

19 Extended ER Model (EER)
Structural Constraint. The min & max number of relationships in R that each entity in E must participate. E (min, max) R Students takes Courses ssn cno name gps title credit (1,5) (5,40) grade Lecture 2 Entity-Relationship Model

20 Cardinality ve Structural
Cardinality Structural R E (0, 1) F 1 (0, m) m (0, n) n (1, 1) The labels are placed in reverse order. Lecture 2 Entity-Relationship Model

21 Entity-Relationship Model
Look Ahead Next topic: Relational Data Model Read from the textbook: Chapter Lecture 2 Entity-Relationship Model


Download ppt "Entity-Relationship Model Ch. 3"

Similar presentations


Ads by Google