Relationships in DBMS

Relationship in DBMS

What are Relationships in DBMS

On this page, 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.

Entity Relationship Diagram in DBMS unary relation

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.

Entity Relationship Diagram in DBMS binary

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.

Entity Relationship Diagram in DBMS n ary

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

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.

Relationships in DBMS img

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription