This is a Clilstore unit. You can link all words to dictionaries.

UNIT 6. DATABASES - MODULE 2

 

LIBRE OFFICE BASE

MODULE 2.

Relations



Objectives



Provide consistency and referential integrity to the Databases creating relations among the tables



Contents



The concepts treated in this module are:

Relation Concept

There is a relation between two tables when the values in a column of the first table must exist in a column of the second table





 

 

 

 

 

 

 

 

 

 

For example, in Pedidos there is a field IDEmpleat meant to contain the identifier of the employee in charge of the order ( el pedido). To keep the consistency of the information in this database, it's important to protect this field to prevent the user from entering in this column a fictitious employee. A fictitious employee is an employee who doesn't have a record in the table Empleados. That's what a relation is, a rule linking the data from two columns in different tables which must be kept consistent.



Therefore (por tanto), a relation constrains (restringe) the possible values in a field, (called alien key or clave ajena), to those existing in the identifier field (called the primary key or clave primaria) of the referenced table, avoiding in this way the insertion of fictitious data.



Types of relations



There are three types



  1. Relation 1 to 1. Example : A teacher can be the tutor of a single students group (ONE) and a students group can only have a single tutor (ONE)

 



 

 

  1. Relation 1 to N: Example: Students and Groups. A student belongs to a single group (ONE) but a group has a number of students belonging to it (N)

  2. Relation N to N: Teachers and Groups. A teacher give class to a number of groups (N) and a group is given class by a number of teachers In LO Base this kind of relation can not be represented. If there is a N to N relation, this is represented by an additional table, but this issue won't be treated in this course.






If you couldn't understand these concepts, call the teacher, he will explain it to you.







IMPORTANT: To make a relation, the two fields (the primary key and the alien key) must contain the same data types. That means, it's not possible to relate a text field with a numeric one.

BUILDING A RELATIONS SCHEME

Download from Moodle the database biblioteca.odbb.



So we can create a relation between Llibres and Llengua, linking the field Codi llengua in both tables.







Notice that there is a new line linking both fields. This is how LO Base represents a relation. Notice the little numbers 1..N showing the relation type





Adding more relations

 

 

 

 

 

 

 

 

 





 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
































 

 

 

 

 

 



EXERCICI 15 Puja a moodle la base de dades biblioteca.odb amb totes les modificacions realitzades en aquest modul

13/13

Short url:   https://multidict.net/cs/4681