Scope, and The Inter-Relationships Among These Entities
Scope, and The Inter-Relationships Among These Entities
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.
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.
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
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.