Database relationships

priya s
YavarTechWorks
Published in
3 min readNov 16, 2022

Hi everyone, in this post, we are going to learn about the different types of relations in databases.

Database relationships are associated between tables.

There are three types of associations namely:

  1. one-to-one relationship
  2. one-to-many or many-to-one relationship
  3. many-to-many relationship

Below is the diagram to show the notations for the relations used in ER diagram.

One to one Relationship (1:1):

It is used to create a relationship between two tables in which a single row of the first table can only be related to one and only one record of a second table. Similarly, the row of a second table can also be related to anyone row of the first table.

Below is an example to show the one-to-one relationship. A country can have only one capital and the capital belongs to only one country.

One to many relationship(1:N):

It is used to create a relationship between two tables. Any single row of the first table can be related to one or more rows of the second table, but the rows of the second table can only relate to the only row in the first table. It is also known as a many-to-one relationship.

Below is an example to show the one-to-many relationship. A customer can order many items in the restaurant.

Many to many relationships:

Each record in the first table can relate to any records in the second table. Similarly, each record of the second table can also relate to more than one record of the first table. It is also represented as an N: N relationship.

Below is an example of many-to-many relationships. Here a book can have more than 1 author and 1 author can be written more than 1 book. So here it is a many-to-many relationship. This will include an extra table called the junction table. This table has the primary keys of the books table and the author table.

Hope you find it useful. Thank you!!

--

--