Relationships in DBMS

Relationship in DBMS

What are Relationships in DBMS

In this article, we will learn about Relationships in DBMS.

A relationship in context of DBMS is mutual situation where two tables in a RDBMS model are related to one another such that, one table has foreign key that is a primary key in another table. Well we may have confused you, if you were please read foreign key and primary key on PrepInsta.

Let us give you some examples below rather than the bookish definition given above.

While most websites say that the following are types of relationships –

  • One to One
  • Many to One
  • Many to Many

The above information is not true, the above is called Cardinality. The relationship is of the following types –

  • Unary Relationship
  • Binary
  • n-ary

Unary Relationship

It is a case when an entity is related to itself. For example an entity type called person will be married to a person itself.

Unary Relationship in Entity Relationship Diagram in DBMS

Binary Relationship

It is when there are two entities which different entities are related to one another like a student is related to another entity called courses, as enroll type of relationship.

Binary Relationships in Entity Relationship Diagram in DBMS

n-ary Relationship

n-ary relationship is when there is complex relationship amongst various entities. These are generally avoided by programmers to keep database architecture simple

For example –

Men eating animal, Animals eating animals, Men eating Plants, Animal eating plants etc etc. All of them are bound by eating relationship.

n-ary Relationship
Relationship in DBMS

Cardinality

All websites confused relationships as cardinality. While cardinality refers to number of participating instances in a relationship, which can be anyUnary, Binary or n-ary. Following, are the cardinality in relationships in DBMS.

  • One to one
  • Many to One
  • Many to many
Cardinality in DBMS

One to One Cardinality in Relationship

In such cases only, a unique row in Table A will be related to only and only one unique row in Table B. We can take example of marriage between man and wife.

 

Many to One Cardinality in Relationship

In such cases many rows in table A are related to only one unique row of Table B. For example course enrollment relationship between students and University. For example many students can enroll in only one single university.

 

One to Many Cardinality in Relationship

In such cases a single unique row in table A are related to only multiple rows of Table B. For example Company gives employment to employees.

 

Many to Many Cardinality in Relationship

In such cases many rows in table A are related to many rows of Table B. For example student course enrollment relationship between students and Courses offered by university. As many students can enroll for many courses.