Chapter 10 Working With Tables
Chapter 10 Working With Tables
INTRODUCTION
After creating the table in database, we may require to edit or delete the table. Sometimes
we have to setup the relations between tables to control data redundancy and
inconsistency. If you set up relations between tables, then adding or updating a record in
one table reflect the changes in all the related tables.
While working with multiple tables, we should check the redundancy and inconsistency of
data. This can be done by setting relationship between the tables of a database.
Each record in Table 10.2 has a value of Admission No. that corresponds to a record in
Table 10.1 with same Value of Admission No.
NOTE: It is important to note that the data types of the common field in both the tables
must be same. If they are not same then LibreOffice Base will display an error message and
will not allow to set the relationship between the two tables.
After setting the relationship between two tables, once a student’s record has been
entered in the Student_Details table, only then that particular Admission No can be
entered in the Student_Result table. Therefore Student_Details is called the master table
and Student_Result is called the transaction table.
Types of Relationships
Three types of relationships can be set up between two tables in a relational database.
These are:
➢ One-to-One
➢ One-to-many
➢ Many-to-Many
One-to-One relationship: In this type of relationship, one specific record of a master table
has one and only one corresponding record in the transaction table.
One-to-One Relationship
One-to-Many relationship: In this type of relationship, one specific record of the master
table has more than one corresponding records in the related transaction table. For
example
One-to-Many Relationship
For example, a teacher in a school may hold multiple responsibilities such as class
teacher, an activity incharge
Or examination in-charge. For each responsibility the teacher might be attached with
multiple students.
Many-to-Many Relationship
Advantages of Relating Tables in a Database
The relationships applied on the tables can be removed also with the help of Delete
option. Right Click on the relationship thread and select Delete option.
Referential Integrity
According to the principle of referential integrity if a record say Admission No as 1001 is not
present or deleted in the master table, then there should be no record with same
Admission no as 1001 in the transaction table.
LibreOffice Base will allow only that corresponding record to be entered in the transaction
table which already exists in the master table.
LibreOffice Base gives us following four options to choose from to maintain referential
integrity in such cases.
No action – This is the default option. This option states that a user should not be allowed
to update or delete any record in the master table if any related record exists in the
transaction table.
Update cascade – This option allows the user to delete or update the referenced field but
along with it all the related records in any of the transaction tables will also be deleted or
updated.
Set NULL – This option assigns NULL value to all the related fields if the master record is
deleted or updated.
Set default – This option assigns any fixed default value to all the related fields if the
master record is deleted or updated.
SUMMARY
1. Relations are set up between the tables to control data redundancy and
inconsistency.
2. The most important prerequisite for setting a relationship between the two tables is
that there must be a common field(s) between the two tables.
3. Three types of relationships can be set up between two tables in a relational
database. These are One-to-One, One-to-Many and Many-to-Many.
4. In One-to-One type of relationship, one specific record of a master table has one
and only one corresponding record in the transaction table.
5. In One-to-Many type of relationship, one specific record of the master table has
more than one corresponding records in the related transaction table.
6. In Many-to-Many type of relationship, there are multiple records in the master table
that correspond to multiple records in the transaction table.
7. According to the principle of referential integrity, no unmatched foreign key values
should exist in the database.