There are 3 core relationship rules, relational databases. However, in some literature, you will see that some count on of them twice depending on the flow of data.
The three core relationship rules within a relational database are:
- One-to-One Relationship
- One-to-Many Relationship (*Many-to-One Relationship)
- Many-to-Many Relationship
*Sometimes included as an additional relationship but really it is the same in reverse.
One-to-one relationships are, as the name suggests, where only one possible relationship exists. A parent record can only be related to one child record in a relevant table. Lets look at the example below.
A Country (parent record) can only have one Capital City (child record in relevant table). Likewise a Capital City can only belong to one Country. Therefore, the relationship is One-To-One.
In the case of One-to-Many, the relationship is between one parent record and potentially one or more child records.
Let’s take a look at another example. In this example, a Customer (parent record) might have lots of Orders (child records). However, an Order can only ever belong to one Customer.
Thirdly, Many-to-Many relationships where a single or multiple parent records, relate to single or multiple child records in another table.
In the example below, multiple Orders (parent records) can contain multiple products (child records). Likewise, multiple Products can be part of multiple order.
I hope you found this post useful? If you have any questions, please comment below.