Professional Documents
Culture Documents
Data Models-E-R
Data Models-E-R
Data Models-E-R
Data Model
A data model is a collection of conceptual tools for describing data,
data relationship, data semantics and consistency constraints.
Entity-Relationship Model: This is a higher-level data model. It is
based on a perception of a real world that consists of a collection of
basic objects, called entities and the relationship among these
objects.
Relational Model: This is a lower level model. It uses a collection
of tables to represent both data and relationships among those
data.
Designers often formulate database schema design by first
modeling data at a high level, using E-R model and then translating
it into the relational model.
Entity
An entity is a thing or object in the real world that is
distinguishable from all other objects. An entity has a set of
properties and the values for some set of properties may uniquely
identify an entity. An entity may be concrete, such as a person or a
book, or it may be abstract, such as loan, or a holiday, or a
concept.
Entity Set
An entity set is a set of entities of the same type that share the
same properties, or attributes.
Customer The set of all persons who are customers at a given
bank
Loan The set of all loans awarded by a particular bank
Attribute Types:
Simple and Composite
Simple When an attribute is not possible to divided into subparts,
customer city, country
Composite Composite attributes can be divided into subparts i.e.
other attributes. Composite attributes help us to group together the
related attributes, making the modeling cleaner.
name first-name, middle-name, last-name
address street, city, state, zip-code (postal code)
street street-number, street-name, apartment-number
Single-valued and multi-valued
Single-valued when there exist a single value for a particular
entity, loan-number
Multi-valued When there exist a set of values for a specific
entity, phone-number, dependent-name of the employee entity set
Boundary can be assigned for a multi-valued attribute
Relationship
A relationship is an association among several entities
Relationship Set
A relationship set is a set of relationships of the same type.
Formally it is a mathematical relation on n>= 2 (possibly nondistinct) entity sets. If E1, E2, .., En are entity sets, then a
relationship set R is a subset of
{(e1, e2,., en) | e1 E1, e2 E3, ., en En }
Where (e1, e2, , en) is a relationship.
borrower association between customer and loan
loan-branch association between loan and branch
depositor association between customer and account
Participation: The association between entity sets is referred to as
participation, i.e. the entity sets E1, E2, ., En participate in
relationship set R.
Constraints
An E-R enterprise schema may define certain constraints to which
the contents of a database must conform. Two of the most
important constraints are:
A. Mapping Cardinalities or cardinality ratios
Mapping cardinalities express the number of entities to which
another entity can be associated via a relationship set. For a binary
relationship set R between entity sets A and B the mapping
cardinality must be one of the following:
1. One to one
2. One to many
3. Many to one
4. Many to many
B. Participation Constraints
The participation of an entity set E in a relationship set R is said to
be total if every entity in E participates in at least one relationship in
R. If only some entities in E participate in relationships in R, the
participation of entity set E in relationship R is said to be partial.
Keys
The values of the attributes of an entity must be such that they can
uniquely identify the entity from the entity set. In other words, no
two entities in an entity set are allowed to have exactly the same
value for all attributes.
A key allows us to identify a set of attributes that suffice to
distinguish entities from each other. Keys also help uniquely
identify relationships, and thus distinguish relationships from each
other.
A. Entity Sets
1. Superkey A superkey is a set of one or more attributes that,
taken collectively, allow identifying uniquely an entity in the entity
set. A superkey may contain extraneous attributes.
customer {customer-id}, {customer-name, customer-id}, {all
attribute}
customer-name is not a superkey
2. Candidate Key The superkey for which no proper subset is a
superkey is a candidate key. So the minimul superkeys are called
is candidate keys.
It is possible that several distinct sets of attributes could serve as a
candidate key.
{customer-name, customer-street}, {customer-id}
{customer-id, customer-name} is not a candidate key because
customer-id itself is a super key/candidate key.
Primary Key: The structure of the primary key for the relationship
set depends on the mapping cardinalities of the relationship set.
Depositor customer and account with attribute access-date
1. many to many the primary key of depositor consists of the
union of the primary keys of customer and account
2. many to one from customer to account - the primary key of
depositor is simply the primary key of customer (many sided)
3. one to many from customer to account - the primary key of
depositor is simply the primary key of account (many sided)
4. one to one from customer to account - the primary key of
depositor is either of the entity set (customer or account)
Entity-Relationship Diagram:
The E-R diagram can express the overall logical structure of a
database graphically. Such a diagram consists of the following
major components:
1. Rectangles, which represent entity sets
2. Ellipses, which represent attributes
3. Diamonds, which represent relationship sets
4. Lines, which link attributes to entity sets and entity sets to
relationship sets
5. Double ellipses, which represent multivalued attributes
6. Dashed ellipses, which denote derived attributes
7. Double lines, which indicate total participation of an entity in a
relationship set
8. Double rectangles, which represent weak entity set
9. Double diamond, identifying relationship set for weak entity set
Note: See symbols used in E-R notation (Figure 2.20)
Design Issues
1. Use of Entity Sets Vs Attributes
- What constitutes an attribute and what constitutes an entity set?
2. Use of Entity Sets Vs Relationship Sets
3. Binary Vs n-ary Relationship Sets
4. Placement of Relationship Attributes
a) Attributes of a one to many relationship set can be repositioned
to only the entity set on the many side of the relationship
b) For one to one relationship sets, the relationship attribute can be
associated with either one of the participating entity sets.
c) When an attribute is determined by the combination on
participating entity sets, rather than by either entity separately, that
attribute must be associated with the many to many relationship
set.
Redundancy of Tables
1. A relationship set linking a weak entity set to the corresponding
strong entity set is many to one relationship set and has no
descriptive attributes.
2. The primary key of a weak entity set includes the primary key of
strong entity set.
Example:
Strong Entity set loan: loan-number, amount
Weak Entity set payment: loan-number, payment-number,
payment-date, payment-amount
Identifying Relationship set loan-payment: loan-number, paymentno
So loan-payment table is redundant. In general, the table for the
relationship set linking a weak entity set to its corresponding strong
entity set is redundant.
Combination of Tables
If there are two entity sets A and B and there exist relationship set
R between them, 3 tables A, B, R can be generated using table
construction scheme.
1. one to one relationship from A to B - the primary key of R is
either of the entity set (A or B)
Composite Attributes
Composite attributes are handled by creating a separate attribute
for each of the component attribute and there should not be a
separate column for the composite attribute itself.
Entity set customer: customer-id, name having composite attribute
name with component attributes first-name, middle-initial, lastname
Table customer : customer-id, first-name, middle-name, last-name
Multivalued Attributes
For a multivalued attribute M, we create a table T with a column C
that corresponds to M and columns corresponding to primary key
of the entity set or relationship set of which M is an attribute.
Entity set employee: employee-id, employee-name, dependentname
Table employee: employee-id, employee-name
Table dependent-name: employee-id, dname
Entity set customer: customer-id, date-of-birth, phone-no.
Table customer: customer-id, date-of-birth
Table cust-phone: customer-id, phone-no.
Generalization
The refinement of initial entity set into successive levels of entity
sub-groupings represents a top-down design process in which
distinctions are made explicit.
The design process may also proceed in a bottom-up manner, in
which multiple entity sets are synthesized into a higher level entity
set on the basis of common features. This commonality can be
expressed by generalization. Generalization is used to emphasize
the similarities among the lower level entity sets and to hide the
differences; it also permits an economy of representation in that
shared attributes are not repeated.
customer = {name, street, city, customer-id}
employee = { name, street, city, employee-id, salary}
person = {name, street, city}
savings-account ={ account-no., balance, interest rate}
checking-account ={ account-no., balance, overdraft-amount}
account = {account no., balance}
Constraints on Generalizations/Specialization
A. Type1: Constraint on which entities can be members of a given
lower-level entity set.
1. Condition-defined: In condition-defined lower-level entity sets,
membership is defined on the basis of whether or not an entity satisfies
an explicit condition or predicate. It is also called attribute-defined
generalization.
Example: Saving account and Checking account
2. User-defined: Used-defined lower-level entity sets are not
constrained by a membership condition; rather, the database user
assigns to a given entity set.
Example: Employee and Team
B. Type2: Constraint on whether or not entities may belong to more than
one lower-level entity set within a single generalization.