You are on page 1of 35

Database Design & Applications (SS ZG 518)

BITS Pilani
Hyderabad Campus

Dr.R.Gururaj
CS&IS Dept.

Lecture Session-2

Conceptual Database Design (ER Modeling) Ch. 3 & 4

Content

ER Model Steps in Database Design Process Entities, Attributes, and Associations ER Notations Enhanced ER modeling Super-class and sub-class representation

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Major Steps in Database Design Process


Step 1: Requirement analysis Understanding the domain Identifying the data to be stored Identifying the constraints Step 2: Conceptual Database design E-R modeling/UML Step 3: Logical Database Design Designing tables and relationships Step 4: Refinement of schema Step 5: Physical database design Indexing Clustering Storage formats

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

ER Modeling
ER Model is a popular high-level (conceptual) data model. It is an approach to designing Semantic Conceptual schema of a Database. ER model allows us to describe the data involved in a real-world environment in terms of objects and their relationships, which are widely used in design of database. ER model provides preliminary concepts or idea about the data representation which is later modified to achieve final detailed design. Important concepts/notions used in ER modeling areEntity is an object in real-world or some idea or concept which can be distinguished from other objects. Ex.: person, school, class, department, weather, salary, temperature etc. Entity has independent existence. Each entity belongs to an Entity type that defines the structure. Entity Set is a Collection of similar objects.
3 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Concepts used in ER
Attribute: reflects a property of an object or entity. We have following types of attributes. > Simple attribute > Composite attribute > Single valued attribute > Multi-valued attribute > Derived attribute > Stored attribute Candidate Key (simply called a key): Is an Attribute of an entity type whose value can uniquely identify an entity in a set. Primary key: one of the candidate keys can become PK of an entity type. Alternate keys: The candidate keys other than the PK, are known as alternate keys.

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

BITS Pilani, Hyderabad Campus

Concepts used in ER
Relationship: The association between entities is known as relationship. Domain of an attribute: The set of possible values is known as domain of an attribute

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Notations used in ER
Notations used in ER modeling are shown below.
Entity Type

Weak Entity Type

Relationship Type

Identifying Relationship type

Attribute

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Notations used in ER

Key Attribute

Multivalued Attribute

Composite Attribute

Derived Attribute

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Notations used in ER

E1

E2

Total Participation of E1 in R

1 E1

Cardinality ratio 1; N for E1; E2 in

E2

(min, max) R E

Structural Constraint (min, max) on Participation of E in R

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Relationships in ER
Relationships
Manager Manages Employee

Manager

Manages

Employee

Degree of a Relationship If there are two entity types involved it is a binary relationship type If there are three entity types involved it is a ternary relationship type
Sales Assistant Sells Product

Manager

Manages

Employee

Unary relationships are also known as a recursive relationship


Manages
Employee

Customer

It is possible to have n-ary relationship (e.g. quaternary or unary)


9 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Relationships in ER
Cardinality of a relationship Relationships are rarely one-to-one. For example, a manager usually manages more than one employee. This is described by the cardinality of the relationship, for which there are four possible categories.

One to one (1:1) relationship

1
Man

is married to

Women

Manages

m Employee

One to many (1:M) relationship

Manager

Many to one (M:1) relationship

Student

Studies

1 Course

Many to many (M:N) relationship

Lecturer

Teaches

n Student

10

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

BITS Pilani, Hyderabad Campus

Relationships in ER
Participation Constraint If all the entities of an entity type are involved in the relationship then that entity types involvement said to be total in that relationship. In the below relationship if each employee is associated with at least one dept. Then the participation of EMP is total. Here, EMP works for DEPT. If, only few entities of the set are involved the participation is partial.
E1 R E2

EMP Worker Employer

DEPT

Association Role:

* EMP

1 DEPT

Multiplicity

EMP

Works_for

Association Name & Direction:

DEPT

11

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

ER Diagram for the Company DB schema, with all role names


Mint FName Name Sex LName
Address
Works_for

Number

(1, 1)
Salary

Employee

(4, N) department
Number of Employees

Name

Location

Ssn Bdate

EMPLOYEE

DEPARTMENT

(0, 1) Manager (0, N)

Start Date

(1, 1)
MANAGES

Controlling (0, N) department

(0, 1) Supervisor Supervisor


SUPERVISION

Hours
CONTROLS

(0, N) Employee
DEPENDENTS_OF

WORKS_ON

(1, N) Project

Controlled (1, 1) project


PROJECT

Name

Dependent (1, 1)
DEPENDENT

Number Location

Name

Relationship Sex Bdate

12

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Introduction to EER
Why EER Some applications like GIS, CAD/CAM, Telecommunication Have more complex requirements than normal database applications. To meet the requirements additional modeling concepts were incorporated into Conceptual data modeling such as ER modeling. The result is EER, stands for Extended ER modeling or Enhanced ER modeling

The additional EER concepts are used to model applications more


completely and more accurately. EER includes some object-oriented concepts, such as inheritance
13 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

EER Basics
Additional concepts:
Subclasses/super classes Specialization/generalization Attribute and relationship Inheritance
These are fundamental to conceptual modeling.

14

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Subclasses in EER
Subclass of an Entity type

An entity type may have additional meaningful subgroupings of its entities


Example: EMPLOYEE may be further grouped into:
SECRETARY, ENGINEER, TECHNICIAN,
Based on the EMPLOYEEs Job

MANAGER
EMPLOYEEs who are managers

SALARIED_EMPLOYEE, HOURLY_EMPLOYEE
Based on the EMPLOYEEs method of pay

EER diagrams extend ER diagrams to represent these additional subgroupings, called subclasses or subtypes
15 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

EER Notations

16

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Subclasses in EER (cntd..)


Each of these subgroupings is a subset of EMPLOYEE entities Each is called a subclass of EMPLOYEE EMPLOYEE is the superclass for each of these subclasses These are called superclass/subclass relationships:
EMPLOYEE/SECRETARY EMPLOYEE/TECHNICIAN EMPLOYEE/MANAGER

17

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Subclasses in EER (cntd..)


These are also called IS-A relationships
SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, .

Note: An entity that is member of a subclass represents the same real-world entity as some member of the superclass:
The subclass member is the same entity in a distinct specific role An entity cannot exist in the database merely by being a member of a subclass; it must also be a member of the superclass A member of the superclass can be optionally included as a member of any number of its subclasses
18 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Subclasses in EER (cntd..)


Examples:
A salaried employee who is also an engineer belongs to the two subclasses:
ENGINEER, and SALARIED_EMPLOYEE

A salaried employee who is also an engineering manager belongs to the three subclasses:
o MANAGER, o ENGINEER, and o SALARIED_EMPLOYEE

It is not necessary that every entity in a superclass be a member of some subclass


19 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Subclasses in EER (cntd..)


Attribute Inheritance in Superclass / Subclass Relationships
An entity that is member of a subclass inherits All attributes of the entity as a member of the superclass All relationships of the entity as a member of the superclass Example: In the previous slide, SECRETARY (as well as TECHNICIAN and ENGINEER) inherit the attributes Name, SSN, , from EMPLOYEE Every SECRETARY entity will have values for the inherited attributes

20

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Specialization in EER
Specialization is the process of defining a set of subclasses of a superclass

The set of subclasses is based upon some distinguishing characteristics of the entities in the superclass Example: {SECRETARY, ENGINEER, TECHNICIAN} is a specialization of EMPLOYEE based upon job type. May have several specializations of the same superclass

21

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Specialization
Example: Another specialization of EMPLOYEE based on method of pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.
Superclass/subclass relationships and specialization can be diagrammatically represented in EER diagrams Attributes of a subclass are called specific or local attributes.
For example, the attribute TypingSpeed of SECRETARY

The subclass can also participate in specific relationship types.


For example, a relationship BELONGS_TO of HOURLY_EMPLOYEE

22

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Generalization
Generalization is the reverse of the specialization process Several classes with common features are generalized into a superclass;
Original classes become its subclasses

Example: CAR, TRUCK generalized into VEHICLE;


both CAR, TRUCK become subclasses of the superclass VEHICLE. We can view {CAR, TRUCK} as a specialization of VEHICLE Alternatively, we can view VEHICLE as a generalization of CAR and TRUCK

23

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

24

31/07/2013 SSZG

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Constraints
Two basic constraints can apply to a specialization/generalization:
o Disjointness Constraint: o Completeness Constraint:

25

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Disjointness Constraint:
Specifies that the subclasses of the specialization must be disjoint:
an entity can be a member of at most one of the subclasses of the specialization

Specified by d in EER diagram If not disjoint, specialization is overlapping:


that is the same entity may be a member of more than one subclass of the specialization

Specified by o in EER diagram


26 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Completeness Constraint:
Total specifies that every entity in the superclass must be a member of some subclass in the specialization/generalization Shown in EER diagrams by a double line Partial allows an entity not to belong to any of the subclasses Shown in EER diagrams by a single line

27

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Hence, we have four types of specialization/generalization:


Disjoint, total Disjoint, partial Overlapping, total Overlapping, partial

Note: Generalization usually is total because the superclass is derived from the subclasses.
28 31/07/2013 SSZG 518 Database Design & Applications BITS Pilani, Hyderabad Campus

Example of disjoint partial Specialization

29

31/07/2013 SSZG

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Example of overlapping total Specialization

30

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

Summary

Various steps in database design process


What is ER modeling Concepts and notations used in ER Enhanced ER notations Super-class and sub-classing Constraints in class hierarchies

32

31/07/2013

SSZG 518 Database Design & Applications

BITS Pilani, Hyderabad Campus

You might also like