Chapter-10 Working With Multiple Tables
Chapter-10 Working With Multiple Tables
Editing a table involves the task such as adding a new field or removing any field in a table or to
alter any of the field properties.
To edit a table, open the Database User Interface window.
Select the Table object in the Database Pane. The list of tables will be displayed in the Table
Area. Right click on the table name and select Edit option from the drop-down menu.
To delete a table, right click on the table to be deleted, say Customer table and select the Delete
option from the drop-down menu.
One-to-one relationships
In a one-to-one relationship, one record in a table is associated with one and only one record in
another table. The record pertaining to Student_ID in the Students table is considered as the
master record in the parent table.
While the corresponding record in the related table Contact_info, is the transaction record in the
child table. Therefore Student_ID is called the master table or parent table and Contact_info is
called the transaction table or child table.
Hence, in a school database, each student has only one student ID, and each student ID is
assigned to only one person.
A one-to-one relationship looks like this in the relationships graph:
In this example, the key field in each table, Student_ID, is designed to contain unique values. In
the Students table, the Student_ID field is the primary key; in the Contact_Info table, the
Student_ID field is a foreign key.
This relationship returns related records when the value in the Student ID field in the Contact
Info table is the same as the Student ID field in the Students table.
One-to-many relationships
In a one-to-many relationship, one record in a table can be associated with one or more records
in another table. For example, each customer can have many sales orders.
A one-to-many relationship looks like this in the relationships graph:
In this example the primary key field in the Customers table, Customer ID, is designed to
contain unique values. The foreign key field in the Orders table, Customer ID, is designed to
allow multiple instances of the same value.
This relationship returns related records when the value in the Customer ID field in the Orders
table is the same as the value in the Customer ID field in the Customers table.
Because relationships work both ways, there are also many-to-one relationships.
Many-to-many relationships
A many-to-many relationship occurs when multiple records in a table are associated with
multiple records in another table. For example, a many-to-many relationship exists between
customers and products: customers can purchase various products, and products can be
purchased by many customers.
A typical example of a many-to many relationship is one between students and online courses.
A student can register for many courses, and a course can include many students.
Advantages of Relating Tables in a Database
There are various advantages of relating tables in a database. Few of them are as given
below.
Referential Integrity
Referential integrity is a term used in database design to describe the relationship between two
tables. It is important because it ensures that all data in a database remains consistent and up
to date. It helps to prevent incorrect records from being added, deleted, or modified.
Referential integrity is a data quality concept that ensures that when you make changes to data
in one place, those changes are reflected in other related records. This is done by enforcing a
rule that says that the foreign key in one table can only refer to the primary key of another table.
This means that if you change the information in one column, it will automatically be updated in
all other related columns.
LibreOffice Base gives us the 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