Relationship


Relationship

A relationship is created when a couple of tables is connected using a primary key and a foreign key. A relationship is also created when two tables are connected using a third table called linking table. Relationships keep the integrity of the data because they avoid duplicate date.
Una relación es creada cuando una pareja de tablas se junta a través de una llave primaria y una llave extranjera. Una relación también se crea cuando dos tablas son unidas por medio de una tercera tabla llamada tabla conectora (linking table). Las relaciones ayudan a mantener la integridad de los datos porque aseguran que no existirán datos duplicados.

Tip
When defining a foreign key, it is highly recommended to use the same data definition as the primary key. For example, if the primary key is an INTEGER, then the foreign key must also be an INTEGER.
Cuando se define una llave extranjera, es altamente recomendable usar la misma definición de datos que se uso para definir la llave primaria. Por ejemplo, si la llave primaria es un INTEGER, entonces la llave extrajera también debe ser un INTEGER.

Tip
In a relational database, relationships may be established between any two attributes that have compatible data values. An attribute in one table that consists solely of numeric values can be related to any attribute in any other table that also consists solely of numbers. In this way, logical links between tables are very easy to establish.
En una base de datos relacional, las relaciones pueden establecerse entre dos atributos que tienen datos compatibles. Un atributo en una tabla que consiste solamente de valores numéricos puede ser relacionado con otro valor numérico en otra tabla. De esta forma, conexiones lógicas entre las tablas puede ser fácilmente establecidas.

One to many relationship

One record in the first table can relate to one or more records in a second table, but only a record in the second table relates with only one record in the first table. A client may place more than one order, this implies that the client_id will appear more than once in the order table.
Un registro en la primera tabla puede relacionarse con uno o más registros en una segunda tabla, pero un solo registro en la segunda tabla puede relacionarse con solo un registro en la primera tabla. Un cliente puede hacer más de una orden, lo que significa que la cliente_id se encontrará más de una vez en la tabla orden.

OneToMany

One to one relationship

It exists between a pair of tables if a single record in the first table is related to only one record in the second table, and the single record in the second table is related to only one record in the first table. They are rare but can occur, they are usually implemented for security or speed reasons.
Existe entre una pareja de tablas si un registro en la primera tabla está relacionado con solamente un registro en la segunda tabla, y un registro único en la segunda tabla está relacionado solamente con un sólo registro en la primer tabla. Esto es raro pero puede ocurrir, y usualmente se implementa por razones de velocidad o de seguridad.

OneToOne

Tip
Occasionally, you might want to break down a table further because you use some of the data in the table infrequently or because some of the data in the table is highly sensitive and should not be available to everyone. In some cases, one to one relationships are used to deactivate records by moving them to another table. The relationship between the original client table and the credit_client table is one-to-one. That is, for each record in the first table, there is exactly one record in the second table.
Ocasionalmente, una tabla puede partirse en dos porque ciertos datos en la tabla no son accesados con frecuencia o por que ciertos datos contienen información que debe manejarse como confidencial. En algunos casos se puede usar para des-activar registros que ya no se usan moviéndolos a otra tabla. Considere por ejemplo la tabla de cliente la cual mantiene una relación de uno a uno con la tabla credit_client, la relación es de uno a uno. Esto es, por cada registro en la primera tabla, existe uno y solo un registro en la segunda tabla.

Many to many relationships

Many-to-many relationship: multiple records from one table are related to multiple records in another table. This type of data relationship can be found in nearly all business or personal database applications.
En este caso varios registros en una tabla están relacionados con varios registros en otra tabla. Este tipo de aplicación es extremadamente popular.

Tip
Examples of many to many relationships:
  • A patient may need many different medications, and any medication is administered to many patients.
  • A movie in a Bluray has may actors, and any actor appears in many movies.

Ejemplos de relaciones de muchos a muchos:
  • Un paciente en particular puede requerir varios medicamentos, y cualquier medicamente es administrado a muchos pacientes.
  • Un película en Bluray de casa contiene varios actores, los cuales aparecen en muchas películas.

Problem 1
cirtuit_city> mention the type of relationships in this database. For each table pair, choose one the following options: one-to-one, one-to-many, many-to-many.
Mencione el tipo de relaciones en esta base de datos. Por cada par de tablas, escoja una de las siguientes opciones: uno-a-uno, uno-a-muchos, muchos-muchos.
  1. client/orderx
  2. orderx/ord_det
  3. client/client_credit
  4. order_det/item

Problem 2
kimberly> mention the type of relationships in this database. For each table pair, choose one the following options: one-to-one, one-to-many, many-to-many.
Mencione el tipo de relaciones en esta base de datos. Por cada par de tablas, escoja una de las siguientes opciones: uno-a-uno, uno-a-muchos, muchos-muchos.
  1. material/item

Problem 3
city_bank> mention the type of relationships in this database. For each table pair, choose one the following options: one-to-one, one-to-many, many-to-many.
Mencione el tipo de relaciones en esta base de datos. Por cada par de tablas, escoja una de las siguientes opciones: uno-a-uno, uno-a-muchos, muchos-muchos.
  1. account/client_account
  2. client_account/client
  3. account/branch

Problem 4
univ> mention the type of relationships in this database. For each table pair, choose one the following options: one-to-one, one-to-many, many-to-many.
Mencione el tipo de relaciones en esta base de datos. Por cada par de tablas, escoja una de las siguientes opciones: uno-a-uno, uno-a-muchos, muchos-muchos.
  1. student/department
  2. department/staff

Problem 5
ford> mention the type of relationships in this database. For each table pair, choose one the following options: one-to-one, one-to-many, many-to-many.
Mencione el tipo de relaciones en esta base de datos. Por cada par de tablas, escoja una de las siguientes opciones: uno-a-uno, uno-a-muchos, muchos-muchos.
  1. position/payroll
  2. division/payroll
  3. payroll/employee

Problem 6
Explain when a linking table is necessary to create a relationship between two tables. Consider for instance, the client_account table in the city_bank database.
Explique cuando es necesaria una tabla conectora para crear una relación entre dos tablas. Considere por ejemplo, la tabla client_account en la base de datos city_bank.

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home