You are on page 1of 46

Unit 2: Data Modeling using the

Entity-Relationship(ER) diagram
- Entity Types, Entity Sets, Attributes
and Keys

ROOPA R ,ISE, BMSCE

9/7/16

Sample Database Application


Example: Develop a database application to automate

the process of course registration


Your first task should be to have a discussion with your
client, to identify the requirements of the application.
Requirements are as follows
Department has students and faculty
Department will offer a set of courses during each semester
Each student in the department during course registration will be opting for
courses offered by the department
Faculty will be handling courses

Your second task should be to prepare a ER diagram

which shows the Design plan of the database application


to be developed.

ROOPA R ,ISE, BMSCE

9/7/16

Example: House design plan


During plan preparation
Various notations and
Terminologies

ROOPA R ,ISE, BMSCE

9/7/16

Design plan or ER diagram before actual development of


the application
USN

Course
Code

Name

Student

Course
Name

Opting

Courses

has

Handles
Offers

Department

Name
4

ROOPA R ,ISE, BMSCE

has

Faculty

ID

Name
9/7/16

Design plan or ER diagram before actual development of


the application
Attribute

Entity

Relationship

Requirements Were
- Department has students and faculty
- Department will offer a set of courses during each semester
- Each student in the department during course registration will be
opting for courses offered by the department
- Faculty will be handling courses

ROOPA R ,ISE, BMSCE

9/7/16

Design plan or ER diagram before actual development of


the application
Constraints
- Each semester student
should register for minimum
of 20 credits and maximum
of 30 credits
- Each faculty can handle
a maximum two courses
During each semester

Requirements Were
- Department has students and faculty
- Department will offer a set of courses during each semester
- Each student in the department during course registration will be
opting for courses offered by the department
- Faculty will be handling courses

ROOPA R ,ISE, BMSCE

9/7/16

The main phases of database design are depicted in Figure


Requirements Collection and Analysis: purpose is to
produce a description of the users' requirements.
Conceptual Design: purpose is to produce aconceptual
schemafor the database, including detailed descriptions
ofentity types,relationship types, andconstraints. All these
are expressed in terms provided by the data model being
used.
Implementation: purpose is to transform the conceptual
schema (which is at a high/abstract level) into a (lowerlevel)representational/implementationalmodel supported by
whatever DBMS is to be used.
Physical Design: purpose is to decide upon the internal
storage structures, access paths (indexes), etc., that will be
used in realizing the representational model produced in
previous phase.

ROOPA R ,ISE, BMSCE

9/7/16

ROOPA R ,ISE, BMSCE

9/7/16

ROOPA R ,ISE, BMSCE

9/7/16

Requirements Analysis is the process of determining


what the database is to be used for.
It involves interviews with user groups and other
stakeholders to identify what functionality they
require from the database, what kinds of data they
wish to process and the most frequently performed
operations.
This discussion is at a non-technical level and
enables the database designers to understand the
business logic behind the desired database.
Conceptual & Logical Design Using the ER data
model, the conceptual design stage involves
identifying
the
relevant
entities
and
the
relationships between them and producing an
entity-relationship diagram.
The logical design stage involves translating the ER
ROOPA Rinto
,ISE, BMSCE
9/7/16
diagram
actual relational database schema.
10

Requirements:
A lecturer has a staff number, a name and a rank
Research projects have a project id, a sponsoring
organization and a budget
Each project has one lecturer as a principal
investigator
Each project may have other lecturers as coinvestigators
Each lecturer can be principal or co-investigator
on multiple projects

11

ROOPA R ,ISE, BMSCE

9/7/16

Example COMPANY Database

Requirements of the Company (oversimplified


for illustrative purposes)
The company is organized into DEPARTMENTs.
Each department has a name, number and an
employee who manages the department. We
keep track of the start date of the department
manager.
Each department controls a number of
PROJECTs. Each project has a name, number and
is located at a single location.

12

ROOPA R ,ISE, BMSCE

9/7/16

We store each EMPLOYEEs social security


number, address, salary, sex, and birthdate. Each
employee works for one department but may
work on several projects. We keep track of the
number of hours per week that an employee
currently works on each project. We also keep
track of the direct supervisor of each employee.
Each employee may have a number of
DEPENDENTs. For each dependent, we keep track
of their name, sex, birthdate, and relationship to
employee.

13

ROOPA R ,ISE, BMSCE

9/7/16

What is Entity, Entity Types, Entity sets ?


Entity is object in real world which has independent existence.
Example: Student, Course, Faculty, Car, House, College, Book, Food
An entity could represent a physical object (e.g., house, person,
automobile, widget) or a less tangible concept (e.g., company, job,
academic course, business transaction).
ER Diagram Notation for Entity: Rectangle
Student

14

Courses

Attribute: An entity is described by its attributes, which are


properties characterizing it. Each attribute has avaluedrawn from
somedomain.
For example, an EMPLOYEE entity may be described by the
employees name, age, address, salary, and job. A particular entity
will have a value for each of its attributes. The attribute values that
describe
ROOPA each
R ,ISE, entity
BMSCE become a major part of the data stored in the
9/7/16
database.

15

ROOPA R ,ISE, BMSCE

9/7/16

16

ROOPA R ,ISE, BMSCE

9/7/16

Different categories of attributes

Attributes are classified along these dimensions:


simple/atomic vs. composite
single-valued vs. multi-valued (or set-valued)
stored vs. derived

Simple (Atomic) vs
Composite
Attributes that are not divisible are called
Simple.
EX: USN,AGE
Attributes that can be divided into smaller
parts are called Composite. EX:ADDRESS

17

ROOPA R ,ISE, BMSCE

EX:BirthDate(Month, Day, Year)

9/7/16

Single-Valued versus Multivalued Attributes.


Most attributes have a single value for a particular entity; such
attributes are called single-valued. For example, Age is a singlevalued attribute of a person.,USN
In some cases an attribute can have a set of values for the same entity
for instance: Mobile numbers,a Colors attribute for a car, or a

College_degrees attribute for a person.


Cars with one color have a single value, whereas two-tone cars have
two color values.

Similarly, one person may not have a college degree, another


person may have one, and a third person may have two or more
degrees; therefore, different people can have different numbers of
values for the College_degrees attribute. Such attributes are
called multivalued.

Denoted as {Color} or {PreviousDegrees}.


A multivalued attribute may have lower and upper bounds to constrain
the number of values allowed for each individual entity. For example, the
Colors attribute of a car may be restricted to have between one and three
ROOPA R ,ISE, BMSCE
9/7/16
18
values,
if we assume that a car can have three colors at most.

Stored versus Derived Attributes.


In some cases, two (or more) attribute values are relatedfor
example, the Age and Birth_date attributes of a person.
For a particular person entity, the value of Age can be
determined from the current (todays) date and the value of that
persons Birth_date. The Age attribute is hence called a derived
attribute and is said to be derivable from the Birth_date
attribute, which is called a stored attribute.
Some attribute values can be derived from related entities; for
example,
an
attribute
Number_of_employees
of
a
DEPARTMENT entity can be derived by counting the number
of employees related to (working for) that department
NULL Values. In some cases, a particular entity may not have an
applicable value for an attribute.
EX:Middle Name is Optional i.e. Gautham Sharma or Gautham K
Sharma
a person with no college degree would have NULL for
College_degrees.
NULL can also be used if we do not know the value of an attribute
R ,ISE, BMSCE
particular
entityfor example, if we do not know the home
9/7/16
19 for aROOPA
phone num-ber of John Smith

The unknown category of NULL can be further classified into two cases.
The first case arises when it is known that the attribute value exists but
is missingfor instance, if the Height attribute of a person is listed as
NULL.
second case arises when it is not known whether the attribute value
existsfor example, if the Home_phone attribute of a person is NULL.
COMPLEX ATTRIBUTES
composite and multivalued attrib-utes can be nested arbitrarily. We can
represent arbitrary nesting by grouping components of a composite
attribute between parentheses () and separating the compo-nents with
commas, and by displaying multivalued attributes between braces { }.
Such attributes are called complex attributes.
For example, if a person can have more than one residence and each
residence can have a single address and multiple phones, an attribute
Address_phone for a person can be specified as
{Address_phone( {Phone(Area_code,Phone_number)},Address(Street_a
ddress (Number,Street,Apartment_number),City,State,Zip) )}
Both Phone and Address are themselves composite attributes.

20

ROOPA R ,ISE, BMSCE

9/7/16

Attribute: ER diagram
notations
Attribute
..

Composite Attribute

Multivalued Attribute

Derived Attribute

21

ISE, BMSCE

9/7/16

What is Entity Types, Entity sets ?


Entity type is collection of entities with

common attributes with different values


Entity set collection of one or more attributes
Student

Entity Type

USN

Name

Email ID

Mobile No.

DOB

1BM14CS001

Aditya

aditya@bmsce.ac.in

9448444160

1-1-1997

1BM14CS002

Bharath

bharath@bmsce.ac.in

8762244699

31-12-1996

Entity Set

22

ISE,BMSCE

9/7/16

Two entity types, EMPLOYEE and COMPANY, and some


member entities of each
An entity type is represented in ER diagrams as a rectangular box
enclosing the entity type name

23

ROOPA R ,ISE, BMSCE

9/7/16

An entity type describes the schema or intension


for a set of entities that share the same structure.
The collection of entities of a particular entity type is
grouped into an entity set, which is also called the
extension of the entity type.

24

ROOPA R ,ISE, BMSCE

9/7/16

KEY ATTRIBUTES OF AN ENTITY TYPE


What is Key ?

Key attribute is a attribute or a combination of

attributes
which
will
uniquely
identify
remaining attributes of entity.
What are the Key attributes in the following
student table ?

25

USN

Name

Email ID

Mobile No.

DOB

1BM14IS001

Aditya

aditya@bmsce.ac.in

9448444160

1-1-1997

1BM14IS002

Bharath

bharath@bmsce.ac.in

8762244699

31-12-1996

ISE, BMSCE

9/7/16

Key attribute is a attribute or a combination of attributes which will


uniquely identify remaining attributes of entity.
What are the Key attributes in the following student table ?
COMPANY
NAME

COMPANY
ADDRESS

COMPANY
PRODUCT

ABC

123,XYZ

AAA

DEF

321,XYZ

AAA

USN

Name

Email ID

Mobile No.

DOB

1BM14IS001

Aditya

aditya@bmsce.ac.in

9448444160

1-1-1997

1BM14IS002

Bharath

bharath@bmsce.ac.in

8762244699

31-12-1996

1BM14IS003

Dinesh K

dineshk@bmsce.ac.in

8444160944

6-6-1998

1BM14IS004

Dinesh K

Dineshk_4@bmsce.ac
.in

7446998762

6-6-1998

26

ROOPA R ,ISE, BMSCE

9/7/16

In ER diagrammatic notation, each key attribute has its name


underlined inside the oval,

Some entity types have more than one key attribute. For
example, each of the Vehicle_id and Registration attributes
of the entity type CAR is a key in its own right. The
Registration attribute is an example of a composite key
formed from two simple component attributes, State and
Number, neither of which is a key on its own

27

ROOPA R ,ISE, BMSCE

9/7/16

28

ROOPA R ,ISE, BMSCE

9/7/16

CREATETABLESAMPLE_TABLE
(COL1integer,
COL2varchar(30),
COL3varchar(50),
PRIMARYKEY(COL1,COL2));
An entity type may also have no key, in which case it is called a weak
entity type
Value Sets (Domains) of Attributes. Each simple attribute of an
entity type is associated with a value set (or domain of values), which
specifies the set of values that may be assigned to that attribute for
each
entity
if the individual
range of ages
allowed for employees is between 16 and 70, we can
specify the value set of the Age attribute of EMPLOYEE to be the set of
integer numbers between 16 and 70.
Similarly, we can specify the value set for the Name attribute to be the
set of strings of alphabetic characters separated by blank characters, and
so on.
Value sets are not displayed in ER diagrams

29

ROOPA R ,ISE, BMSCE

9/7/16

Mathematically, an attribute A of entity set E whose value set is V can be


defined as a function from E to the power set P(V) of V:
A : E P(V)
Age:Employee ->{16,17,..60}

Initial Conceptual Design of the COMPANY


1. An entity type DEPARTMENT with attributes Name, Number, Locations,
Database
Manager, and Manager_start_date. Locations is the only multivalued
attribute. We can specify that both Name and Number are (separate)
key attributes because each was specified to be unique.

30

ROOPA R ,ISE, BMSCE

9/7/16

2. An entity type PROJECT with attributes Name, Number, Location, and


Controlling_department. Both Name and Number are (separate) key
attributes.

3. An entity type EMPLOYEE with attributes Name, Ssn, Sex, Address,


Salary, Birth_date, Department, and Supervisor. Both Name and Address
may be composite attributes; however, this was not specified in the
requirements. We must go back to the users to see if any of them will
refer to the individual components of NameFirst_name, Middle_initial,
Last_nameor of Address.

31

ROOPA R ,ISE, BMSCE

9/7/16

4. An entity type DEPENDENT with attributes Employee,


Dependent_name, Sex, Birth_date, and Relationship (to the employee).

32

ROOPA R ,ISE, BMSCE

9/7/16

Relationship Types, Sets, Roles, and


Structural Constraints
Relationship: This is an association between two entities. As an
example, one can imagine a STUDENT entity being associated to
an ACADEMIC_COURSE entity via, say, an ENROLLED_IN
relationship.
Whenever an attribute of one entity type refers to an entity (of
the same or different entity type), we say that a relationship
exists between the two entity types.

Relationships of the same type are grouped or typed into a relationship


type.

33

ROOPA R ,ISE, BMSCE

9/7/16

A relationship type R is a set of associations among entities E,


E, .
Preliminary COMPANY schema, we identify the following relationship
types
EMPLOYEE MANAGES DEPARTMENT (arising from Manager
attribute in DEPARTMENT)
DEPARTMENT CONTROLS PROJECT (arising from ControllingDept
attribute in PROJECT and the Projects attribute in DEPARTMENT)
EMPLOYEE WORKS_FOR DEPARTMENT (arising from Dept attribute
in EMPLOYEE and the Employees attribute in DEPARTMENT).
EMPLOYEE SUPERVISES EMPLOYEE (arising from Supervisor
attribute in EMPLOYEE)
EMPLOYEE WORKS_ON PROJECT (arising from WorksOn attribute
in EMPLOYEE and the Workers attribute in PROJECT)
DEPENDENT DEPENDS_ON EMPLOYEE (arising from Employee
attribute in DEPENDENT and the Dependents attribute in EMPLOYEE)
In ER diagrams, relationship types are drawn as diamond-shaped boxes
connected by lines to the entity types involved

34

ROOPA R ,ISE, BMSCE

9/7/16

35

ROOPA R ,ISE, BMSCE

9/7/16

Relationship Types, Sets, Roles, Structural Constraints


A relationship set is a set of instances of a relationship type.
If, say, R is a relationship type that relates entity types A and
B, then, at any moment in time, the relationship set of R will be a
set of ordered pairs (x,y), where x is an instance of A and y is an
instance of B.
for example, if our COMPANY miniworld is, at some moment,
such that employees e1, e3, and e6 work for department d1,
employees e2 and e4 work for department d2, and
employees e5 and e7 work for department d3,
then the WORKS_FOR relationship set will include as
instances the ordered pairs (e1, d1), (e2, d2), (e3, d1), (e4, d2),
(e5, d3), (e6, d1), and (e7, d3).

36

ROOPA R ,ISE, BMSCE

9/7/16

37

ROOPA R ,ISE, BMSCE

9/7/16

Ordering of entity types in relationship


types: Note that the order in which we list the
entity types in describing a relationship is of little
consequence, except that the relationship name
(for purposes of clarity) ought to be consistent
with it.
For example, if we swap the two entity types in
each of the first two relationships listed above,
we should rename them IS_MANAGED_BY and
IS_CONTROLLED_BY, respectively.

38

ROOPA R ,ISE, BMSCE

9/7/16

The degree of a relationship is the number of


participating entity types.
One-unary:
Employee Manager-of Employee
Two-binary:
Employee works-for Department
Three- ternary:
A supplier S supplies a part P to a Project j

39

ROOPA R ,ISE, BMSCE

9/7/16

40

ROOPA R ,ISE, BMSCE

9/7/16

Micro Systems
Pvt. Ltd
UNIQ systems
Pvt. Ltd

Laptop
Manufacturing

Supplier
Entity

Desktop
Manufacturing

Hard disk
Keyboard

Part
Entity

41

ROOPA R ,ISE, BMSCE

supplies
relationship

Project
Entity

9/7/16

ROLE NAMES AND RECURSIVE


RELATIONSHIPS
The role name signifies the role that a participating
entity from the entity type plays in each relationship
instance, and helps to explain what the relationship
means.
For example, in the WORKS_FOR relationship type,
EMPLOYEE plays the role of employee or worker
and
In DEPARTMENT
some cases the
same
participates or
plays
theentity
role type
of department
more
than once in a relationship type in different
employer.
roles. In such cases the role name becomes essential
for distinguishing the meaning of the role that each
participating entity plays. Such relationship types are
called recursive relationships
42

ROOPA R ,ISE, BMSCE

9/7/16

H.O.D

Supervisor

ASST.PROF

Subordinate

43

ROOPA R ,ISE, BMSCE

9/7/16

Relationship Constraints or Structural Constraints

Two Types
1. Cardinality Ratios
One to one (1:1)
b. One to Many (1:M)
c. Many to Many (N:M)
a.

2. Participation Constraints

Total
b. Partial
a.

44

ROOPA R ,ISE, BMSCE

9/7/16

Constraints on Relationship Types

Relationship types have certain constraints that limit


the possible combination of entities that may
participate in relationship.
An example of a constraint is that if we have the
entities Doctor and Patient, the organization may
have a rule that a patient cannot be seen by more
than one doctor. This constraint needs to be
described in the schema.
There are two main types of relationship
constraints, cardinality ratio, and
participation.
45

ROOPA R ,ISE, BMSCE

9/7/16

Cardinality for Binary Relationship

46

Binary relationships are relationships


between exactly two entities.
The
cardinality
ratio
specifies
the
maximum number of relationship instances
that an entity can participate in.
The possible cardinality ratios for binary
relationship types are: 1:1, 1:N, N:1, M:N.
Cardinality ratios are shown on ER
diagrams by displaying 1, M and N on the
diamonds.
The ratio shown closest to an entity,
represents the ratio the other entity has to
that
entity.
ROOPA R ,ISE, BMSCE
9/7/16

You might also like