You are on page 1of 80

Module-II

Conceptual Database Design


Module –II -Contents
High-Level Conceptual Data Models for
Database Design
Entity Types, Entity Sets, Attributes, and Keys,
Relationship Types, Relationship Sets, Roles, and
Structural Constraints,
Weak Entity Types, ER Diagrams,
Naming Conventions, and Design Issues,
Relationship Types of Degree Higher than Two,
Enhanced ER, Specialization, Generalization
• E-R data model was developed to modeling
database design by allowing specification of an
enterprise schema that represents the overall
logical structure of a database.
• Entity Sets
– An entity is a “thing” or “object” in the real world that
is distinguishable from all other objects.
– An entity set is a set of entities of the same type that
share the same properties, or attributes.
–Value
• Relationship Sets
–A relationship is an association among several
entities.
–A relationship set is a set of relationships of the
same type.
–Role - The function that an entity plays in a
relationship is called entity’s role
Example

birthday
id
Actor

name address
• Attributes
– Simple (Age)
– Composite (Address , Date of Joining)
– Single Valued (Age)
– Multi Valued (Car Type, Car Fuel Type, Car Color)
– Derived (Age from Date of Birth)
– Complex (Combination of Composite & multi values
attributes)
• An attribute takes a null value when an entity
does not have a value for it.
Degree of Relationship Type:
The degree of relationship type is the
number of participating entity types.
For eg,
WORKS_FOR relationship is of degree 2 called
binary.
SUPPLY is of degree 3 (supplier, parts, project)
• Constraints on Relationship Types:
Relationship Types usually have certain constraints that
limit the possible combinations of entities that may
participate in the corresponding relationship set.
–Mapping Cardinalities (Max. no. of relationship
instances an entity can participate)
• One to One
• One to many
• Many to One
• Many to Many
Participation Constraints
Specifies whether the existence of an entity
depends on another entity via relationship type.
The two types of participation constraints are:
• Total Participation (Existence dependency)
• Partial
– Keys
One-to-One
 A film is directed by at most one director
 A director can direct at most one film

id
Director Directed Film title

name

Director Directed Film


One-to-Many
 A film is directed by at most one director
 A director can direct any number of films

id
Director Directed Film title

name

Director Directed Film


Many-to-Many
 A film is directed by any number of directors
 A director can direct any number of films

id
Director Directed Film title

name

Director Directed Film


Attributes of Relationship Types
Weak Entity Types
ER Model - Example
• Example Database Application (COMPANY)
• ER Model Concepts
– Entities and Attributes
– Entity Types, Value Sets, and Key Attributes
– Relationships and Relationship Types
– Weak Entity Types
– Roles and Attributes in Relationship Types
• ER Diagrams - Notation
• ER Diagram for COMPANY Schema
• Alternative Notations – UML class diagrams, others
Example COMPANY Database

• Requirements of the Company


– 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.
Example COMPANY Database (Cont.)

– We store each EMPLOYEE’s 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.
ER Model Concepts
• Entities and Attributes
– Entities are specific objects or things in the mini-world that are
represented in the database. For example the EMPLOYEE John
Smith, the Research DEPARTMENT, the ProductX PROJECT
– Attributes are properties used to describe an entity. For example
an EMPLOYEE entity may have a Name, SSN, Address, Sex,
BirthDate
– A specific entity will have a value for each of its attributes. For
example a specific employee entity may have Name='John Smith',
SSN='123456789', Address ='731, Fondren, Houston, TX', Sex='M',
BirthDate='09-JAN-55‘
– Each attribute has a value set (or data type) associated with it –
e.g. integer, string, subrange, enumerated type, …
Types of Attributes (1)
• Simple
– Each entity has a single atomic value for the attribute. For
example, SSN or Sex.
• Composite
– The attribute may be composed of several components. For
example, Address (Apt#, House#, Street, City, State, ZipCode,
Country) or Name (FirstName, MiddleName, LastName).
Composition may form a hierarchy where some components are
themselves composite.
• Multi-valued
– An entity may have multiple values for that attribute. For
example, Color of a CAR or PreviousDegrees of a STUDENT.
Denoted as {Color} or {PreviousDegrees}.
Types of Attributes (2)
• In general, composite and multi-valued attributes may be
nested arbitrarily to any number of levels although this is
rare. For example, PreviousDegrees of a STUDENT is a
composite multi-valued attribute denoted by
{PreviousDegrees (College, Year, Degree, Field)}.
Entity Types and Key Attributes
• Entities with the same basic attributes are grouped or typed into
an entity type. For example, the EMPLOYEE entity type or the
PROJECT entity type.
• An attribute of an entity type for which each entity must have a
unique value is called a key attribute of the entity type. For
example, SSN of EMPLOYEE.
• A key attribute may be composite. For example,
VehicleTagNumber is a key of the CAR entity type with
components (Number, State).
• An entity type may have more than one key. For example, the CAR
entity type may have two keys:
– VehicleIdentificationNumber (popularly called VIN) and
– VehicleTagNumber (Number, State), also known as license_plate number.
ENTITY SET corresponding to the
ENTITY TYPE CAR
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
.
.
.
SUMMARY OF ER-DIAGRAM
NOTATION FOR ER SCHEMAS
Symbol Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

E1 R E2 TOTAL PARTICIPATION OF E2 IN R

N CARDINALITY RATIO 1:N FOR E1:E2 IN R


E1 R E2

(min,max) STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R


R E
ER DIAGRAM – Entity Types are:
EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT
Relationships and Relationship Types (1)
• A relationship relates two or more distinct entities with a
specific meaning. For example, EMPLOYEE John Smith works
on the ProductX PROJECT or EMPLOYEE Franklin Wong
manages the Research DEPARTMENT.
• Relationships of the same type are grouped or typed into a
relationship type. For example, the WORKS_ON relationship
type in which EMPLOYEEs and PROJECTs participate, or the
MANAGES relationship type in which EMPLOYEEs and
DEPARTMENTs participate.
• The degree of a relationship type is the number of
participating entity types. Both MANAGES and WORKS_ON
are binary relationships.
Example relationship instances of the WORKS_FOR relationship
between EMPLOYEE and DEPARTMENT
EMPLOYEE WORKS_FOR DEPARTMENT

e1 r1 d1
e2 r2
e3 d2
r3
e4
r4
e5 d3
r5
e6
e7 r6

r7
Example relationship instances of the WORKS_ON relationship
between EMPLOYEE and PROJECT

r9

e1 r1 p1
e2 r2
e3 p2
r3
e4
r4
e5 p3
r5
e6
e7 r6

r7
r8
Relationships and Relationship Types (2)
• More than one relationship type can exist with the same
participating entity types. For example, MANAGES and
WORKS_FOR are distinct relationships between EMPLOYEE
and DEPARTMENT, but with different meanings and different
relationship instances.
ER DIAGRAM – Relationship Types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS,
SUPERVISION, DEPENDENTS_OF
Weak Entity Types
• An entity that does not have a key attribute
• A weak entity must participate in an identifying relationship type
with an owner or identifying entity type
• Entities are identified by the combination of:
– A partial key of the weak entity type
– The particular entity they are related to in the identifying
entity type
Example:
Suppose that a DEPENDENT entity is identified by the dependent’s
first name and birhtdate, and the specific EMPLOYEE that the
dependent is related to. DEPENDENT is a weak entity type with
EMPLOYEE as its identifying entity type via the identifying
relationship type DEPENDENT_OF
Weak Entity Type is: DEPENDENT
Identifying Relationship is: DEPENDENTS_OF
Constraints on Relationships

• Constraints on Relationship Types


– ( Also known as ratio constraints )
– Maximum Cardinality
• One-to-one (1:1)
• One-to-many (1:N) or Many-to-one (N:1)
• Many-to-many
– Minimum Cardinality (also called participation
constraint or existence dependency constraints)
• zero (optional participation, not existence-dependent)
• one or more (mandatory, existence-dependent)
Many-to-one (N:1) RELATIONSHIP
EMPLOYEE WORKS_FOR DEPARTMENT

e1 r1 d1
e2 r2
e3 d2
r3
e4
r4
e5 d3
r5
e6
e7 r6

r7
Relationships and Relationship Types (3)
• We can also have a recursive relationship type.
• Both participations are same entity type in different roles.
• For example, SUPERVISION relationships between EMPLOYEE
(in role of supervisor or boss) and (another) EMPLOYEE (in
role of subordinate or worker).
• In following figure, first role participation labeled with 1 and
second role participation labeled with 2.
• In ER diagram, need to display role names to distinguish
participations.
A RECURSIVE RELATIONSHIP
SUPERVISION
EMPLOYEE SUPERVISION

e1 2
1 r1
e2 2
1 r2
e3 2
1 r3
e4
2
e5 1
1 r4
e6 2
1
r5
e7
2
r6

© The Benjamin/Cummings Publishing Company, Inc. 1994, Elmasri/Navathe, Fundamentals of Database Systems, Second Edition
Recursive Relationship Type is: SUPERVISION
(participation role names are shown)
Attributes of Relationship types

• A relationship type can have attributes; for


example, HoursPerWeek of WORKS_ON; its
value for each relationship instance describes
the number of hours per week that an
EMPLOYEE works on a PROJECT.
Attribute of a Relationship Type is:
Hours of WORKS_ON
Structural Constraints –
one way to express semantics
of relationships
Structural constraints on relationships:
l Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or
M:N
SHOWN BY PLACING APPROPRIATE NUMBER ON THE LINK.
l Participation constraint (on each participating entity
type): total (called existence dependency) or partial.
SHOWN BY DOUBLE LINING THE LINK
NOTE: These are easy to specify for Binary Relationship
Types.
Alternative (min, max) notation for relationship structural
constraints:
l Specified on each participation of an entity type E in a relationship type R
l Specifies that each entity e in E participates in at least min and at most max
relationship instances in R
l Default(no constraint): min=0, max=n

l Must have minmax, min0, max 1

l Derived from the knowledge of mini-world constraints

Examples:
l A department has exactly one manager and an employee can manage at
most one department.
– Specify (0,1) for participation of EMPLOYEE in MANAGES

– Specify (1,1) for participation of DEPARTMENT in MANAGES

l An employee can work for exactly one department but a department can
have any number of employees.
– Specify (1,1) for participation of EMPLOYEE in WORKS_FOR

– Specify (0,n) for participation of DEPARTMENT in WORKS_FOR


The (min,max) notation
relationship constraints
(0,1) (1,1)

(1,1) (1,N)
COMPANY ER Schema Diagram
using (min, max) notation
Relationships of Higher Degree

l Relationship types of degree 2 are called binary


l Relationship types of degree 3 are called ternary and of
degree n are called n-ary
l In general, an n-ary relationship is not equivalent to n
binary relationships
l Higher-order relationships discussed further in Chapter 4
Problems with Current Modeling
Tools
• DIAGRAMMING
– Poor conceptual meaningful notation.
– To avoid the problem of layout algorithms and aesthetics of
diagrams, they prefer boxes and lines and do nothing more
than represent (primary-foreign key) relationships among
resulting tables.(a few exceptions)
• METHODOLGY
– lack of built-in methodology support.
– poor tradeoff analysis or user-driven design preferences.
– poor design verification and suggestions for improvement.
PROBLEM with ER notation

THE ENTITY RELATIONSHIP MODEL IN ITS


ORIGINAL FORM DID NOT SUPPORT THE
SPECIALIZATION/ GENERALIZATION
ABSTRACTIONS
A university registrar’s office maintains data about the following
entities:
• courses, including number, title, credits, syllabus, and prerequisites;
• course offerings, including course number, year, semester, section
number, instructor(s), timings, and classroom;
• students, including student-id, name, and program; Instructors,
including identification number, name, department, and title.
• Further, the enrollment of students in courses and grades awarded
to students in each course they are enrolled for must be
appropriately modeled.

Construct an E-R diagram for the registrar’s office. Document


all assumptions that you make about the mapping constraints.
SUMMARY OF ER-DIAGRAM
NOTATION FOR ER SCHEMAS
Symbol Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

E1 R E2 TOTAL PARTICIPATION OF E2 IN R

N CARDINALITY RATIO 1:N FOR E1:E2 IN R


E1 R E2

(min,max) STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R


R E
The (min,max) notation

(0,1) (1,1)

(1,1) (1,N)
COMPANY ER Schema Diagram
using (min, max) notation
Designing an ER Diagram

Consider the following set of requirements for a University database. Design an ER diagram
for this application:

• The university keeps track of each student's name, student number, social security
number, current address and phone number, permanent address and phone number,
birthdate, sex, class (freshman, graduate), major department, minor department (if
any), degree program (B.A., B.S., ... Ph.D.). Some user applications need to refer to the
city, state, and zip code of the student's permanent address and to the student's last
name. Both social security number and student number are unique for each student.
All students will have at least a major department.
• Each department is described by a name, department code, office number, office
phone, and college. Both the name and code have unique values for each department.
• Each course has a course name, description, course number, number of credits, level
and offering department. The course number is unique for each course.
• Each section has an instructor, semester, year, course, and section number. The section
number distinguishes sections of the same course that are taught during the same
semester/year; its value is an integer (1, 2, 3, ... up to the number of sections taught
during each semester).
• A grade report must be generated for each student that lists the section, letter grade,
and numeric grade (0,1,2,3, or 4) for each student and calculates his or her average
GPA.
University ER Diagram
Degree DName DCode OfficeNumber
Name StudentID SSN
Major In
Birth date
OfficePhone
Department
Sex Student
College
Class Minor In

Address

City State Zip


Offer

CName

Grade_Report
CourseDesc
Letter Grade Instructor Year Course
CNumber
GPA
Credits
Numeric Grade Section Belong_To

SectionNumber Semester
ER DIAGRAM FOR A BANK
DATABASE

© The Benjamin/Cummings Publishing Company, Inc. 1994, Elmasri/Navathe, Fundamentals of Database Systems, Second Edition
FIGURE 3.17
An ER diagram
for an AIRLINE
database
schema.
The Enhanced Entity-Relationship
(EER) Model
• Enhanced ER (EER) model
– Created to design more accurate database
schemas
• Reflect the data properties and constraints more
precisely
– More complex requirements than traditional
applications
Subclasses, Superclasses, and
Inheritance
• EER model includes all modeling concepts of
the ER model
• In addition, EER includes:
– Subclasses and superclasses
– Specialization and generalization
– Category or union type
– Attribute and relationship inheritance
Subclasses, Superclasses, and
Inheritance (cont’d.)
• Enhanced ER or EER diagrams
– Diagrammatic technique for displaying these
concepts in an EER schema
• Subtype or subclass of an entity type
– Subgroupings of entities that are meaningful
– Represented explicitly because of their
significance to the database application
Subclasses, Superclasses, and
Inheritance (cont’d.)
• Terms for relationship between a superclass
and any one of its subclasses
– Superclass/subclass
– Supertype/subtype
– Class/subclass relationship
• Type inheritance
– Subclass entity inherits all attributes and
relationships of superclass
Specialization and Generalization
• Specialization
– Process of defining a set of subclasses of an entity
type
– Defined on the basis of some distinguishing
characteristic of the entities in the superclass
• Subclass can define:
– Specific attributes
– Specific relationship types
Specialization and Generalization
(cont’d.)
• Certain attributes may apply to some but not
all entities of the superclass
• Some relationship types may be participated
in only by members of the subclass
Generalization
• Reverse process of abstraction
• Generalize into a single superclass
– Original entity types are special subclasses
• Generalization
– Process of defining a generalized entity type from
the given entity types
Constraints and Characteristics of
Specialization and Generalization
Hierarchies
• Constraints that apply to a single
specialization or a single generalization
• Differences between specialization/
generalization lattices and hierarchies
Constraints on Specialization and
Generalization
• May be several or one subclass
• Determine entity subtype:
– Predicate-defined (or condition-defined)
subclasses
– Attribute-defined specialization
– User-defined
Constraints on Specialization and
Generalization (cont’d.)
• Disjointness constraint
– Specifies that the subclasses of the specialization
must be disjoint
• Completeness (or totalness) constraint
– May be total or partial
• Disjointness and completeness constraints are
independent
Specialization and Generalization
Hierarchies
and Lattices
• Specialization hierarchy
– Every subclass participates as a subclass in only
one class/subclass relationship
– Results in a tree structure or strict hierarchy
• Specialization lattice
– Subclass can be a subclass in more than one
class/subclass relationship
Specialization and Generalization
Hierarchies
and Lattices (cont’d.)
• Multiple inheritance
– Subclass with more than one superclass
– If attribute (or relationship) originating in the
same superclass inherited more than once via
different paths in lattice
• Included only once in shared subclass
• Single inheritance
– Some models and languages limited to single
inheritance
Utilizing Specialization and
Generalization in Refining Conceptual
Schemas
• Specialization process
– Start with entity type then define subclasses by
successive specialization
– Top-down conceptual refinement process
• Bottom-up conceptual synthesis
– Involves generalization rather than specialization
Modeling of UNION Types Using
Categories
– Union type or a category
– Represents a single superclass/subclass
relationship with more than one superclass
– Subclass represents a collection of objects that is a
subset of the UNION of distinct entity types
– Attribute inheritance works more selectively
– Category can be total or partial
• Some modeling methodologies do not have
union types
A Sample UNIVERSITY EER Schema,
Design Choices, and Formal Definitions

• The UNIVERSITY Database Example


– UNIVERSITY database
• Students and their majors
• Transcripts, and registration
• University’s course offerings

You might also like