Database
Database
Database Models
Database Models
Primary key
Each table should have a primary key, which means a field whose
value is different for every record,
For example student number for a students’ table.
Information redundancy
situations trying to put the information we need in a single table
database causes a duplication of identical data.
For example, if we add to our students’ table the information on who
is the reference secretary for each student, together with other
secretary’s information such as office telephone number, office room
and timetables, we get this table:
Information redundancy is not a problem by itself, but:
storing several times the same information is a waste of computer
space
whenever we need to update a repeated information (e.g. the
secretary changes office), we need to do a lot of changes;
manually inserting the same information several times can lead to
typing (or copying & pasting) mistakes, which decrease the quality of
the database.
In order to avoid this situation, it is a common procedure to split the
table into two distinct tables, one for the students and another one
for the secretaries. To each secretary we assign a unique code and to
each student we indicate the secretary’s code.
Foreign key
When a field, which is not the primary key, is used in a relation with
another table this field is called foreign key.
One‐to‐many relation.
For the example of section the tables above are indicated in this way,
meaning that for each student there is exactly one secretary and for
each secretary there are many students. This relation is called many‐to‐
one relation.
The Entity-Relationship (ER)
Model
The Entity-Relationship (ER) Model is a conceptual framework
used to represent and design databases by identifying entities, their
attributes, and the relationships between them. It provides a clear,
high-level structure of the data and how they are interconnected
An entity is a real-world object, concept, or thing that can be
distinctly identified and stored in a database. Entities typically
represent objects that have data associated with them.
Example: Employee, Product, Department, Customer.
Types of Entities
Strong Entities:
These exist independently of other entities. For example, "Employee"
could be a strong entity
Weak Entities:
These depend on a strong entity and cannot exist without it. For
example, "Dependent" in relation to an Employee might be a weak
entity because its existence depends on the Employee entity.
Attributes