WORKING WITH MULTIPLE TABLES

CHAPTER 10, CLASS x

1. Table Management Operations

Once tables are created in a database, they can be edited, renamed, or deleted using the Database User Interface in LibreOffice Base.

  • Editing a Table: In the Database Pane, select the Table object, right-click the desired table name, and select Edit. This opens the table in Design View to add/remove fields or modify field properties. Modifications made will not affect previously entered records.
  • Deleting a Table: Right-click the table name in the Table Area, select Delete, and click Yes on the confirmation alert box.
  • Renaming a Table: Right-click the table name, select Rename…, type the new name, and press Enter.

2. Table Relationships Overview

Setting up relationships between tables helps control data redundancy (duplication of data) and data inconsistency (conflicting values for the same field across tables).

  • Prerequisite: To create a relationship, there must be a common field(s) between the two tables.
  • Data Type Requirement: The common fields in both tables must have the exact same data type. If they differ, LibreOffice Base will display an error message and reject the relationship.
  • Master vs. Transaction Table:
    • Master Table (Master Record): The parent table containing unique records (e.g., Student_Details) where the common field is typically the Primary Key. Data must be entered here first.
    • Transaction Table (Transaction Record): The child table containing dependent records (e.g., Student_Result) where the common field acts as a Foreign Key.

3. Types of Relationships

(i) One-to-One Relationship

  • Definition: A single record in the master table corresponds to one and only one record in the transaction table.
  • Examples:
    • A student and their specific admission number / examination result record.
    • A citizen and their driving license number.
    • A person and their entry ticket number.

(ii) One-to-Many Relationship

  • Definition: A single record in the master table corresponds to multiple records in the related transaction table. This is the most common relationship type.
  • Examples:
    • One teacher teaching multiple classes or students.
    • One customer placing multiple orders.
    • One category containing multiple sports events.

(iii) Many-to-Many Relationship

  • Definition: Multiple records in the master table correspond to multiple records in the transaction table. Used when entries need to be stored multiple times in both tables.
  • Examples:
    • Teachers assigned multiple administrative departments/duties.
    • Multiple customers purchasing multiple products from a shop.

4. Key Advantages of Relating Tables

  1. Prevents Data Redundancy: Reduces duplicated entries across the database.
  2. Ensures Data Integrity: Prevents users from entering invalid or non-existent data into referenced foreign key fields.
  3. Automatic Synchronization: Updates in the master table are automatically reflected across all connected transaction tables.
  4. Maintains Referential Integrity: Prevents missing or orphaned data when master records are updated or deleted.

5. Step-by-Step: Creating a Relationship in LibreOffice Base

  1. Open Relationship Screen: From the top main menu, click Tools $\rightarrow$ Relationships…
  2. Add Tables: In the Add Tables dialog box, select the required tables (e.g., Events and EventCategory) and click Add. Click Close when finished.
  3. Establish Link: Click and drag the common field (e.g., CategoryID) from the master table and drop it onto the corresponding field in the transaction table.
  4. Identify Notation: A joining line will appear with labels ‘1’ on the primary key (referenced) side and ‘n’ on the foreign key (referencing) side.

6. Referential Integrity & Options

Definition

Referential integrity is a database principle ensuring that no unmatched foreign key values exist in a database. A transaction record cannot exist without a valid, corresponding master record.

Update / Delete Action Options in LibreOffice Base

To configure these options, double-click the relationship line joining the two tables to open the Relations dialog box:

OptionBehavior
No action (Default)Blocks the user from updating or deleting a record in the master table if related records exist in the transaction table.
Update cascadeAutomatically updates or deletes all related records in transaction tables whenever the master record is updated or deleted.
Set NULLAutomatically sets foreign key values in related transaction records to NULL if the master record is deleted or updated.
Set defaultAutomatically assigns a fixed default value to foreign key fields in transaction records if the master record is deleted or updated.

7. Solved Practice Questions & Exercise Key

Section A: Multiple Choice Questions (MCQs)

  1. Which of the following actions can be performed once tables are created?
    • Answer: (d) All of the above (Add field, rename table, delete table)
  2. Which of the following is checked by a DBMS?
    • Answer: (c) Both (a) and (b) (Redundancy and Inconsistency)
  3. Which of the following is required to set a relationship between two tables?
    • Answer: (b) Both the tables must have a common field
  4. If a record is added in a master table, which of the following is NOT true for transaction table?
    • Answer: (b) The corresponding record in transaction table can only be entered once. (In one-to-many, it can be entered multiple times)
  5. Which type of relationship exists between a student and the subjects studied by him/her?
    • Answer: (c) Many-to-many
  6. Consider the tables Item and Item_Category. Which type of relationship can be established between them?
    • Answer: (b) One-to-many (One category contains multiple items)
  7. Which of the following menus contains the Relationship option?
    • Answer: (c) Tools
  8. The list of tables to be added is displayed in the ______ dialog box in the Relationship Screen.
    • Answer: (a) Add Tables
  9. In the relationship design screen, the relationship between two tables is done using ______ operation.
    • Answer: (c) Drag and Drop
  10. Which of the following is NOT an option that can be used to maintain referential integrity?
    • Answer: (d) Set Value

Section B: True or False

  1. Redundancy is preferred in a database. $\rightarrow$ False
  2. In a table, a record for a particular entity should not be repeated. $\rightarrow$ True
  3. A single field should always have only one data value. $\rightarrow$ True
  4. If a table is edited, the records already entered in it are deleted. $\rightarrow$ False
  5. The record in master table should be entered before the corresponding record is entered in the transaction table. $\rightarrow$ True
  6. In one-to-many relationship, one specific record of the master table has more than one corresponding records in the related transaction table. $\rightarrow$ True
  7. The Relationship option is present in the Windows menu. $\rightarrow$ False (It is in the Tools menu)
  8. In a database, the referential integrity is maintained by the user. $\rightarrow$ False (It is maintained by the DBMS)
  9. A relationship is always set between the tables based on a common field. $\rightarrow$ True
  10. If the master record is deleted, the transaction records will always be deleted. $\rightarrow$ False (Depends on rule selected, e.g., No Action, Set NULL)

Section C: Fill in the Blanks

  1. A table to be edited is displayed in Design view.
  2. The most important prerequisite for setting a relationship between two tables is that there must be a common field between them.
  3. In One-to-One relationship, one specific record of a master table has one and only one corresponding record in the transaction table.
  4. One-to-Many is one of the most common types of relationship between tables in a database.
  5. A record being entered in a transaction table must always exist in a master table.
  6. The principle of referential integrity helps prevent missing data by keeping deleted data from getting out of synch.
  7. Creating relationships between tables restricts the user from entering invalid data in the referenced fields.
  8. Data integrity is maintained by DBMS.
  9. A relationship between customers and products is an example of Many-to-Many relationship.
  10. The Relationship Design window is used to set relationships between the tables.
Scroll to Top