Beruflich Dokumente
Kultur Dokumente
Introduction
Benefits of Data Modeling
Types of Models
Phases of Database Modeling
The Entity-Relationship (ER) Model
Extended Entity-Relationship(EER) Model
Generalization
Specialization
Aggregation
Introduction
Building a database system is a complex process
that normally requires analyzing the user's
requirements followed by a design process and
finally concluding with an implementation. During
analysis and design, the database designer
normally needs to build a model of the proposed
database system. Database modeling is essential to
manage the database development process.
Models have not been invented recently. Humans
have used models for a long time for a variety of
purposes and perhaps that is why modeling is
interpreted differently by different people. Some
examples of model building:
Data Models
A collection of tools for describing
Data
Data relationships
Data semantics
Data constraints
Entity-Relationship data model (mainly for database
design)
Relational model
Object-based data models (Object-oriented and
Object-relational)
Entity-Relationship Model
Models an enterprise as a collection of
entities and relationships
Entity: a thing or object in the enterprise
that is distinguishable from other objects
Described by a set of attributes
Relational Model
It uses collection of tables to represent
data as well as relationship among those
data.
Each table has multiple columns, each
column has unique name.
Other Models
Network Model
Data are represented by collection of
records, and relationships among those
data are represented by links, which
are viewed as pointers.
Records are organized as a collection
of arbitrary graph
Hierarchical Model
Data are represented by collection of
records, and relationships among those
data are represented by links, which are
viewed as pointers.
Records are organized as a collection of
trees rather than arbitrary graph
Entity-Relationship Model
ER modeling: A graphical technique for
understanding and organizing the data independent
of the actual database implementation OR
The ER model describes data as entities, attributes
and relationships
Basic Notations of ER model are
Entity
Attributes
Relationship
Entity
Entity An entity is a thing or object in the
real world that is distinguishable from all
other objects OR
Any thing from the real world that have an
independent existence and about which
we intend to collect data
An entity may be an object with
physical existence (person, book, car,
house) or with a conceptual existence
(Company, job, or university course)
Entity
Each Entity has attributes, the particular
properties that describe it
Entity type - Set of entities of the same type
that share the same attributes. Each Entity
type is described by its name and attributes
Entity Set Collection of all entities of a
particular entity type in DB at any point in
time
Extension of the entity Set - The individual
entities that constitute a set
Entity sets do not need to be disjoint
Attributes
Each entity has attributesthe particular
properties that describe it
Figure: Two entities, EMPLOYEE e1, and COMPANY c1, and their attributes
Domain of attributes
Each Simple attribute of an entity 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
individual entity
If range of ages allowed for employees is between
16 & 70 then value set for age attribute is set of
integer numbers between 16 & 70
Value set for name attribute is set of strings of
alphabetic characters separated by blank spaces
Types of attributes
Simple Vs composite attribute
Simple (Atomic) - cannot be divided into
smaller subparts (simpler) components
age of an employee
Composite Attributes
Null attribute
Null - In some cases, a particular entity may not have an
applicable value for an attribute
Complex Attributes
Composite and multi-valued attributes can be nested
arbitrarily.
We can represent arbitrary nesting by grouping components
of a composite attribute between parentheses () and
separating the components with commas, and by displaying
multi-valued attributes between braces { }. Such attributes
are called complex attributes
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
Relationship
A relationship is an association among several entity
sets
Example:
Hayes
depositor
A-102
Mapping Constraints
E-R model may define certain
constraints to which the contents of
the database must confirm. Two
most important constraints are
Existence dependencies
Mapping Cardinalities
Existence Dependencies
If the existence of entity set x
depends on the existence of entity
set y, then x is said to be existence
dependent on y. If y is deleted, so
is x. Entity set y is said to be
dominant entity set and x is said to
be subordinate entity set
Mapping Cardinalities
Express the number of entities to which
another entities can be associated via a
relationship set.
Most useful in describing binary relationship
sets.
For a binary relationship set the mapping
cardinality must be one of the following
types:
Mapping Cardinalities
Mapping Cardinalities
Entitys Role
Each entity set that participates in a relationship set
plays a particular role in a relationship
The role name signifies the role that a participating entity
from the entity set plays in each relationship instance,
and helps to explain what the relationship means
in the WORKS_FOR relationship set, EMPLOYEE plays
the role of employee or worker and DEPARTMENT
plays the role of department or employer.
Role names are not necessary in relationship types
where all the participating entity set are distinct, since
each participating entity set name can be used as the
role name.
In some cases the same entity set participates more
than once in a relationship set in different roles. In such
cases the role name becomes essential for distinguishing
the meaning of the role that each participating entity
plays
Identifying / Owner Entity set Entities belonging to a weak entity set are
identified by being related to specific
entities from another entity set in
combination with one of their attribute
values. The other entity set is identifying
(owner / parent / dominant) entity set
E-R Diagram
Overall logical structure of a database expressed graphically
Design Issues
Use of entity sets vs. attributes
Choice mainly depends on the structure of the
enterprise being modeled, and on the semantics
associated with the attribute in question
Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship
set to describe an action that occurs between
entities
Binary versus n-ary relationship sets
Although it is possible to replace any nonbinary
(n-ary, for n > 2) relationship set by a number of
distinct binary relationship sets, a n-ary
relationship set shows more clearly that several
entities participate in a single relationship.
Placement of relationship attributes
A banking Scenario
Banks have customers. Customers are identified by name,
customer id, phone number and address. Accounts can be
held by more than one customer and a customers can have
more than one accounts. Accounts are identified by an
account number, account type (savings, current) and a
balance. Customers can avail loans. Loans are identified by
loan id, loan type (car, home, personal) and an amount.
Banks are identified by a name, code and the address of the
main office. Banks are organized into branches. Branches
are identified by a branch number, branch name and an
address. Accounts and loans are related to the banks
branches.
Draw an ER diagram for a database to represent this application
University Database
The university is organized into departments. Each department is identified by a
unique name (dept_name), is located in particular building, and has a budget.
Each department has a list of courses it offers. Each course has associated with it a
course_id, title, dept_name, and credits, and may also have associated
prerequisites.
Instructors are identified by their unique ID. Each instructor has name, associated
department (dept_name), and salary.
Students are identified by their unique ID. Each student has a name, an associated
major department (dept_name), and tot_cred (total credit hours the student
earned thus far).
The university maintains a list of classrooms, specifying the name of the building,
room_number, and room capacity.
The university maintains a list of all classes (sections) taught. Each section is
identified by a course_id, sec_id, year, and semester, and has associated with it
a semester, year, building, room_number, and time_slot_id (the time slot when
the class meets).
The department has a list of teaching assignments specifying, for each instructor,
the sections the instructor is teaching.
The university maintains a list of all student course registrations, specifying, for
each student, the courses and the associated sections that the student has
taken (registered for).
Specialization
A process of defining a set of sub-classes of an
entity type (set); this entity type is called superclass of the specialization. The sub-class is
defined on the basis of some distinguishing
characteristic of the super-class.
Specialization is Top-down process
Generalization
A reverse process of abstraction in which the
differences among several entity types are
suppressed. Common features of sub-class
entity types are identified and generalized them
into a single super-class. It is a Bottom-up
process
The term generalization refer to the process of
defining a generalized entity type from the given
entity types
Design Constraints on a
Specialization/Generalization
Constraint on which entities can be members of a given
subclass (lower-level) entity type
Condition-defined An entity will become member of
which subclass is determined by placing a condition on the
value of some attribute of the superclass.
E.g. membership in the SECRETARY subclass by the
condition (Job_type = Secretary)
User-defined - When we do not have a condition for
determining membership in a subclass, the subclass is
called user-defined. Membership in such a subclass is
determined by the database users when they apply the
operation to add an entity to the subclass; hence,
membership is specified individually for each entity by the
user, not by any condition that may be evaluated
automatically.
Design Constraints on a
Specialization/Generalization
Constraint on whether or not entities may belong
to more than one subclass (lower-level) entity
type within a single generalization
Disjoint - an entity in super class can belong to
only one subclass (lower-level) entity type
Noted in E-R diagram by writing disjoint next to
the ISA triangle
Design Constraints on a
Specialization/Generalization
Completeness constraint -- specifies whether or
not an entity in the super class (higher-level)
entity set must belong to at least one of the
subclass (lower-level) entity sets within a
generalization
Total : an entity in super class must belong to one
of the subclass (lower-level) entity type
Partial: an entity in super class need not belong
to one of the subclass (lower-level) entity type
Aggregation
Consider the ternary relationship
works-on
Suppose we want to record managers for
tasks performed by an employee at a
branch
Aggregation
Eliminate this redundancy via
aggregation
Treat relationship as an abstract entity
Allows relationships between
relationships
Abstraction of relationship into new
entity
Keys
A super key of an entity set is a set of one
or more attributes whose values uniquely
determine each entity.
A candidate key of an entity set is a
minimal super key
Customer-id is candidate key of customer
account-number is candidate key of account
Keys
A super key of an entity set is a set of one
or more attributes whose values uniquely
determine each entity.
A candidate key of an entity set is a
minimal super key
Customer-id is candidate key of customer
account-number is candidate key of account
Non-Key Attributes
The attributes other than the Candidate Key
attributes are called Non-Key attributes.
OR
The attributes which do not participate in
any of the Candidate keys
Foreign key
A foreign key is a copy of a primary key
that has been exported from one relation
into another to represent the existence of
a relationship between them. A foreign
key is a copy of the whole of its parent
primary key i.e. if the primary key is
composite, then so is the foreign key
Entity example
Here address is a composite attribute
Years of service is a derived attribute (can be
calculated from date of joining and current
date)
Skill set is a multi-valued attribute
The relational Schema
Employee (E#, Name, Door_No, Street, City, Pincode, Joining_Date)
Converting relationships
The way relationships are represented depends
on the cardinality and the degree of the
relationship and participation
The possible cardinalities :
Binary 1:1
Binary 1 : 1
Binary 1:N
Binary 1 : N
Binary M : N
Unary 1 : 1
Consider employees who are
also a couple
The primary key field itself will
become foreign key in the same
table
Employee( E#, Name,... , Spouse)
Unary 1 : 1
Employee Table
EmpCode
PK
EmpName
DateofJoining
Spouse
FK
Unary 1:N
The primary key field itself will
become foreign key in the same
table
Same as unary 1:1
Unary 1 : N
Employee Table
EmpCode
PK
EmpName
DateofJoining
Manager
FK
Unary M:N
There will
be two
resulting
tables. One to
represent the
entity and
another to
represent the
M:N
relationship as
follows
Unary M : N
Employee Table
Employee Table
Guarantor PK/FK
EmpCode
Beneficiary PK /FK
PK
EmpName
DateofJoining
Spouse
FK
Ternary relationship
Ternary relationship
Represented by a new table
The new table contains three foreign keys
one from each of the participating Entities
Representing Specialization as
Tables
Method 1
create a table for the higher level entity
create a table for each lower level entity set,
include primary key of higher level entity set
and local attributes
table
table attributes
person
customer
employee
Method 2
create a table for each entity set with all local
and inherited attributes
table
customer
employee
table attributes
name, street, city, credit-rating
name, street, city, salary