GST Billing Software

header image

Database Design Relationship

Erachana Line

5. Database Design Relationship

Relationships are represented by a diamond-shaped box. All the entities (rectangle shaped) participating in a relationship gets connected using a line.



5.1 One-to-One

A row in table A can have only one matching row in table B, and vice versa. This is not a common relationship type, as the data stored in table B could just have easily been stored in table A. However, there are some valid reasons for using this relationship type. A one-to-one relationship can be used for security purposes, to divide a large table, and various other specific purposes.

Example :



5.2 One-to-Many (or Many-to-One)

This is the most common relationship type. In this type of relationship, a row in table A can have many matching rows in table B, but a row in table B can have only one matching row in table A.

Example :


5.3 Many-to-Many

In a many-to-many relationship, a row in table A can have many matching rows in table B, and vice versa. A many-to-many relationship could be thought of as two one-to-many relationships, linked by an intermediary table. The intermediary table is typically referred to as a "junction table" (also as a "cross-reference table"). This table is used to link the other two tables together. It does this by having two fields that reference the primary key of each of the other two tables. The following is an example of a many-to-many relationship:

Example :



5.4 Assignment

Create a Company database that consists of all the three relations, i.e. one-to-one, one-to-many(many-to-one) and many-to-many.