What are the different types of relationships in DBMS?

  • Entities may have several relationships among themselves. Whenever an attribute of one entity refers to another entity, there exists a relationship between the two entities.
  • A relationship, in the context of databases, is a situation that exists between two relational database tables when one table has a foreign key that references the primary key of the other table. Relationships allow relational databases to split and store data in different tables, while linking disparate data items.
  • Any association between two entity types is called a relationship. Entities take part in the relationship. It is represented by a diamond shape.

Types of Relationship

Three types of relationship exist among entities. These are:

  • One-to-one
  • One-to-many
  • Many-to-many

One-to-one(1:1) Relationship

  • A one-to-one (1:1) relationship is when at most one instance of a entity A is associated with one instance of entity B.
  • For example, in a university each department has only one head of the department. Moreover, one faculty member cannot head more than one department. This shows one-to-one (1:1) relationship between department and the person as head.
  • One-to-one(1:1) Relationship

One-to-many (1:M) Relationship

  • A one-to-many (1:M) relationships is when for one instance of entity A, there are zero, one, or many instances of entity B, but for one instance of entity B, there is only one instance of entity A.
  • An example of a 1:M relationships is A department has many employees, Each employee is assigned to one department
  • One-to-many (1:M) Relationship

Many-to-many (M:M) Relationship

  • A many-to-many (M:M) relationship, sometimes called non-specific, is when for one instance of entity A, there are zero, one, or many instances of entity B and for one instance of entity B there are zero, one, or many instances of entity A.
  • For example, one customer may buy many items and one item may be bought by many customers.
  • Many-to-many (M:M) Relationship