What is Relationship Cardinality?

 

What is Relationship Cardinality?


Relationship cardinality
refers to the number of instances of one entity that can be associated with instances of another entity in a database. It defines the type of relationship between two entities and plays a crucial role in database design. The most common types of relationship cardinality are:

  1. One-to-One (1:1): Each record in one table is linked to exactly one record in another table. For example, one person may have one passport.
  2. One-to-Many (1:N): One record in a table can be associated with multiple records in another table, but each record in the second table is linked to only one record in the first table. For instance, one department can have many employees.
  3. Many-to-One (N:1): The inverse of one-to-many, where multiple records in a table can be associated with a single record in another table, such as many orders linked to one customer.
  4. Many-to-Many (N:M): Multiple records in one table can be associated with multiple records in another. For example, students can enroll in multiple courses, and each course can have many students. This often requires a junction table to manage the relationship.

Understanding cardinality is essential for defining how data relates and ensuring the integrity of a relational database.

 We use this in SQL Queries

Do the full course: SQL Course

Comments

Popular posts from this blog

The Seven Different Types of Coding Blocks in Java

What is a web application? (Lesson 7 of our Java Bootcamp)

Why attend a Java Bootcamp?