Summary ERD
Summary ERD
1. Introduction databases
1.1 Introduction
Una organization is a partnership de personas que es fundado with a certain
purpose. Many resources are needed to achieve the goal of this organization.
Information that is needed must be use in the right moment for the organisation
to function properly.
La necesidad por la data aumenta, we can look at data processing in a
organisation in 2 ways.
The proces-oriented approach, how the data is flowing en la organization y en
que actividades en usada.
The data-oriented approach, la forma en que la data es guardada. (ESTO ES)
1.2 Databases
1.2.1 Why databases?
The computer is mostly used for data storage. Before automation, around 1950,
data was store in separate files. This could lead to many problems, having the
same data store separately in many places creates the risk that the data in one
place does not match the same data in another file.
This is solve by centrally managing all data and making available to
everybody.
Ejemplo:
A separate article file for each department, a single article file was kept
centrally, which all departments involved could use. Such a collection of
centrally managed data is called a database.
Reader 1
The occurrence of the same data multiple times is what we call redundancy.
Esto trae muchos problemas, almacenar la misma data ocupa mucho espacio
en el disco, además no improve the reliability of the data.
To avoid redundancy it needed to think before setting the database. The
Relational Model offers a solution to it, the columns that repeat data become
separate files.
In addition to the existing sales file, two new files arise: the CUSTOMERS file
and the ARTICLES file. In these new files, every customer and each article
appears only once. All we have to do now is refer to the right customer and the
right article from the SALES file. This is usually done by means of a number or
code.
1.2.3 Concepts
Reader 2
1.2.4 Keys
Primary key: Key are the things that make a record unique, this are called
primary key or unique identifier. It has more than one attribute.
Composite key: This are keys that combine one or more attributes combine to
uniquely identify a record in a table. Are use when no single attribute is
sufficient to uniquely identify the records in a table.
Reader 3
Enforcing correct references: Ensuring that every customer number in the
SALES table corresponds to an existing customer.
Entity
Is something we want to capture data about, is a rectangle. The entities
become tables in the database.
Relationships
There are references between the tables in a relational database, the
references are included in the ERD and are called relationships. They are a
connection between entities, they are represented by a diamond.
Attributes
Properties of an entity or relationship that we want to keep track of. Is an
ellipse.
The attributes are not required for every relationship, if an entity has no
atributes is because we don't want to keep track of anything about it, so it's
usually pointless to include this "blank" entity in the design.
They can also be presented as a list attached to the ERD.
Reader 4
Cardinality
Type Meaning Example
One-to-Many One entity can be related to One customer can place many
(1:N) many others orders
Many-to-Many Many entities relate to many Students take many courses, and
(M:N) others courses have many students
Functionality
The maximum number of occurrences for one entity in relation to another is
called the Functionality. When a certain entity can occur at most once in
relation to another entity, we write down a 1 near the relationship, on the side of
that entity. If she can occur multiple times, we write down an n.
Reader 5
Current databases, by contrast, only store data relevant to the present
moment. They do not retain historical records, meaning that once
information is updated, previous data is lost.
Generalización
Its when two or more entities have a lot of attributes in common.
The specific entity side is total (T) — every Student must be a Person .
Reader 6
The name IS_A is reserved and only used for generalization. It never has its
own attributes — they belong to either the superclass or subclass.
Specialization
Specialization in an ERD (Entity-Relationship Diagram) is the process of
creating sub-entities from a more general super-entity based on some
distinguishing characteristics.
In simple terms:
It means breaking down a general entity into more specific types.
Example:
You have a general entity called Employee.
You can specialize it into Teacher and Administrator, since they have different
attributes or roles.
markdown
Copy code
Employee
▲
┌────┴────┐
Teacher Administrator
IS_A
In an Entity-Relationship Diagram (ERD), the IS_A relationship used in
specialization or generalization represents a 1-to-1 relationship between the
specialized entity and the general entity.
This means that each instance of the specialized entity (e.g., Teacher)
corresponds to exactly one instance of the general entity (e.g., Employee).
Additionally, every specialized entity must be a general entity (total
participation), but not every general entity has to be a specialized one (optional
participation).
Therefore, the IS_A relationship is both 1:1 in functionality and has T/O totality
(Total on the specialized side, Optional on the general side).
Reader 7
When working with the special relationship with the name IS_A a number of
rules apply. A IS_A Relationship:
is always two-dimensional
Multidimensional relationship
It connects one or more than two entities.
A multidimensional relationship in an Entity-Relationship Diagram (ERD) is a
relationship that involves more than two entities at the same time. Unlike binary
relationships, which connect two entities, multidimensional (or n-ary)
relationships connect three or more.
For example, if we want to represent which student is taught by which teacher
in which course, we need a relationship that includes all three entities. This
type of relationship captures the combined meaning of all the involved entities
and is used when the interaction between them cannot be fully described with
just pairs.
Reader 8
3. From ERD to relational model
Condition 1: Give each entity type and relationship type a unique name.
All the entities and relationships have a unique name, only is_a can appear
more than once.
uniquely identifying;
not empty (a key attribute must have a value for each entity).
Conversion Rule 1
Conversion Rule 1 explains how to handle n-to-m (many-to-many)
relationships when converting an ERD (Entity-Relationship Diagram) into a
relational database model.
A Student can enroll in many Courses, and a Course can have many
Students.
2. Conversion Process:
Reader 9
2. One table for the second entity.
3. Relationship Table:
The relationship table stores the connection between the two entities.
This table will contain foreign keys that reference the primary keys of
the two entity tables.
The combination of these two foreign keys together forms the primary
key of the relationship table, ensuring that each relationship instance is
unique.
4. No redundancy:
Example:
Let’s consider the entities Student and Course with a many-to-many (n-to-m)
relationship (a student can enroll in many courses, and a course can have
many students).
ERD:
Student has an attribute Student_ID .
The relationship is: "A Student can enroll in many Courses, and a Course
can have many Students."
Conversion:
We need three tables:
1. Student table
2. Course table
In the relationship table, we’ll have foreign keys pointing to the Student_ID and
Course_ID , and the combination of these foreign keys will be the primary key.
Reader 10
Final Database Model:
1. Student table:
Student_ID Name
1 John
2 Jane
2. Course table:
Course_ID Course_Name
101 Math
102 Science
1 101
1 102
2 101
Enrollment table holds foreign keys ( Student_ID , Course_ID ) from both the
Student and Course tables.
The combination of Student_ID and Course_ID forms the primary key of the
Enrollment table.
Summary:
n-to-m relationships are represented by three tables: two for the entities
and one for the relationship.
The relationship table contains foreign keys to both entities, and the
combination of these foreign keys forms the primary key.
Conversion rule 2
Conversion Rule 2 explains how to handle n-to-1 or 1-to-n relationships when
converting an ERD (Entity-Relationship Diagram) into a relational database
Reader 11
model.
2. Conversion Process:
The 1-side entity (the one with the "one" side of the relationship) will
have a foreign key pointing to the n-side entity.
1. How it works:
The 1-side entity is converted into a table that includes a reference key
(foreign key) to the n-side entity.
2. Foreign Key:
The foreign key is added to the 1-side entity table and it refers to the
primary key of the n-side entity.
Example:
Let’s consider the entities Department and Employee with a 1-to-n relationship
(one department can have many employees).
ERD:
Department has an attribute Department_ID .
Conversion:
Reader 12
We add a foreign key ( Department_ID ) to the Employee table to represent the
relationship.
Department_ID Name
1 HR
2 IT
Employee table:
101 John 1
102 Jane 1
103 Bob 2
In this case:
The Employee table holds the foreign key ( Department_ID ) to establish the 1-
to-n relationship with the Department table.
Summary:
In a 1-to-n or n-to-1 relationship, you don’t create a separate relationship
table.
The 1-side entity gets a foreign key reference to the n-side entity.
Conversion Rule 3
Conversion Rule 3 explains how to handle a 1-to-1 relationship when
converting an ERD (Entity-Relationship Diagram) into a relational database
model.
Reader 13
Here's what it means, step by step:
1. 1-to-1 Relationship:
This is when each entity in one table is associated with only one entity in
another table, and vice versa. For example, a Person might have exactly
one Passport.
2. Conversion Process:
When converting a 1-to-1 relationship into a relational model:
You choose one entity to hold the foreign key of the other entity.
3. How it works:
The foreign key is unique for each record, ensuring that each
relationship instance is one-to-one.
Example:
Let’s consider the entities Employee and Office with a 1-to-1 relationship.
ERD:
Employee has an attribute Employee_ID .
Conversion:
You can place a reference to Office_ID inside the Employee table as a
foreign key.
Reader 14
Office_ID Location
102 London
1 John 101
2 Jane 102
Office table:
In this case, the Employee table holds the foreign key ( Office_ID ) to represent the
1-to-1 relationship with the Office table.
Summary:
For a 1-to-1 relationship, the foreign key is placed in one table (typically
the one with fewer attributes or more logical association).
Conversion Rule 4
Conversion Rule 4 explains how to handle total relationships in the context of
relational database design when there is a foreign key involved.
Reader 15
When a foreign key is involved in a total relationship, it is mandatory to fill
the foreign key field in the table that participates in the relationship. This
ensures that there is always a valid reference to the related entity, adhering
to the total participation rule.
3. Implication:
If a record in one table is required to be linked to a record in another table
(due to the total relationship), you cannot leave the foreign key column null
— it must contain a valid reference to the related table.
Example:
Let’s consider two entities:
Conversion Process:
If we add a foreign key ( Department_ID ) in the Employee table, it must be
filled for each Employee.
Department_ID Department_Name
1 HR
2 IT
2. Employee table:
101 John 1
102 Jane 2
In this case:
Reader 16
Every Employee has a Department_ID (foreign key) that must be filled.
Summary:
When a foreign key is part of a total relationship, the foreign key must
always be filled with a valid reference to the related entity.
This ensures that the entity on the "many" side of the relationship always
has an associated entity on the "one" side, maintaining data integrity.
Conversion Rule 5
Conversion Rule 5 deals with total relationships where the "1-side" entity
does not have a reference key (foreign key), but still participates in the
relationship in a way that requires all key values to appear at least once in the
"many-side" table.
Every key value in the table that does not have the foreign key (the 1-
side entity) must appear at least once in the foreign key field in the
other table (the many-side entity).
Reader 17
This ensures that every record on the "1-side" has at least one matching
record on the "many-side," maintaining the integrity of the total
relationship.
Example:
Let’s consider two entities:
Scenario:
In this case, the Department table does not have a foreign key pointing to
the Employee table. But the Employee table has a foreign key ( Department_ID )
that links back to the Department table.
Conversion Process:
Every Department_ID must appear at least once in the Employee table
as a Department_ID foreign key.
If a Department does not have any employees, it violates the total relationship
rule.
Department_ID Department_Name
1 HR
2 IT
2. Employee table:
Reader 18
101 John 1
102 Jane 2
In this case:
Key Rule:
Even if the Department table does not have a reference key, each
Department must appear in the Employee table at least once to satisfy the
total relationship.
Summary:
When a table without a reference key participates in a total relationship,
the key values in the table must appear at least once as a foreign key in
the related table.
This ensures that each entity in the "1-side" of the relationship is properly
linked to the "many-side" entities, maintaining the integrity of the total
relationship.
4. Logical Notion
Is a detailed version of a conceptual data model, the attributes are added to
each entity, can also be introduced to represent areas for storing data in the
system.
4.2 Entities
The entities become tables, with the atributes as part of them.
Reader 19
4.3 Relationships and Cardinality
Reader 20
In the AUTHOR table, an author appears at most once and cannot be null. In the
BOOK table, an author appears at least once but can also appear multiple
times.
Relational Model
EMPLOYEE:
personnel number, name, address, residence
CAR:
license plate, brand, type, color, personnel number, start date
Personnel number is unique in CAR.
Foreign key ‘personnel number’ refers to personnel number in EMPLOYEE.
In the EMPLOYEE table, personnel number appears at most once and cannot be
null. The personnel number in the CAR table must exist in the EMPLOYEE table.
Reader 21
In the CAR table, the personnel number from the EMPLOYEE table appears at
most once, but it may also not appear at all.
The member number from the MEMBER table can appear in the RESERVATION
table with a minimum of 0 and a maximum of infinity. The member number in
the RESERVATION table must appear at most once in the MEMBER table. The
ISBN in the RESERVATION table must appear at most once in the BOOK table.
Reader 22
The ISBN in the BOOK table can appear in the RESERVATION table with a
minimum of 0 and a maximum of infinity.
5 Designing an ERD
Irrelevant entities:
Entities that become a table that always contain one record, are irrelevant and
are not included in an ERD.
Attributes list:
6 Normalization
Introduction to Normalization
The goal is to minimize redundancy and prevent anomalies (errors during
insert, update, or delete operations) by structuring data logically.
Normalization Process
The document outlines the steps to achieve the Third Normal Form (3NF),
starting from the Zeroth Normal Form (0NF).
Steps:
Reader 23
2. Inventory all attributes (e.g., student number, name, course code).
Example:
Steps:
1. Ensure atomicity (e.g., address can be split into street, house number,
etc., but only if necessary).
3. Carry over the primary key to the new entity and create a composite
key (e.g., Student Number + Course Code ).
Example:
Reader 24
Two tables:
Steps:
1. Identify attributes not fully dependent on the composite key (e.g., Course
3. Link the original entity to the new one via a foreign key.
Example:
Reader 25
Three tables:
STUDENT .
Reader 26
4. Third Normal Form (3NF)
Definition: 2NF + remove transitive dependencies (attributes not dependent
on the key but on other non-key attributes).
Steps:
Reader 27
2. Separate them into a new entity (e.g., "LECTURE BUILDING").
BUILDING ).
Example:
Four tables:
STUDENT .
COURSE .
2. Refined ERD (Figure 6.7): Reflects the normalized tables with proper
relationships (e.g., ENROLLMENT as an associative entity between STUDENT
and COURSE ).
Key Takeaways
Normalization ensures data integrity by eliminating redundancy and
dependencies.
Reader 28
Rrrresummen
Database
In an organisation people work together to achieve a certain goal. In order to
achieve this goal, all kinds of data are used, which also need to be stored
somewhere. Nowadays, this usually happens in one central storage: a
database.
Database Structure
When all the data is stored in a database on one large pile, redundancy quickly
arises: the same data occurs several times, with all the dangers that entails.
The relational model offers a solution to this problem: the large pile of data is
split into a number of small piles: tables. These tables are
connected by keys (numbers or codes that make a record unique). The
references between the tables that emerge must of course be correct, this is
what we call referential integrity.
Concepts:
Process-oriented approach: Focuses on how data flows through processes in
a system.
Data-oriented approach :Focuses on organizing and storing data efficiently,
independent of processes.
Reader 29
Key: A field (or fields) used to uniquely identify a record in a table.
Composite key: A key made up of two or more attributes to uniquely identify a
record.
Referential integrity: Ensures relationships between tables remain consistent
and valid.
Inconsistency: Conflicting or mismatched data in a system, often due to
redundancy.
ERD
Before we build a database, it's wise to create a design first. The entity
relationship diagram (ERD) is a technique for designing databases. We have
three symbols at our disposal:
Cardinality
For a relationship the cardinality is also captured in an ERD. The cardinality
consists of functionality and totality. The functionality indicates whether an
entity can occur multiple times in relation to another entity (n), or up to once (1).
Totality can indicate whether an entity always occurs in relation to another
entity (T), or not always (O).
Special relationship
In order to design the most efficient database possible, we have a number of
special relationships at our disposal:
Reader 30
From ERD to Database/Conversion
The ERD must be translated into the relational model before we can actually
build a database. The complete process:
Reader 31
In the above example, (in two steps) the key from A is also included in B via R,
where it will function as a reference to A.
Basic Rules
The first step in translating to the relational model is applying the three basic
rules:
2. Convert each entity into a table (with its attributes) and assign each table a
key (for IS_A, inheritance applies)
3. Convert each relationship into a table (with its attributes), except for IS_A.
The key is formed by adding the keys of the connecting entities.
Restructuring
After applying the basic rules, restructuring must take place. This involves
considering functionality and totality:
Reader 32
Attributes are not subsumed on one
side with the totality O.
Relevance
When designing an ERD, we need to make sure that we only include relevant
entities and relationships. A tool to discover irrelevant entities is to imagine
what records will appear in that entity once it has become a table. If such a
table always contains only one record or meaningless data, the entity is
irrelevant.
In the case of relationships, the situation in the organisation should be looked
at in particular: what links are one interested in? Only the relationships that the
organization needs are included in the ERD.
Floor
In addition to the theory, the following can be noted:
Pitfalls
When designing an ERD, the following matters should be taken into account:
Reader 33
Sometimes we accidentally model attributes as entities.
When using the relationship IS_A we need to take into account a number of
rules.
In an ERD's attributes list, we are not yet allowed to indicate keys and not
yet restructure.
Reader 34