Vous êtes sur la page 1sur 10

SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

CHAPTER 2: ENTITY RELATIONSHIP MODEL

2.1 RELATIONAL MODEL


The relational model used the basic concept of a relation or table. The columns or fields in the table
identify the attributes such as name, age, and so. A tuple or row contains all the data of a single instance of
the table such as a person named ABDI. In the relational model, every tuple must have a unique
identification or key based on the data. In this figure, a social security account number (SSAN) is the key
that uniquely identifies each tuple in the relation.

Tables: In relation data model, relations are saved in the format of Tables. This format stores the relation
among entities. A table has rows and columns, where rows represent records and columns represents the
attributes.
Tuple: A single row of a table, which contains a single record for that relation is called a tuple.
Relation instance: A finite set of tuples in the relational database system represents relation instance.
Relation instances do not have duplicate tuples.
Relation schema: This describes the relation name (table name), attributes and their names.
Relation key: Each row has one or more attributes which can identify the row in the relation (table)
uniquely, is called the relation key.
Attribute domain: Every attribute has some pre-defined value scope, known as attribute domain.

2.2 ENTITY RELATIONSHIP MODEL


Simply stated the ER model is a conceptual data model that views the real world as entities and
relationships. A basic component of the model is the Entity-Relationship diagram which is used to visually
represent data objects.
1|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

ER model is:
It maps well to the relational model. The constructs used in the ER model can easily be transformed into
relational tables. It is simple and easy to understand with a minimum of training. Therefore, the model can
be used by the database designer to communicate the design to the end user.

2.3 BASIC CONSTRUCTS OF E-R MODELING


The ER model views the real world as a construct of entities and association between entities.

 Entity and Entity Set


Entities are the principal data object about which information is to be collected. The basic object that the
ER model represents is an entity, which is a "thing" in the real world with an independent existence. An
entity may be an object with a physical existence a particular person, car, house, or employee—or it may
be an object with a conceptual existence—a company, a job, or a university course. An entity set is a
collection of entities that share a common definition.

 Attributes
Each entity has attributes—the particular properties that describe it. For example, an employee entity may
be described by the employee’s name, age, address, salary, and job. A particular entity will have a value for
each of its attributes. The attribute values that describe each entity become a major part of the data stored
in the database.
Several types of attributes occur in the ER model: simple versus composite; single-valued versus multi-
valued; and stored versus derived.
Composite versus Simple (Atomic) Attributes
Composite attributes can be divided into smaller subparts, which represent more basic attributes with
independent meanings. For example, the Address attribute of the customer entity can be sub-divided into
Street, City, and number.

Fig: Composite Attributes

2|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

Attributes that are not divisible are called simple or atomic attributes. Composite attributes can form a
hierarchy; for example, Name can be subdivided into two simple attributes, First_Name, Last_Name. The
value of a composite attribute is the concatenation of the values of its constituent simple attributes.

Single-valued Versus Multi-valued Attributes


Attributes which have only one value for a entity are called single valued attributes. E.g. For a student
entity, RollNo attribute has only one single value. But phone number attribute may have multiple values.
Such values are called Multi-valued attributes.
Take one more example: a teacher entity can have multiple subject values.

Stored Versus Derived Attributes


Two or more attribute values are related—for example, the Age and Birth Date attributes of a person. For a
particular person entity, the value of Age can be determined from the current (today’s) date and the value
of that person’s Birth Date. The Age attribute is hence called a derived. The attribute from which another
attribute value is derived is called stored attribute.
In the above example, date of birth is the stored attribute.
Take one more example: a circle the area can be derived from the radius.

Database Keys
Keys are very important part of Relational database. They are used to establish and identify relation
between tables. The key is defined as the column or attribute of the database table. For example if a table
has id, name and address as the column names then each one is known as the key for that table. We can
also say that the table has 3 keys as id, name and address. The keys are also used to identify each record in
the database table. The following are the various types of keys available in the DBMS system. They also
ensure that each record within a table can be uniquely identified by combination of one or more fields
within a table.

3|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

Super Key: “Super Key” is defined as a set of attributes within a table that uniquely identifies each record
within a table. Super Key is a superset of Candidate key.

Candidate Key: “Candidate keys” are defined as the set of fields from which primary key can be selected.
It is an attribute or set of attribute that can act as a primary key for a table to uniquely identify each record
in that table.

Primary Key: “Primary key” is a candidate key that is most appropriate to become main key of the table.
It is a key that uniquely identify each record in a table.
Composite Key: Key that consists of two or more attributes that uniquely identify an entity occurrence is
called “Composite key”. But any attribute that makes up the “Composite key” is not a simple key in its
own.
Secondary or Alternative key: The candidate keys which are not selected for primary key are known as
secondary keys or alternative keys
Non-key Attribute: “Non-key” attributes are attributes other than “candidate key” attributes in a table.
Foreign Key: A foreign key is generally a primary key from one table that appears as a field in another
where the first table has a relationship to the second. In other words, if we had a table A with a primary key
X that linked to a table B where X was a field in B, then X would be a foreign key in B.

4|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

 Relationships
A Relationship represents an association between two or more entities. An example of a relationship would
be Employees are assigned to projects, Projects have subtasks, departments manage one or more projects,
Relationships are classified in terms of degree, connectivity, cardinality, and existence.

Fig: E-R diagram corresponding to customers and loans.

Degree of a Relationship
The degree of a relationship is the number of entities associated with the relationship. The n-ary
relationship is the general form for degree n. Special cases are the binary, and ternary ,where the degree is
2, and 3, respectively.
Binary relationships, the association between two entities is the most common type in the real world. A
recursive binary relationship occurs when an entity is related to itself. An example might be "some
employees are married to other employees".
A ternary relationship involves three entities and is used when a binary relationship is inadequate. Many
modelling approaches recognize only binary relationships. Ternary or n-ary relationships are decomposed
into two or more binary relationships.

Mapping cardinalities:
Mapping cardinalities, or cardinality ratios, express the number of entities to which another entity can be
associated via a relationship set. For a relationship set R between entity sets A and B, the mapping
cardinality must be one of the following:
There are three types of relationships
1) One to One
2) One to Many
3) Many to One
4) Many to Many
One to One: An entity in A is associated with at most one entity in B, and an entity in B is associated with
at most one entity in A.

5|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

One to Many: An entity in A is associated with any number (zero or more) of entities in B. An entity in B,
however, can be associated with at most one entity in A.

Figure: Mapping cardinalities. (a) One to One. (b) One to Many.

Many to One: An entity in A is associated with at most one entity in B. An entity in B, however, can be
associated with any number (zero or more) of entities in A.
Many to Many: An entity in A is associated with any number (zero or more) of entities in B, and an entity
in B is associated with any number (zero or more) of entities in A.

Figure: Mapping Cardinalities. (a) Many to One. (b) Many to Many

Real Example of Mapping Cardinality:

6|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

Direction
The direction of a relationship indicates the originating entity of a binary relationship. The entity from
which a relationship originates is the parent entity; the entity where the relationship terminates is the child
entity.
The direction of a relationship is determined by its connectivity. In a one-to-one relationship the direction
is from the independent entity to a dependent entity. If both entities are independent, the direction is
arbitrary. With one-to-many relationships, the entity occurring once is the parent. The direction of many-
to-many relationships is arbitrary.

Participation
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. It is indicated by double line between entity and relationship. 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.
For example, we expect every loan entity to be related to at least one customer through the borrower
relationship. Therefore the participation of loan in the relationship set borrower is total. In contrast, an
individual can be a bank customer whether or not she has a loan with the bank.

Hence, it is possible that only some of the customer entities are related to the loan entity set through the
borrower relationship, and the participation of customer in the borrower relationship set is therefore partial.

 Weak Entities
An entity set may not have sufficient attributes to form a primary key. Such an entity set is termed a weak
entity set. An entity set that has a primary key is termed a strong entity set. As an illustration, consider the
entity set payment, which has the three attributes: payment-number, payment-date, and payment_amount.
Payment-numbers are typically sequential numbers, starting from 1, generated separately for each loan.
Thus, al-though each payment entity is distinct, payments for different loans may share the same payment
number. Thus, this entity set does not have a primary key; it is a weak entity set.
For a weak entity set to be meaningful, it must be associated with another entity set, called the identifying
or owner entity set.
7|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

The relationship associating the weak entity set with the identifying entity set is called the identifying
relationship. The identifying relationship is many to one from the weak entity set to the identifying entity
set, and the participation of the weak entity set in the relationship is total.
In our example, the identifying entity set for payment is loan, and a relationship loan-payment that
associates payment entities with their corresponding loan entities is the identifying relationship.
The discriminator of a weak entity set is a set of attributes that allows this distinction to be made. For
example, the discriminator of the weak entity set payment is the attribute payment-number, since, for each
loan, a payment number uniquely identifies one single payment for that loan. The discriminator of a weak
entity set is also called the partial key of the entity set.
The primary key of a weak entity set is formed by the primary key of the identifying entity set, plus the
weak entity set’s discriminator. In the case of the entity set payment, its primary key is {loannumber,
payment-number}, where loan-number is the primary key of the identifying entity set, namely loan, and
paymentnumber distinguishes payment entities within the same loan.
In E-R diagrams, a doubly outlined box indicates a weak entity set, and a doubly outlined diamond
indicates the corresponding identifying relationship.

Specialization
An entity set may include sub groupings of entities that are distinct in some way from other entities in the
set. For instance, a subset of entities within an entity set may have attributes that are not shared by all the
entities in the entity set.
Consider an entity set person, with attributes name, street, and city. A person may be further classified as
one of the following:
• Customer
• Employee
Each of these person types is described by a set of attributes that includes all the attributes of entity set
person plus possibly additional attributes. For example, customer entities may be described further by the

8|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

attribute customer-id, whereas employee entities may be described further by the attributes employee-id
and salary.
The process of designating sub groupings within an entity set is called specialization. The specialization of
person allows us to distinguish among persons according to whether they are employees or customers.
In terms of an E-R diagram, specialization is depicted by a triangle component labeled ISA. The label ISA
stands for “is a” and represents, for example, that a customer “is a” person. The ISA relationship may also
be referred to as a super class subclass relationship. Higher- and lower-level entity sets are depicted as
regular entity sets—that is, as rectangles containing
the name of the entity set.

Generalization:
The refinement from an 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.

9|Page

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE


SUBJECT: DBMS (ECEg 4172) CH: 2 - ER MODEL

The database designer may have first identified a customer entity set with the attributes name, street, city,
and customer-id, and an employee entity set with the attributes name, street, city, employee-id, and salary.
There are similarities between the customer entity set and the employee entity set in the sense that they
have several attributes in common. This commonality can be expressed by generalization, which is a
containment relationship that exists between a higher-level entity set and one or more lower-level entity
sets.
In our example, person is the higher-level entity set and customer and employee are lower-level entity sets.
Higher- and lower-level entity sets also may be designated by the terms super class and subclass,
respectively. The person entity set is the super class of the customer and employee subclasses.

ER Diagram Symbols and Notations

10 | P a g e

PREPARED BY: RITURAJ JAIN WOLLEGA UNIVERSITY, NEKEMTE

Vous aimerez peut-être aussi