Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Comprehensive Guide to Cardinality in DBMS

Last Updated on October 3, 2022 by Ria Pathak

Introduction:

When we talk about Database Management Systems (DBMS), or we deal with databases (SQL or No-SQL), we often hear the term cardinality. It is a very important term in DBMS. People often get confused with the difference between cardinality and degree in DBMS. In this article, we are going to discuss cardinality in detail and will answer a lot of your questions and clear your doubts. So, let’s get started with the basics first.

Basics of DBMS

These are the basics that you should know before jumping into cardinality and its concepts. So, let us understand these concepts one by one.

What is an Entity?

An entity is an object in the real world that is distinguishable from other objects based on the values of attributes (properties) it possesses. For example, a Student with the name “Guneet” and enrollment number “98765” studying in the IT Department of a particular college is uniquely identifiable because of the values of the attributes he possesses. This is because even if there are multiple students with the name “Guneet”, there will only be one student with the enrollment number “98765” as the enrollment numbers are unique.

So, even if one attribute is there to help identify the real-world object separately from others, that real-world object is an entity.

The term entity is observer-dependent. How? Let us say you are a part of the college in which this student is studying and you know that enrollment number will uniquely identify this student. Now, if someone outside of this college came into the college to deliver a package, he/she does not know the student’s enrollment number. The delivery person only knows that the delivery has to be made to someone named Guneet.
So, if the delivery person does not have any Phone number or any other unique feature to identify the customer to whom he has to deliver the parcel, this student “Guneet” is now not an entity as he cannot be uniquely identified.

So, calling an object as an entity is observer-dependent.

What are the types of Entities?

An entity can be of 2 types.

  1. Tangible Entities: The entities that can be touched physically like a car, pen, or bank locker.
  2. Non-Tangible Entities: The entities that cannot be touched physically are non-tangible entities like a bank account.

What is an Entity Set?

A collection or a set of the same types of entities i.e. the entities that share the same attributes and properties is called an entity set. For instance, Student is an entity set. Teacher is an entity set. However, a particular student with a particular name, enrollment number, etc. is an entity.

What is a Relationship?

A relationship is an association between 2 or more 2 entities of the same or different entity set. For example, let us say that the teacher Mr. Gupta is an entity of the entity set Teacher and the Student “Guneet” is an entity of the entity set Student.

So, if we say, “Mr. Gupta teaches Guneet.”, then “teaches” is a relationship between 2 entities of different entity sets. However, if there is a class of 5 students say “Guneet”, “Yash”, “Ashish”, “Rohan” and “Ajay” and Ajay is the monitor of this class and we say, “Ajay monitors Guneet, Yash, Ashish, and Rohan.”, then “monitors” is a relationship between more than 2 entities of the same entity set Student.

What is a Relationship Set?

The relationship set is a set of similar types of relationships. For instance, in place of naming every teacher and every student they teach, if we say, “Teacher teaches students”, then teaching is a relationship set between 2 entity sets Teacher and Student. This is represented as shown below.

Note: It is important to note that relationship and relationship set are 2 different things. Similarly, entity and entity set are 2 different things. However, we usually use the words “relationship” and “relationship set” synonymously. So, we will be using the word relationship only.

What is an ER Diagram?

The above-shown representation of a relationship set and 2 entity sets is actually an ER diagram or what we call an Entity-Relationship Diagram.

Note: It is interesting to note that the name is “Entity-Relationship Diagram”, however, we don’t represent entity and relationship in the ER diagram. We represent the entity set and relationship set in the ER diagram.

Now you can take Mock Tests which will consist of questions of the DBMS that may appear in the interview itself. Go on, check it out and start giving the test!

Now that we have a basic understanding of all the concepts, let us move to cardinality in DBMS.

What is Cardinality?

Cardinality (or Mapping Cardinality) expresses the number of entities to which another entity can be related in a relationship. For example, if there is a relationship where one entity can relate to a maximum of 5 entities, then the cardinality of that entity is 5. The concept of cardinality is better understood and better used in cardinality ratios.

What are Cardinality Ratios?

These are the ratios that represent the cardinalities of different entities against one another in a relationship. For instance, let us see the following relation.

One-to-One Relationship (1:1)

This relationship shows that every Indian citizen has exactly 1 Aadhaar Number and also, an Aadhaar Number is unique and can belong to exactly one citizen. So, the cardinality ratio here is 1:1. This is a One to One Relationship. The one-to-one cardinality mapping is shown by either writing 1 on both the arms of the relationship in the ER diagram or by drawing arrowed arms as shown below.

One-to-Many Relationship (1:N)

In this cardinality ratio is 1:N. This means that an entity of the first entity set can map to at most N entities of the second entity set, however an entity of the second entity set can map to at most 1 entity of the first entity set. This can be shown in the following 2 ways shown below.

So, the above relationship shows that an Indian citizen can have at most N phone numbers i.e. more than 1 phone number. However, a phone number belongs to one particular person only. A phone number cannot be shared by 2 or more people. This was an example of a one-to-many relationship.

Many-to-One Relationship (N:1)

This is the exact opposite of a one-to-many relationship. So, we can take the above example only and reverse it. It will become a many-to-one relationship.

Many-to-Many Relationship (M:N)

A many-to-many has a cardinality ratio of M:N. This means that the entity of the first entity set can map to at most M entities of the second entity set and the entity of the second entity set can map to at most N entities of the first entity set. This is shown below.

So, a teacher can teach multiple students and a student can also be taught by multiple teachers.

Now, the last thing we need to discuss is the difference between Cardinality and Degree.

What is the difference between Degree and Cardinality in DBMS?

Degree refers to the number of entity sets associated in a relationship. For instance, consider the relation shown below.

Here, there are 2 entity sets participating in a relationship and they are Student and Teacher. Although the cardinality ratio is M:N or many-to-many, the relationship degree is 2 since there are 2 entity sets participating. Thus, this relationship is a binary relationship.

So, we hope that you have understood the concept of cardinality and the differences between cardinality and degree. Let us now look at some FAQs.

Also you can prefer this DBMS Interview Questions article for better understanding, go and check it out!

Cardinality In DBMS FAQs (Frequently Asked Questions)

1. Are cardinality and degree the same?

No, cardinality and degree are not the same. Cardinality tells us the maximum number of entities an entity can be associated with in a relationship. However, degree just tells about the number of entity sets participating in a relationship.

2. What is the minimum possible Cardinality?

The cardinality can be 0. This is the case of partial participation i.e. the entities are allowed not to participate in a relationship. If the minimum cardinality of a relationship is 1, then it is called total participation i.e. every entity has to take part in a relationship.

3. What is the minimum possible degree?

The degree can be 1 at the minimum. For example, consider the following relationship.

The relationship below shows that there is a class of students and out of them 1 is the class monitor and he/she monitors the rest of the class. So, this relationship is between Student and Student only i.e. there is only one entity set. Hence, the degree is 1 and it is called a unary relation. It can also be represented as shown below.

So, with this, we come to the end of our FAQs and our discussion on the topic, Cardinality in DBMS. Hope you liked the discussion and understood the concepts well. We will see you again at PrepBytes.

We tried to discuss Cardinality in DBMS in this article. We hope this article gives you a better understanding of the topic Cardinality in DBMS you will face in the Interviews. Prepbytes also provides a good collection of Foundation Courses that can help you enhance your coding skills. Want to make sure you ace the interview in one go? Join our Placement Program that will help you get prepared and land your dream job at MNCs. Mentors of Prepbytes are highly experienced and can provide you with basic, in-depth subject knowledge for better understanding.

Leave a Reply

Your email address will not be published. Required fields are marked *