1. INT306
Database Management Systems
DATABASE DESIGN & THE E-R MODEL
Text book
Database System Concepts
A. Silberschatz, H. F. Korth, S. Sudarshan
Course Instructor
Mr. Sumit Mittu
Assistant Professor and Placement Coordinator, CSE/IT
Lovely Professional University, Punjab (India)
sumit.12735@lpu.co.in sumit.mittu@gmail.com
http://tinyurl.com/askSumit
01-03-2014 11:42:06
2. IN THIS CHAPTER
•
•
•
•
•
•
•
•
data modelling
overview of database design process
entity-relationship model
constraints
removing redundant attributes in entity sets
entity-relationship diagram
reduction to relational schema
entity-relationship design issues
01-03-2014 11:42:07
Sumit Mittu, Assistant Professor, CSE/IT
2
3. DATA MODELS
• Data Model defined…
• Collection of conceptual tools for describing:
•
•
•
•
Data
Data relationships
Data semantics, and
Consistency constraints
• Types
• Object Based Logical data models
• Record Based Logical data models
• Physical data models
01-03-2014 11:42:07
Sumit Mittu, Assistant Professor, CSE/IT
3
4. DATA MODELS
Object based
Logical Models
Record based Logical Models
(Semantic)
(Semantic)
ER Model
01-03-2014 11:42:07
OO Model
Relational
Hierarchical
Sumit Mittu, Assistant Professor, CSE/IT
Network
Physical
Model
Unifying
4
5. DATA MODELLING
• A database can be modelled as:
• a collection of entities, and
• relationships among entities
• An entity:
• An object that exists and is distinguishable from other objects
• Example: specific person, company, event, plant
• Entities have attributes
• Example: people have names and addresses
• An entity set
• A set of entities of same type that share the same attributes
• Example: set of all persons, companies, trees, holidays
01-03-2014 11:42:07
Sumit Mittu, Assistant Professor, CSE/IT
5
6. DATABASE DESIGN PROCESS
• Creating a database involves:
• Design of database schema
• Design of programs that access and update the data
• Design of security scheme to control access to data
Design of
database
schema
01-03-2014 11:42:07
Design of
programs that
access and
update the data
Sumit Mittu, Assistant Professor, CSE/IT
Design of security
scheme to
control access to
data
6
7. DATABASE DESIGN PROCESS
• Design Phases
Collect User Requirements
• Fully characterize the needs of prospective
database users and domain experts
Choose Data Model
• Choose a data model and translate above
requirements into a conceptual schema
Specify Functional
Requirements
• Users describe the kinds of operations (or
transactions) to be performed on data
Review Conceptual
Schema
• Designer reviews conceptual schema to ensure
that it meets functional requirements
Physical Implementation
01-03-2014 11:42:07
• Logical design phase
• Physical design phase
Sumit Mittu, Assistant Professor, CSE/IT
7
8. DATABASE DESIGN PROCESS
• Pitfalls to avoid during database design process
Incompletenes
s
Redundancy
01-03-2014 11:42:08
Pitfalls
Sumit Mittu, Assistant Professor, CSE/IT
8
10. THE ENTITY–RELATIONSHIP MODEL
• The E-R Model
• Perceives the real world as consisting of basic objects
(called entities) and relationships among them
• Represents overall logical design of the database
• A semantic model
• Useful in mapping the meanings and interactions of real
world enterprises onto conceptual schema
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
10
11. THE ENTITY–RELATIONSHIP MODEL
• The E-R Model
• Three basic concepts of E-R model
• Entity Sets
• Composed of entities
• Relationship Sets
• Composed of relationships
• Attributes
• Properties of entities (entity sets) and relationships (relationship sets)
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
11
12. THE ENTITY–RELATIONSHIP MODEL
• Entity
• A thing of an object in real world distinguishable from the
others
• E.g. each employee in an enterprise, each notebook, each wall
• Entity may be: concrete or abstract
• Entity Set
• Collection of entities with same set of properties/attributes
• E.g. Set of all employees in an enterprise, set all notebooks in a bag,
set of all walls in a building
• Individual entities that constitute a set are known as extension
of the entity set.
• Two or more entity sets may be disjoint (overlapping)
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
12
14. THE ENTITY–RELATIONSHIP MODEL
• Attributes
• Each entity posses some properties whose values may help
identify an entity uniquely over a set of similar entities
• E.g. name/address of an employee, no. of pages in notebook,
height of a wall
• Each entity has a value for each of its attributes
• Domain or value-set of an attribute is the set of permissible
values for a given attribute for any entity.
• E.g. Age can be a positive integer above 18 for a voter entity.
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
14
15. Types of Attributes
THE ENTITY–RELATIONSHIP MODEL
Simple
Username, Password
Composite
Name composed of first name and last name
Single-valued
Registration No., Password
Multi-valued
Contact No., Subjects
Derived
Age derived from DoB
Null-valued
Criminal Record (that may not exist for some records)
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
15
17. THE ENTITY–RELATIONSHIP MODEL
• Relationship
• An association among several entities
• Relationship Set
• Set of relationships of same type
• Mathematically, it is a set R of ordered pairs set on n≥2
(possibly non-distinct) entity sets E1, E2, … En
• R = { (e1,e2,…en} | e1 є E1, e2 є E2, … en є En}
• Each ordered pair (e1,e2, … en) is a relationship
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
17
18. THE ENTITY–RELATIONSHIP MODEL
Each line above implies a relationship between entity
from instructor entity set and that from student entity set
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
18
19. THE ENTITY–RELATIONSHIP MODEL
• Relationship Set
• Participation
• The association between entity sets in a relationship
• Types: Total or Partial
• Relationship instance
• An association between named entities
• Entity’s Role
• Function that entity plays in a relationship
• Types: Implicit or Explicit
• Recursive Relationship Set
• Entities of an entity set form relationship with other entities of same
entity set
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
19
20. THE ENTITY–RELATIONSHIP MODEL
• Relationship
• Types (or degree of relationship):
• Binary (degree 2)
• Instructor, Student
• Ternary (degree 3)
• Instructor, Student, Course
• N-ary (degree N)
• Involving entities from N entity sets
• Descriptive attributes
• Attributes assigned to relationships
• Session Year attribute of Instructor-Student relationship
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
20
23. CONSTRAINTS
• Mapping Cardinalities
• or, Cardinality ratios express the number of entities to which
another entity may be associated via a relationship set.
• Types
•
•
•
•
One to one
One to many
Many to one
Many to many
01-03-2014 11:42:08
1:1
1:N
N:1
M:N
Husbands :: Wives
Fathers :: Children
Children :: Mothers
Instructors :: Students
Sumit Mittu, Assistant Professor, CSE/IT
23
26. CONSTRAINTS
• Participation Constraints
• Total
• When all entities of an entity
participate in relationship set
• E.g. Entity Set A (in diagram)
• Partial
• When only some of the entities
participate in the relationship
set
• E.g. Entity Set B (in diagram)
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
26
27. KEYS
• Keys
• Help identify a set of attributes that suffice to distinguish
entities from each other
• Entity Set Keys
•
•
•
•
Super keys
Candidate Keys
Primary Key
Alternate Keys
• Relationship Set Keys
• PK(E1) u PK(E2) u … u PK(En) u {a1,a2,…am}
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
27
28. REMOVING REDUNDANT ATTRIBUTES
• Database design using E-R Model
•
•
•
•
Identify the entity sets
Choose appropriate attributes
Form the relationship sets
Eliminate redundant attributes that may
• Exist in multiple entity sets
• E.g. instructor_id, instructor_dept_id and instructor_dept_name
repeated in instructor and student entity. The instructor_dept_id and
instructor_dept_name may be eliminated from student entity set
• Exist even when not actually required
01-03-2014 11:42:08
Sumit Mittu, Assistant Professor, CSE/IT
28