Site icon libreofficehelp.com

Create Tables and Establish Relationships in LibreOffice Base

A tutorial explains how you can create relationships in LibreOffice Base between tables via design view.

In the prior tutorials, you learned how to create a simple database with tables and enter data using the graphical wizard in LibreOffice Base. That is pretty easy to do.

This guide goes another step towards difficulty. And we will create three tables with an example and establish relations between them.

The example following is a preparation for the upcoming guides, which goes further on creating forms and queries.

Example table structure

For this demo, I will create three tables, as shown below. The player table contains the name and other details of the players.

The sports table contains the name of the sports and events.

And the last table is for establishing the player id with sports id – to show which player is going to play which sport.

Creating the tables

Follow this guide to create a database in LibreOffice Base. Give any name you want. I named it “example_sport_db.odb”.

In the LibreOffice Base window, click on “create table in design view” and create three tables as per the above specification.

Establish relationships

After you have created three tables, click Tools > Relationships from the main Base menu.

You should see the following window. The add table dialog should list the tables in your database. To establish a relationship, double-click on the tables to add them to the canvas. See below.

double-click to add the tables in relationship window

After adding the tables, click on the “new relation” button in the toolbar.

Click on new relation in the toolbar

In the relations window, select the two tables where you want to establish a relation. And select the fields involved. Ideally, you should select the columns of the tables which are related key fields as per your database design.

In this step, you must carefully consider what relationship you want to establish. Yes, you can modify it later on as well.

How to create relationships

Repeat the “new relation” process for each relation you want to establish. In this example, there are two relationships created, and it is shown below.

After creating relationships

Once done, close the window to return to the main Base window. And start adding some data.

Double-click the table name in the main window to open the data entry grid. You can start typing your data here. You can press TAB to navigate between cells, and once done, click on Save.

View the relationship and modify them in LibreOffice Base

At any time, if you want to modify, you can select the relationship handle and right-click to edit. The handle becomes highlighted when selected. And then choose options from the context menu.

Select and edit-delete a relationship

Handling errors and usage guide

Here are some errors and notes that you should remember while creating relationships.

You can not change the column attribute when its part of relationship
SQL Status: S0021
Error code: -57 Column types do not match in statement [ALTER TABLE "rel_player_sport" ADD FOREIGN KEY ("sport_id") REFERENCES "sport" ("sport_id") ON UPDATE CASCADE ON DELETE CASCADE ] at /builddir/build/BUILD/libreoffice-7.4.3.2/connectivity/source/drivers/jdbc/Object.cxx:173
Column type does not match error in Base during relationship build

Summary

In this tutorial, you learned how to create relationships in LibreOffice base tables, change column types and handle some errors. If you have any questions, do let me know in the comment box below.

Exit mobile version