entity-relationship model chapter 3 ii cosc 457 sungchul hong

26
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong

Upload: eugene-dorsey

Post on 14-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Entity-Relationship Model

Chapter 3 II

COSC 457

Sungchul Hong

COMPANY Database

• DEPARTMENT– Name, Number, {Locations}, Manager, ManagerStartDate

• PROJECT– Name, Number, Location, ControllingDepartment

• EMPLOYEE– Name (FName, MInit, LName), SSN, Sex, Address, Salary,

BirthDate, Department, Supervisor, {WorksOn(Project, Hours)}

• DEPENDENT– Employee, DependentName, Sex, BirthDate, Relationship

Relationship, Relationship Types, and Structural Constraints

• In the initial design of entity types, relationships are typically captured in the from of attributes.

• The attribute Manager of DEPARTMENT refers to an employee who manages the department.

Relationship Types, Set and Instances

• A relationship type R among n entity types E1, E2, …, En defines a set of associations or a relationship set among entities from these types.

• The relationship set R is a set of relationship instances ri, where each ri associates n individual entities (e1, e2, …, en), and each entity ej in ri is a member of entity type Ej, 1 j n.

• A relationship type is a mathematical relation on E1, E2, …, En, or alternatively it can be defined as a subset of the Cartesian product E1E2 …En.

• Relationship instance ri=(e1,e2, …, en)

Mathematical Relations

• Sets D1 and D2 where D1 = {2, 4} and D2={1, 3, 5}.

• Cartesian product D1 D2, is the set of all ordered pairs such that the first element is a member of D1 and the second element is a member of D2.

– D1 D2 ={(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)}

Example

• The company is organized into departments. Each department has a unique name, a unique number, and a particular employee who manages the department. We keep track of the start date when that employee began managing the department. A department may have several locations.

Example (2)

• A department controls a number of projects, each of which has a unique name, a unique number, and single location.

• We store each employee’s name, social security number, address, salary, sex, and birth date. An employee is assigned to one department but may work on several projects, which are not necessarily controlled by the same department. We keep track of the number of hours per week that an employee works on each project. We also keep track of the direct supervisor of each employee.

User Requirement Example (3)

• We want to keep track of the dependents of each employee for insurance purposes. We keep each dependent’s first name, sex, birth date, and relationship to the employee.

Relationship Degree, Role Names, and Recursive Relationship

• Degree of a Relationship Type– The number of participating entity types.

• Binary, ternary, quaternary, and etc.

– E.g. WORKS_FOR has degree 2 or binary

• Relationships as Attributes– Attribute Department of the EMPLOYEE entity

• Role Names and Recursive Relationships– The role name signifies the role that a participating

entity from the entity type plays in each relationship instance.

Binary Relationship

Employee ProjectWorks_on

Supplier Project

Part

Supply

Employee Supervise

Constraints on Relationship Types

• Cardinality Ratios for Binary Relationships– 1:1 (MANAGES EMPLOYEE : DEPARTMENT)

– 1:N (WORK_FOR DEPARTMENT : EMPLOYEE)

– M:N (WORKS_ON EMPLOYEE : PROJECT)

• Participation Constraints and Existence Dependences (structural constraints)– Total participation (Double lines)

– Partial dependences

Attributes of Relationship Types

• 1:1

• 1:N

• N:M– Some attributes may be determined by the

combination of participating entities in a relationship.

– Attributes must be specified as relationship attributes

1

1

1

101

1

00

0

Min: Min:Max: Max:

1111

1

11

3

2

2

Min:

Max:

Min:

Max:

1231

2

1

2

2

Min:

Max:Min:

Max:

The (min,max) notation relationship constraints

(0,1)(1,1)

(1,1)(1,N)

(1,M)(1,N)

Weak Entity Types

• Entity types that do not have key attributes of their own.

• The relationship type that relates a weak entity type to its owner is called the identifying relationship of the weak entity type.

• Partial key: the set of attributes that can uniquely identify weak entities that are related to the same owner entity.

• Example: Employee{SSN, LName, FName} • Dependant{FName, DOB}

Example Relationships

• MANAGES

• WORKS_FOR

• CONTROLS

• SUPERVISION

• WORKS_ON

• DEPENDENTS_OF