Вы находитесь на странице: 1из 57

Entity Relationship Model

Introduction to Entity-Relationship (E-R) Modeling

Notation uses three main constructs

Data entities Relationships Attributes


A detailed, logical representation of the entities, associations and data elements for an organization or business

Entity-Relationship (E-R) Diagram

Entity-Relationship (E-R) Modeling


Key Terms

Entity

A person, place, object, event or concept in the user environment about which the organization wishes to maintain data Represented by a rectangle in E-R diagrams A collection of entities that share common properties or characteristics A named property or characteristic of an entity that is of interest to an organization

Entity Type

Attribute

Depicting Entities and Attributes

Conceptual Data Modeling and the E-R Diagram

Goal

Capture as much of the meaning of the data as possible If you know the rules of normalization, referential integrity, foreign keys, etc., this is good but not as important now. It is much more important to get the organizational data model correct, i.e. to understand the actual data requirements for the organization. A better design that is scalable and easier to maintain

Result

Example of Elements of E-R Model


Entity Sets Departments Professors Students Administrators Attributes Name of Departments, Phone No., Address... Name, SSN, Address of Professors... Relationship Students and Professors are under a certain department Admin manage the campus/ departments

Example of the 3 elements in E/R Diagram


Attribute Attribute Attribute

Entity A

Entity B

Entity C

Relationship

Classification of Constraints
1.

2.
3. 4.

Keys Single-value constraints Multi-valued constraints Mapping Cardinalities and Participation Constraints

Key in the E/R Model

Superkey is a set of one or more attributes that, taken collectively, for us to identify uniquely an item in the entity set. For example, customer-id is a superkey. Candidate key is a minimal superkey. For example, customer-name and customer-street is sufficient to distinguish among members of the customer entity set. Then {customer-name, customer-address } is a candidate key. Primary key denotes a candidate key that is chosen by the database designer as the principal means of identifying items within an entity set. the primary key should be chosen such that its attributes are never, or very rarely, changed. For example, Social-security numbers are guaranteed to never changed.

name
price

category

name

makes
Product

Company
stockprice

buys

employs

Person

address

name

ssn

Keys in E/R Diagrams

Every entity set must have a key

a key is an attribute that has a different value for every entity

name price Product

category

What is a Relation ?

A mathematical definition:

A={1,2,3},

if A, B are sets, then a relation R is a subset of A x B 1 a

B={a,b,c,d},

R = {(1,a), (1,c), (3,b)} A=

2 3

b c

- makes is a subset of Product x Company:


makes Product Company

B=

Single/Multi-valued attributes

Single-valued attributes are attributes that only have a single value for a particular entity. Multi-valued attributes refers to items that are not singled-value and Null valued. For example, consider an employee entity set with the attribute phone-number. An employee may have zero, one, or several phone numbers; different employee may have different numbers of phones.

Mapping Cardinalities or Cardinality ratios

Express the number of items to which another item can be associated via a relationship set Are most useful in describing binary relationship sets. For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following:

One to One One to Many Many to One Many to Many

Multiplicity of E/R Relations

one-one:
1 2 3

a b c d
a b c d

many-one

1 2 3

many-many
1 2 3

a b c d

Participation Constraints

The participation of an entity set E in a relationship set R is said to be total, if every item in E participates in at least one relationship in R. If only some items in E participate in relationship R, the participation of entity set E in relationship R is said to be partial.

Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every Departments entity must appear in an instance of the Manages relationship.

name ssn lot

since
dname

did
Manages

budget
Departments

Employees

Works_In

since

Degree of a Relationship Set


Refers to number of entity sets that participate in a relationship set. Relationship sets that involve two entity sets are binary (or degree two). Generally, most relationship sets in a database system are binary. Relationship sets may involve more than two entity sets. Relationships between more than two entity sets are rare. Most relationships are binary. Example: Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branch

Attributes
An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Domain the set of permitted values for each attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes Example: multivalued attribute: phone_numbers Derived attributes Can be computed from other attributes Example: age, given date_of_birth

Compposite Attributes

Keys for Relationship Sets


The combination of primary keys of the participating entity sets forms a super key of a relationship set. (customer_id, account_number) is the super key of depositor NOTE: this means a pair of entity sets can have at most one relationship in a particular relationship set. Must consider the mapping cardinality of the relationship set when deciding the what are the candidate keys Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key

Example: if we wish to track all access_dates to each account by each customer, we cannot assume a relationship for each access. We can use a multivalued attribute though

E-R Diagrams

Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes. Underline indicates primary key attributes.

E-R Diagram With Composite, Multivalued, and Derived Attributes

Roles

Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how employee entities interact via the works_for relationship set. Roles are indicated in E-R diagrams by labeling the lines that connectdiamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship.

Cardinality Constraints
We express cardinality constraints by drawing either a directed line (), signifying one, or an undirected line (), signifying many, between the relationship set and the entity set. One-to-one relationship: A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower.

One-To-Many Relationship
In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower

Many-To-One Relationships
In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower

Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower

Participation of an Entity Set in a Relationship Set


Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set E.g. participation of loan in borrower is total every loan must have a customer associated to it via borrower Partial participation: some entities may not participate in any relationship in the relationship set Example: participation of customer in borrower is partial

E-R Diagram with a Ternary Relationship

E-R Diagram for Movie Databse


Title year Name Address

Movies

Stars-in

Stars

length fileType owns Studios

Name

Address

ISA Hierarchies

Some objects in a class may be special


define a new class better: define a subclass PRODUCTS

Software Products

Educational Products

Subclasses
name category

price
Product

isa

isa

Software Product

Educational Product

platforms

Age Group

Understanding Subclasses

Think in terms of records:

Product
SoftwareProduct

field1 field2

field1 EducationalProduct field2


field3

field1 field2
field4 field5

Subclasses to Relations

Product
Name Gizmo Price 99 49 39 Categor y gadget photo gadget platform s unix Age Group todler retired

name
price

category

Camera Toy

Product

Sw.Product
isa

Name
Gizmo

isa

Ed.Product
Name
Gizmo Toy

Software Product platforms

Educational Product Age Group

Example-ISA
address birthday Movie Person id

name

ISA

picture

Actor

Director

Example - Requirements (1)

For actors and directors, we want to store their name, a unique identification number, address and birthday. For actors, we also want to store a photograph For films, we want to store the title, year of production and type (thriller, comedy, etc.) We want to know who directed and who acted in each film. Every film has one director. We store the salary of each actor for each film

Requirements (2)

An actor can receive an award for his part in a film. We store information about who got which award for which film, along with the name of the award and year. We also store the name and telephone number of the organization who gave the award. Two different organizations can give an award with the same name. A single organization does not give more than one award with a particular name per year.

birthday Movie Person name

id

phone number

name

Organization

ISA

Gives Won Award year name

picture salary

Actor Acted In

Director

Directed

year

Film title type

Weak Entity Sets

Weak entity sets are entity sets that are not uniquely identified by their attributes A weak entity set has an "identifying relationship" with an entity set that is the "identifying owner" of the weak entity set

Weak Entity Sets

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.

name ssn lot cost pname age

Employees

Policy

Dependents

Example
name

phone number

Organization

What would be the meaning if this was not a thick line?


year

Gives Won Award name

Example

Suppose that you were storing information about books. Should books be modeled as a weak entity set or a regular entity set?

Does ISBN identify a book

Copies of Books in Libraries


name Library Owned By author id Person

title

Book isbn Copy Of

Borrowed

Copy condition

copy number

Specialization

It is the process of defining a set of subclasses of a superclass. Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set. The set of subclasses based upon some distinguishing characteristics of entities in the superclass. Example:{SECRETARY,ENGINEER, DOCTOR} is a specialization of Employee based on Job type. Attribute of Sub class are called Specific Attributes.

Specialization Example

Aggregation

A bottom-up design process combine a number of entity sets that share the same features into a higher-level entity set. Several classes with common features are generalized into a superclass; oroginal classes become its subclasses. Example:CAR,TRUCK generalized into Vehicle. Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way. The terms specialization and generalization are used interchangeably.

Aggregation Example
name ssn Employees lot

Monitors

until

started_on pid Projects pbudget

since did

dname budget Departments

Sponsors

Constraints on Specialization and Generalization

EXAMPLE
Use the following business rules to write all appropriate connectivities in the E-R diagram: a. A department employs many employees, but each employee is employed by one department. b. Some employees, known as "rovers," are not assigned to any department. c. A division operates many departments, but each department is operated by one division d. An employee may be assigned to many projects, and a project may have many employees assigned to it. e. A project must have at least one employee assigned to it. f. One of the employees manages each department, and each department is managed by only one employee. g. One of the employees runs each division, and each division is run by one employee.

DIVISION

operates

DEPARTMENT

employs

manages

runs

EMPLOYEE

is assigned to

PROJECT

EXAMPLE

Given the following summary of business rules for the ROBCOR catering service, draw the ERD. Make sure to include all appropriate entities, relationships, connectivities, and cardinalities.

Each dinner is based on a single entree, but each entree can be served at many dinners. A guest can attend many dinners, and each dinner can be attended by many guests. Each dinner invitation can be mailed to many guests, and each guest can receive many invitations.

1 ENTREE (1,N) is part of M 1 (1,1) DINNER (1,N) (1,N) (1,1) M


INVITATION

M
ATTENDANCE

M (1,1) M (1,1)

1 GUEST (0,N) (1,N)

(1,1)

Вам также может понравиться