What is the degree of relation in DBMS?

We have seen in our previous blog that there are three types of relationship. We have seen many examples in which two entity type like ‘Teacher’ and ‘Student’ are associated with a relationship. So, as we are talking about a relationship in DBMS, is it necessary that at least two entity sets should be there. What is the minimum number of entity sets required in a relationship? Can there be a relationship in which we have only one entity type? What is the maximum number of an entity type that can be a part of a DBMS relationship? We will answer all such question while we go through this blog. So, let's dive deeper and get started with the degree of relationship.

Degree of Relationship

The degree of a relationship is the number of entity types that participate(associate) in a relationship. By seeing an E-R diagram, we can simply tell the degree of a relationship i.e the number of an entity type that is connected to a relationship is the degree of that relationship.

For example, If we have two entity type ‘Customer’ and ‘Account’ and they are linked using the primary key and foreign key. We can say that the degree of relationship is 2 because here two entities are taking part in the relationship.

Based on the number of entity types that are connected we have the following degree of relationships:

  • Unary
  • Binary
  • Ternary
  • N-ary

Unary (degree 1)

A unary relationship exists when both the participating entity type are the same. When such a relationship is present we say that the degree of relationship is 1.

For example, Suppose in a classroom, we have many students who belong to a particular club-like dance club, basketball club etc. and some of them are club leads. So, a particular group of student is managed by their respective club lead. Here, the group is formed from students and also, the club leads are chosen from students. So, the ‘Student’ is the only entity participating here. We can represent this relationship using the E-R diagram as follows:

So, here we get the answer to our first question which was asked in the introduction section. Yes, there can be only one entity type in a relationship and the minimum degree of a relationship can be one.

Binary (degree 2)

A binary relationship exists when exactly two entity type participates. When such a relationship is present we say that the degree is 2. This is the most common degree of relationship. It is easy to deal with such relationship as these can be easily converted into relational tables.

For example, We have two entity type ‘Customer’ and ‘Account’ where each ‘Customer’ has an ‘Account’ which stores the account details of the ‘Customer’. Since we have two entity types participating we call it a binary relationship. Also, one ‘Customer’ can have many ‘Account’ but each ‘Account’ should belong to only one ‘Customer’. We can say that it is a one-to-many binary relationship. (Learn more about types of relationships in DBMS from here)

Ternary(degree 3)

A ternary relationship exists when exactly three entity type participates. When such a relationship is present we say that the degree is 3. As the number of entity increases in the relationship, it becomes complex to convert them into relational tables.

For example, We have three entity type ‘Employee’, ‘Department’ and ‘Location’. The relationship between these entities are defined as an employee works in a department, an employee works at a particular location. So, we can see we have three entities participating in a relationship so it is a ternary relationship. The degree of this relation is 3.

N-ary (n degree)

An N-ary relationship exists when ‘n’ number of entities are participating. So, any number of entities can participate in a relationship. There is no limitation to the maximum number of entities that can participate. But, relations with a higher degree are not common. This is because the conversion of higher degree relations to relational tables gets complex. We are making an E-R model because it can be easily be converted into any other model for implementing the database. But, this benefit is not available if we use higher degree relations. So, binary relations are more popular and widely used. Though we can make a relationship with any number of entity types but we don't do that.

We represent an N-ary relationship as follows:

In the above example, E1 denotes the first entity type, E2 denotes the second entity type and so on. R represents the relationship. So, here we have a total of 5 entity type which participates in the relationship. Therefore, the degree of the above n-ary relationship is 5.

This is all about the degree of relationship in the E-R model of DBMS. Hope you learned something new today.

Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content. You can read more blogs from here.

Keep Learning :)

Team AfterAcademy!