Why table relationships are created in databases…
An important part of designing a relational database is creating multiple tables which are related to each other to effectively and efficiently store data. When you are working with databases, you realize how important it is to find a way link the data in whatever number of tables there are in the database in meaningful way, because, it is more than likely that all the data cannot be contained in one table, at least not without causing unnecessary complications and chaos. It is important to create relationships in databases for many different reasons.
Firstly, there are many different kinds of relationships in real life but in databases there are only three main types. If we consider relationships in different kinds of families we can simply understand the relationships in a database.
For example, a one-to-one relationship may be expressed in a single parent family consisting of a mother and her only daughter. The mother loves only her daughter and her daughter loves only her in their small family. In this example we can consider the family to be the database and the mother and the daughter to be two separate tables. This relates to databases where in two tables, each record only has one matching record on either side of the relationship.
An example of a one-to-many relationship in real life would be a single parent family with a father and three children. There is only one father but he loves all three children but the three children all love one father. Therefore there is a one-to-many relationship since the primary table has multiple matching records in the secondary table.
The third and final relationship is the many-to-many relationship which can be expressed by a nuclear family with a mother, father and two children. Both the mother and father love their two children and the children love both their parents. Therefore, this is a many-to-many relationship because for each parent loves more than one child and each child will love more than one of their parents.
The most obvious reason why relationships are important in databases is to establish a relationship between two or more tables. For example, in the Capetown Public Library’s database there are two logically related tables. The first table named BORROWERS contains fields to show the library card number, borrowers’ first name, last name and some other fields which are unimportant to this example. The second table named BOOKS BORROWED shows the borrowers’ library card number, book borrowed, date borrowed, date book is to be returned and more field unimportant to this example. A relationship exists between the...