Top Banner
Entity-Relationship Modeling In this section you are introduced to Entity- Relationship modeling a popular way to design databases.
46

Database Systems - Entity Relationship Modeling (Chapter 4/2)

Feb 21, 2017

Download

Data & Analytics

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity-Relationship Modeling

In this section you are introduced to Entity-Relationship modeling a popular way to

design databases.

Page 2: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Why Data Modeling?

•To understand “meaning” or “semantics” of data

•To communicate about information requirements (among the project members and customers)

•To use it as conceptual data model of database (our interest)

Page 3: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Understanding Data

The understanding of data involves understanding:

Each user’s perspective of the data

The nature of the data independent of its physical representation

The use of the data across user views.

Page 4: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Good Data Model Characteristics

SNO Characteristic

1 Structural Validity

2 Simplicity

3 Expressibility

4 Nonredundancy

5 Shareability

6 Extensibility

7 Integrity

8 Diagrammatic Representation

Page 5: Database Systems - Entity Relationship Modeling (Chapter 4/2)

ER Model Concepts

Entity

Entity Type

Entity Set

Relationship

Relationship Type

Relationship Set

Week Entities

Page 6: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity

An entity is an “object” in the real world that is distinguishable from all other objects.

An entity may be a concrete or an abstract object.

Each entity may have one or more of properties.

Page 7: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Examples

Each person in an organization is an entity. It is a concrete entity.

If the organization employs 150 persons, then it means the organization has 150 person entities.

If there is a person by name john, then john is an entity. We used the term john even though the person has first name, last name, designation, etc., because the name uniquely distinguishes the entity from the remaining 149 entities.

Page 8: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Examples (contd...)

Similarly each department in an organization is an entity. (abstract)

Each purchase order is an entity. (concrete)

Each course in a university is an entity. (abstract)

Each university itself is also an entity. (concrete)

Each book is an entity. (concrete)

Each flight reservation is an entity. (abstract)

Page 9: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Attributes

An attribute of an entity describes a specific characteristic or property of the entity.

For example, first name is an attribute of person entity. color is an attribute of entity car. Another attribute is price.

Depending the database requirements, you choose the attributes for entities.

Page 10: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Attribute Examples

Attributes of some entity types are as follows:

Entities Attributes

person person id, first name, last name,

dob, address

book book id, title, author, publisher,

price

course course id, title, teacher

Page 11: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Types

An entity type is a named set of attributes of similar entities.

Examples of entity types Person, Book and Course.

Person: {person id, first name, last name, dob, address }

Book: {book id, title, author, publisher, price}

Course: {course id, title, teacher}

Note that we used id columns (person id, book id, course id) in each entity type so that we can uniquely identify each entity.

Page 12: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Set

An entity set is a named collection of entities having the same attributes.

Example:

An entity set for persons could be as follows:

Persons: {<1001, ‘Hari’, ‘KVS’, 1962-01-20, ‘Hyderabad’, ‘301, Banjara Hills’>,

<1002, ‘Mathews’, ‘Philips’, 1965-08-10, ‘Bangalore’, ‘10, Nagavara’>

}

This entity set has two entities.

Page 13: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Simple Attribute

An attribute that can not be divided into two or more components is a simple attribute.

Examples of simple attributes are:

person id, first name, last name and dob.

Page 14: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Composite Attribute

A composite attribute consists of multiple components where each component has its own independent existence.

An example is attribute address. An example value for address is “305, 2nd C Main Road, 8th Block, Koramangala, Bangalore” where each component has it own existence. “305” is a house number, “2nd C Main Road” is street , “8th Block” indicates small area, and “Koramangala” is an area of “Bangalore”.

Based on the application requirements, the attribute is retailed as composite attribute or split into its component simple attributes.

Page 15: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Single-Valued Attributes

A single-valued attribute is an attribute that can contain only single value in each entity of an entity type.

For example, attributes person id, first name, last name and dob in the following example are single valued attributes:

person- id fist name last name phone dob

1001 Akhil M 7498750138

8035621234

1997-01-18

1002 Bhargav Tamiri 9498012398 1997-03-15

1003 Krishna S 8012398654

9449010137

1990-11-25

Page 16: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Multi-Valued Attributes

A multi-valued attribute is an attribute that can contain multiple values in each entity of an entity type.

For example, attribute phone may have multiple phone numbers in each entity of entity type Person.

person- id fist name last name phone dob

1001 Akhil M 7498750138

8035621234

1997-01-18

1002 Bhargav Tamiri 9498012398 1997-03-15

1003 Krishna S 8012398654

9449010137

1990-11-25

Page 17: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Derived Attributes

A derived attribute is an attribute that has its value derived from one or more attributes not necessarily from the same entity type.

For example, attribute age in Person is a derived attribute as its value is derived from dob.

person-

id

fist

name

… phone dob age

1001 Akhil .. 7498750138

8035621234

1997-01-18 16

1002 Bhargav … 9498012398 1997-03-15 16

1003 Krishna … 8012398654

9449010137

1990-11-25 23

Page 18: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Domain

A domain is a set of values an attribute of an entity set can have in an entity.

Sample domains:

Attribute Domain

first name set of 30 character strings

color red, green, silver, white

price 30000 to 70000

rating 0 to 10

Page 19: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Keys

A key is a minimal set of attributes whose values uniquely identify an entity in an entity set.

Entity Set Key

Persons person id

Books book id

Courses course id

Student Marks roll number, subject id

Page 20: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Candidate Key and Primary Key

An Entity Set or Entity Type may have more than one key. Each key is known as candidate key. One of the candidate keys is designated as primary key used as the main key for the entity set.

Example: Account(customer number, PAN number, aadhaar number, first name, last name, balance)

Candidate keys: customer number, PAN number, aadhaar number

Primary key: customer number

Page 21: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of Entity Type

Entity type is represented using a rectangular box with entity type name written inside it.

Examples of Entity Types:

Person Book

Page 22: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of Entity Set

Diagram used for entity sets is the same that is used for entity types:

Examples of Entity Sets:

Persons Books

Page 23: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Entity Type Versus Entity Set

1. In an ER model, use either entity types or entity sets.

2. Do not use a mix of entity types and entity sets in the ER diagrams.

3. Use naming conventions consistently.

4. Though the slides use singular names for entity types and plural names for entity sets, you can use any name you want.

Page 24: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of Entity Type Attributes

Entity type attributes are represented in the bottom portion of rectangular box separated by a line from entity type name.

An examples of Entity Type with attributes:

Employee

Employee Number

First name

Last name

Date of birth

Designation

Department Name

Page 25: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Relationship

A relationship is an association between two or more entities.

For example, there is a borrow relationship between entity sets Persons and Books to indicate that a person (entity of entity set Persons) borrows one or more books (entities of entity set Books). We can also say the relationship between Books and Persons is borrowed by to indicate a book is borrowed by zero or one person.

Primary key values of participating entities will identify the relation.

Page 26: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Relationship Type

A relationship type represents collection of associations of similar type.

Similar types of associations means associations having the same attributes from participating entity types or sets. Attribute set (person id, book_id) represents a relationship type. A name that could be given to the relationship type is Borrower. The relationship type can be specified as Borrower(person id, book id).

Page 27: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Relationship Set

A relationship set is an instance of a relationship type. It means one or more associations of a relationship type is a relationship set.

For example relationship set Borrowers of relationship type Borrower(person id, book id) could be as follows:

{ <1001, 12956>, <1001, 23567>, <1002, 12345>}

Page 28: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Relationships Explained using Semantic Net

Person Book Borrows

p1

p2

p3

b1

b2

b3

b4

r1

r2

r3

Page 29: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of Relationship

Relationship between two entity types is represented with a line as shown in the following diagram:

Person Book

Borrows

Page 30: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Degree of Relationship Type

Number of entity types involved in a relationship type is called degree of the relationship type.

Person Book

Borrows

Borrows is a binary relationship type

Page 31: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Relationship Types of Various Degrees

Degree Kind of Relationship Type

2 Binary relationship type

3 Ternary relationship type

4 Quaternary relationship type

Page 32: Database Systems - Entity Relationship Modeling (Chapter 4/2)

An Example of Ternary Relationship Type

Rental Agency

Tenant Landlord Arranges

Page 33: Database Systems - Entity Relationship Modeling (Chapter 4/2)

An Example of Quaternary Relationship Type

Real Estate Agency

Builder Bank Arranges

Buyer

Page 34: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Strong and Week Entity Types

Strong Entity Type: An entity type that does not

depend on other entity types for its existence.

Example: Person

Week Entity Type: An entity type that depends

on other entity types for its existence.

Example: Hobby

Page 35: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Structural Constraints

Structural constraints are constraints on Entity

Types on how many entities of an Entity Type

participate in a relationship.

Identifying and representing constraints on

Entity Types is an important step in E-R modeling

of an enterprise data.

Multiplicity constraint is the main type of

constraint on relationships.

Page 36: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Multiplicity Constraint

Multiplicity is the number of possible entities of

an entity type that may relate to a single entity

of an associated entity type participating in a

relationship.

Page 37: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Binary Relationships

Binary relationships are relationships between

two entity types.

Types of binary relationships:

• One-to-one (1:1) relationships

• One-to-many (1:*) relationships

• Many-to-many (*:*) relationships

Page 38: Database Systems - Entity Relationship Modeling (Chapter 4/2)

One-to-one (1:1) Relationship

A relationship is a 1:1 relationship, if an entity in

one entity type of the relationship is associated

with at most one entity in another entity type

of the relationship and vice versa.

Employee Department

Manages

Page 39: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of 1:1 Relationship

Department Employee

Manages

0..1 1..1

Multiplicity 0..1 indicates

that an employee can

manage none or one

department

Multiplicity 1..1 indicates a

department is managed by

exactly one employee

Page 40: Database Systems - Entity Relationship Modeling (Chapter 4/2)

One-to-many (1:*) Relationship

A relationship between two entity types is a one-to-

many (1:*) relationship, if an entity in one entity type

is associated with any number (zero or more) of

entities in another entity type whereas an entity of the

latter entity type can be associated with at most one

entity of the former entity type.

Staff Subject Teaches

Page 41: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of 1:* Relationship

Subject Staff

Teaches

0..* 0..1

Multiplicity 0..* indicates

that a staff member teaches

none or one or more subjects

Multiplicity 0..1

indicates a subject is

taught by none or at

most one staff member

Page 42: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Many-to-one (*:1) Relationship

This is a mirror relationship of the one-to-many

relationship.

The one-to-many relationship of the earlier slide can be

called as many-to-one relationship if it is represented

as Taught-by relationship and swap its entity types.

Page 43: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Many-to-many (*:*) Relationship

A relationship between two entity types is a many-to-

many (*:*) relationship, if an entity in one entity type is

associated with any number (zero or more) of entities

in another entity type and an entity of the latter entity

type is also associated with any number entities of the

former entity type.

Author Book Wrote

Page 44: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Diagrammatic Representation of *:* Relationship

Book Author

Wrote

1..* 1..*

Multiplicity 1..* indicates

that an author wrote one or

more books

Multiplicity 1..* indicates

a book was written by

one or more authors

Page 45: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Cardinality and Participation Constraints

Cardinality is the maximum number of relationship

occurrences for an entity participating in a given

relationship type.

Participation determines whether all or only some

entities participate in a relationship.

Page 46: Database Systems - Entity Relationship Modeling (Chapter 4/2)

Cardinality and Participation Constraints

Entity -2 Entity -1

Relationship-1

p..q m..n

Cardinality

Participation