Scope, and The Inter-Relationships Among These Entities

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

ERD

- Entity Relationship Diagram, also known as ERD, ER Diagram or ER model, is a type of


structural diagram for use in database design. An ERD contains different symbols and
connectors that visualize two important information: The major entities within the system
scope, and the inter-relationships among these entities.

When we talk about entities in ERD, very often we are referring to business objects such as
people/roles (e.g. Student), tangible business objects (e.g. Product), intangible business
objects (e.g. Log), etc. "Relationship" is about how these entities relate to each other within
the system.

In a typical ER design, you can find symbols such as rounded rectangles and connectors (with
different styles of their ends) that depict the entities, their attributes, and inter-relationships.
When to draw ER Diagrams?
So, when do we draw ERDs? While ER models are mostly developed for designing relational
databases in terms of concept visualization and in terms of physical database design, there are
still other situations when ER diagrams can help. Here are some typical use cases.
 Database design - Depending on the scale of change, it can be risky to alter a
database structure directly in a DBMS. To avoid ruining the data in a production
database, it is important to plan out the changes carefully. ERD is a tool that helps. By
drawing ER diagrams to visualize database design ideas, you have a chance to
identify the mistakes and design flaws, and to make corrections before executing the
changes in the database.
 Database debugging - To debug database issues can be challenging, especially when
the database contains many tables, which require writing complex SQL in getting the
information you need. By visualizing a database schema with an ERD, you have a full
picture of the entire database schema. You can easily locate entities, view their
attributes and identify the relationships they have with others. All these allow you to
analyze an existing database and to reveal database problems easier.
 Database creation and patching - Visual Paradigm, an ERD tool, supports a
database generation tool that can automate the database creation and patching process
by means of ER diagrams. So, with this ER Diagram tool, your ER design is no
longer just a static diagram but a mirror that reflects truly the physical database
structure.
 Aid in requirements gathering - Determine the requirements of an information
system by drawing a conceptual ERD that depicts the high-level business objects of
the system. Such an initial model can also be evolved into a physical database model
that aids the creation of a relational database, or aids in the creation of process maps
and data flow modes.
ERD notations guide
An ER Diagram contains entities, attributes, and relationships. In this section, we will go
through the ERD symbols in detail.
Entity
An ERD entity is a definable thing or concept within a system, such as a person/role (e.g.
Student), object (e.g. Invoice), concept (e.g. Profile) or event (e.g. Transaction) (note: In
ERD, the term "entity" is often used instead of "table", but they are the same). When
determining entities, think of them as nouns. In ER models, an entity is shown as a rounded
rectangle, with its name on top and its attributes listed in the body of the entity shape. The
ERD example below shows an example of an ER entity.

Entity Attributes
Also known as a column, an attribute is a property or characteristic of the entity that
holds it.
An attribute has a name that describes the property and a type that describes the kind of
attribute it is, such as varchar for a string, and int for integer. When an ERD is drawn for
physical database development, it is important to ensure the use of types that are supported by
the target RDBMS.
The ER diagram example below shows an entity with some attributes in it.
Primary Key
Also known as PK, a primary key is a special kind of entity attribute that uniquely defines a
record in a database table. In other words, there must not be two (or more) records that
share the same value for the primary key attribute. The ERD example below shows an entity
'Product' with a primary key attribute 'ID', and a preview of table records in the database. The
third record is invalid because the value of ID 'PDT-0002' is already used by another record.

Foreign Key
Also known as FK, a foreign key is a reference to a primary key in a table. It is used to
identify the relationships between entities. Note that foreign keys need not be unique.
Multiple records can share the same values. The ER Diagram example below shows an entity
with some columns, among which a foreign key is used in referencing another entity.
Relationship
A relationship between two entities signifies that the two entities are associated with each
other somehow. For example, a student might enroll in a course. The entity Student is
therefore related to Course, and a relationship is presented as a connector connecting between
them.

Cardinality
Cardinality defines the possible number of occurrences in one entity which is associated
with the number of occurrences in another. For example, ONE team has MANY players.
When present in an ERD, the entity Team and Player are inter-connected with a one-to-many
relationship.
In an ER diagram, cardinality is represented as a crow's foot at the connector's ends. The
three common cardinal relationships are one-to-one, one-to-many, and many-to-many.
One-to-One cardinality example
A one-to-one relationship is mostly used to split an entity in two to provide information
concisely and make it more understandable. The figure below shows an example of a one-to-
one relationship.

One-to-Many cardinality example


A one-to-many relationship refers to the relationship between two entities X and Y in which
an instance of X may be linked to many instances of Y, but an instance of Y is linked to only
one instance of X. The figure below shows an example of a one-to-many relationship.

Many-to-Many cardinality example


A many-to-many relationship refers to the relationship between two entities X and Y in
which X may be linked to many instances of Y and vice versa. The figure below shows an
example of a many-to-many relationship. Note that a many-to-many relationship is split into
a pair of one-to-many relationships in a physical ERD. You will know what a physical ERD
is in the next section.
Conceptual, Logical and Physical data models
An ER model is typically drawn at up to three levels of abstraction:
Conceptual ERD / Conceptual data model
Logical ERD / Logical data model
Physical ERD / Physical data model

While all the three levels of an ER model contain entities with attributes and relationships,
they differ in the purposes they are created for and the audiences they are meant to target.
A general understanding to the three data models is that business analyst uses a conceptual
and logical model to model the business objects exist in the system, while database designer
or database engineer elaborates the conceptual and logical ER model to produce the physical
model that presents the physical database structure ready for database creation. The table
below shows the difference between the three data models.

ERD features Conceptual Logical Physical

Entity (Name) Yes Yes Yes

Relationship Yes Yes Yes

Columns Yes Yes

Column's Types Optional Yes

Primary Key Yes


Foreign Key Yes

Conceptual model vs Logical model vs Data model:


Conceptual data model
Conceptual ERD models the business objects that should exist in a system and the
relationships between them. A conceptual model is developed to present an overall picture
of the system by recognizing the business objects involved. It defines what entities exist,
NOT which tables. For example, 'many to many' tables may exist in a logical or physical data
model but they are just shown as a relationship with no cardinality under the conceptual data
model.
Conceptual data model example

NOTE: Conceptual ERD supports the use of generalization in modeling the 'a kind of'
relationship between two entities, for instance, Triangle, is a kind of Shape. The usage is like
generalization in UML. Notice that only conceptual ERD supports generalization.
Logical data model
Logical ERD is a detailed version of a Conceptual ERD. A logical ER model is developed
to enrich a conceptual model by defining explicitly the columns in each entity and
introducing operational and transactional entities. Although a logical data model is still
independent of the actual database system in which the database will be created, you can still
take that into consideration if it affects the design.
Logical data model example

Physical data model


Physical ERD represents the actual design blueprint of a relational database. A physical
data model elaborates on the logical data model by assigning each column with type, length,
nullable, etc. Since a physical ERD represents how data should be structured and related in a
specific DBMS it is important to consider the convention and restriction of the actual
database system in which the database will be created. Make sure the column types are
supported by the DBMS and reserved words are not used in naming entities and columns.
Physical data model example

How to draw an ER diagram?


If you find it difficult to get started with drawing an ER diagram, don't worry. In this section,
we will give you some ERD tips. Try to follow the steps below to understand how to draw an
ER diagram effectively.
1. Make sure you are clear about the purpose of drawing the ERD. Are you trying to
present an overall system architecture that involves the definition of business objects?
Or are you developing an ER model ready for database creation? You must be clear
about the purpose to develop an ER diagram at the right level of detail (Read the
section Conceptual, Logical and Physical Data Models for more details)
2. Make sure you are clear about the scope to model. Knowing the modeling scope
prevents you from including redundant entities and relationships in your design.
3. Draw the major entities involved in the scope.
4. Define the properties of entities by adding columns.
5. Review the ERD carefully and check if the entities and columns are enough to store
the data of the system. If not, consider adding additional entities and columns.
Usually, you can identify some transactional, operational and event entities in this
step.
6. Consider the relationships between all entities and relate them with proper cardinality
(e.g A one-to-many between entity Customer and Order). Don't worry if there are
orphan entities. Although it's not common, it's legit.
7. Apply the technique of database normalization to re-structure the entities in a way that
can reduce data redundancy and improve data integrity. For example, the details of
the manufacturer might be stored under the Product entity initially. During the process
of normalization, you may find that the detail keeps repeating records over records,
then you can split it as a separate entity Manufacturer, and with a foreign key that
links between Product and Manufacturer.

1. What is an entity subtype? What are entity subtypes used for? Example
Entity subtypes are entered into the ER model in order to reduce the total number of attributes
of each entity.
Each entity has a set of unique attributes. However, the attributes of different entities can be
repeated. Therefore, it is necessary to develop the ER-model so that the number of repeated
attributes in different entities was minimal or reduced to zero. Repeating attributes carries
redundancy in the database. The size of the database becomes unreasonably large, so this
problem needs to be fixed. Entity subtypes are used to solve this problem.
The idea of using an entity subtype is that a supertype is allocated for the entire diverse set of
entities, which contains information common to all types of entities. Details (subtleties) of
each type of entity are taken out separately in several specialized subtypes.
Example.
Suppose you need to develop a database of employees of the educational institution. In an
educational institution there are 3 entities, each of which represents a professional group of
employees:
 the entity Administration;
 the entity Teacher;
 the entity Support staff.
If for each entity to describe its own set of attributes, then you will notice that some attributes
in different entities will be repeated. The following attributes are common to all entities:
 Name;
 Surname;
 Identification number.
You can also highlight some unique attributes:
 the entity type “Administration” has the administrative rate, the name of the position
held, etc.;
 the type of entity “Teacher” has the number of hours read, the rate per 1 hour,
category, etc.;
 the entity type “Support personnel” has a staff rate, a weekend or working day ratio (if
the employee worked on weekends), etc.
To solve the problem of avoiding data repeatability, changes are made to the ER-model, as
shown in Figure 1, namely:
 the “Employee” supertype of entity is introduced. This supertype contains common
attributes for all types (subtypes) of entities;
 entity subtypes “Administration”, “Teacher”, “Support staff” are introduced. Each of
the entity subtypes has its own unique attributes.
Figure 1. Supertype and subtypes in the diagram

2. What is an entity supertype?
An entity supertype is an entity type in which only common attributes are implemented
(described) for entity subtypes that use this supertype.

3. How can entity subtypes be related together? Example
Entity subtypes may or may not intersect. If a subtype of one entity may be suitable for a
subtype of another entity, then this means that these subtypes of entities intersect each other.
Otherwise subtypes of entities do not intersect.

Example. In an educational institution, an employee who holds an administrative position


(subtype Administration) may be a teacher. That is, the entity
subtype Administration intersects with the entity subtype Teacher.
However, an employee from the entity subtype “Support staff” cannot be a teacher.
Therefore, the entity subtype “Support staff” does not intersect with the Teacher subtype.
In view of the above, the image of the supertype and subtypes in the diagram has the form, as
shown in Figure 2.
Figure 2. The supertype and entity subtypes with intersection between entity subtypes
In Figure 2, between the subtypes Administration and Teacher is a text Gs. This means that
subtypes can intersect. Between the Teacher and the Support Personnel subtypes is a
symbol ‘G’. This means that entity subtypes do not intersect.

4. What are the disadvantages of using subtypes of entities in database developing?
Each supertype and subtype of entities is implemented by a corresponding table. Table fields
are attributes of this type of entity.
The disadvantages of using subtypes of entities are that the overall development of the
database is complicated. The difficulties are as follows:
 the difficulty in organizing the interaction between the master and detailed tables for
relational databases;
 in the subtype tables, you must additionally enter the primary keys for linking to the
supertype table;
 SQL queries become more complex because you need to process data in related
tables;
 difficulty in providing secure of user access to table columns.

5. What are the advantages of using entity subtypes when designing databases?
Advantages of using subtypes of entities:
 avoid data redundancy, as each subtype contains only unique information. This in turn
leads to a reduction in the size of the database itself;
 simplifying the setting of restrictions for any attribute that corresponds to a column of
a table that implements a particular subtype of an entity;
 reduction of errors in programming operations on a table that corresponds to a
specific subtype of an entity;
 flexibility in modifying the database structure. You do not need to modify the
supertype table if you add / change the structure of the subtype table. This, in turn,
leads to the fact that there is no need to redo the entire database management program.

6. What type of relationship is established between a supertype and a subtype?
Between the supertype and subtype set relation “one to one” or 1:1.

You might also like