ss zg518-l2.ppt

35
BITS Pilani Hyderabad Campus Database Design & Applications (SS ZG 518) Dr.R.Gururaj CS&IS Dept.

Upload: anup-raghuveer

Post on 29-Nov-2015

116 views

Category:

Documents


0 download

DESCRIPTION

klmmmlkmkll

TRANSCRIPT

Page 1: SS ZG518-L2.ppt

BITS PilaniHyderabad Campus

Database Design & Applications(SS ZG 518)

Dr.R.GururajCS&IS Dept.

Page 2: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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

1 31/07/2013 SSZG 518 Database Design & Applications

Page 3: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Step 1: Requirement analysisUnderstanding the domainIdentifying the data to be storedIdentifying the constraints

Step 2: Conceptual Database designE-R modeling/UML

Step 3: Logical Database DesignDesigning tables and relationships

Step 4: Refinement of schemaStep 5: Physical database design

Indexing Clustering Storage formats

Major Steps in Database Design Process

2 31/07/2013 SSZG 518 Database Design & Applications

Page 4: SS ZG518-L2.ppt

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 are-

Entity 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

Page 5: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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.

Concepts used in ER

4 31/07/2013 SSZG 518 Database Design & Applications

Page 6: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Page 7: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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 

Concepts used in ER

5 31/07/2013 SSZG 518 Database Design & Applications

Page 8: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Entity Type

Weak Entity Type

Relationship Type

Identifying Relationship type

Attribute

Notations used in ER modeling are shown below.

Notations used in ER

6 31/07/2013 SSZG 518 Database Design & Applications

Page 9: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Key Attribute

Multivalued Attribute

Composite Attribute

Derived Attribute

Notations used in ER

7 31/07/2013 SSZG 518 Database Design & Applications

Page 10: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Total Participation of E1 in R

Cardinality ratio 1; N for E1; E2 in

R

Structural Constraint (min, max)

on Participation of E in R

E1

R E2

E1

R E2

1 N

R E

(min, max)

Notations used in ER

8 31/07/2013 SSZG 518 Database Design & Applications

Page 11: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Manager Manages Employee

Manages Manager Employee

Relationships

Degree of a Relationship

Manages Manager Employee

Sells Sales Assistant

Product

Customer

• 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

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

• Unary relationships are also known as a recursive relationship Manages

Employee

Relationships in ER

9 31/07/2013 SSZG 518 Database Design & Applications

Page 12: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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

One to many (1:M) relationship

Many to one (M:1) relationship

Many to many (M:N) relationship

1 Man Women

1 is married to

Manages Manager Employee

1 m

Studies

Student Course

m 1

Teaches

Lecturer Student

m n

Relationships in ER

10 31/07/2013 SSZG 518 Database Design & Applications

Page 13: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Page 14: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Participation Constraint

If all the entities of an entity type are involved in the relationship then that entity type’s 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 DEPT

Worker Employer

EMP DEPT * 1

EMP DEPT

Works_for

Association Role:

Multiplicity

Association Name & Direction:

Relationships in ER

11 31/07/2013 SSZG 518 Database Design & Applications

Page 15: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

EMPLOYEE

SUPERVISION

Bdate

Ssn

Name

FName

Mint LName

Sex

Address

Salary

Works_for

DEPARTMENT

Name

Number

Location

MANAGES

Start Date

Number of Employees

WORKS_ON

CONTROLS

PROJECT DEPENDENTS_OF

Name

Number

Location

Hours

DEPENDENT

Name Sex Bdate Relationship

Dependent (1, 1)

(1, N) Project

Controlled project

(1, 1)

(0, N) Controlling department

(4, N) department

(1, 1)

(0, N)

(0, 1)

Employee

(1, 1)

(0, 1)

Manager

Employee

Supervisor Supervisor

(0, N)

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

12 31/07/2013 SSZG 518 Database Design & Applications

Page 16: SS ZG518-L2.ppt

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

Page 17: SS ZG518-L2.ppt

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

Page 18: SS ZG518-L2.ppt

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

Page 19: SS ZG518-L2.ppt

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 EMPLOYEE’s Job

• MANAGER– EMPLOYEEs who are managers

• SALARIED_EMPLOYEE, HOURLY_EMPLOYEE– Based on the EMPLOYEE’s 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

Page 20: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

EER Notations

16 31/07/2013 SSZG 518 Database Design & Applications

Page 21: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

• 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

Subclasses in EER (cntd..)

17 31/07/2013 SSZG 518 Database Design & Applications

Page 22: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

• 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

Subclasses in EER (cntd..)

18 31/07/2013 SSZG 518 Database Design & Applications

Page 23: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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, ando SALARIED_EMPLOYEE

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

Subclasses in EER (cntd..)

19 31/07/2013 SSZG 518 Database Design & Applications

Page 24: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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 superclassExample:

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

Subclasses in EER (cntd..)

20 31/07/2013 SSZG 518 Database Design & Applications

Page 25: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

 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

Specialization in EER

21 31/07/2013 SSZG 518 Database Design & Applications

Page 26: SS ZG518-L2.ppt

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

Page 27: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

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

Generalization

23 31/07/2013 SSZG 518 Database Design & Applications

Page 28: SS ZG518-L2.ppt

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

Page 29: SS ZG518-L2.ppt

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

Page 30: SS ZG518-L2.ppt

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

Page 31: SS ZG518-L2.ppt

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

Page 32: SS ZG518-L2.ppt

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

Page 33: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Example of disjoint partial Specialization

29 31/07/2013 SSZG SSZG 518 Database Design & Applications

Page 34: SS ZG518-L2.ppt

BITS Pilani, Hyderabad Campus

Example of overlapping total Specialization

30 31/07/2013 SSZG 518 Database Design & Applications

Page 35: SS ZG518-L2.ppt

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