Checking your session…
Module 09: Data Modeling and ER Diagrams

9.4 Cardinality (1:1, 1:N, M:N)

Level: 9 | Version: v1.1 | Author: Meptrasoft

Overview

Cardinality describes how many records in one table can be related to records in another table.

The three common types are:

Type Meaning Example
1:1 One ↔ One Person ↔ Passport
1:N One ↔ Many Department ↔ Employees
M:N Many ↔ Many Students ↔ Courses
Database Cardinality: 1:1, 1:N, M:N relationships
Figure 1: Cardinality describes how many records can be related between entities: one-to-one, one-to-many, or many-to-many.

1:1 — One-to-One

One record in Table A is related to one record in Table B.

Example:

TEXT
PERSON 1 ─── 1 PASSPORT

A person has one passport, and that passport belongs to one person.

1:1 → One to One


1:N — One-to-Many

One record in Table A can relate to many records in Table B.

Example:

TEXT
DEPARTMENT 1 ───< EMPLOYEES

One department can have many employees.

1:N → One to Many


M:N — Many-to-Many

Many records in Table A can relate to many records in Table B.

Example:

TEXT
STUDENTS >───< COURSES

A student can take many courses, and a course can have many students.

In a relational database, this is normally implemented using a junction (bridge) table:

TEXT
Students
   ↓
Enrollment
   ↓
Courses

M:N Example in SQL

SQL
CREATE TABLE enrollment (
    student_id INT REFERENCES students(student_id),
    course_id INT REFERENCES courses(course_id)
);

The enrollment table connects students and courses.

A query can retrieve the relationship:

SQL
SELECT s.student_name, c.course_name
FROM students s
JOIN enrollment e
    ON s.student_id = e.student_id
JOIN courses c
    ON e.course_id = c.course_id;

Quick Comparison

TEXT
1:1 → ONE ↔ ONE
1:N → ONE ↔ MANY
M:N → MANY ↔ MANY

M:N relationships are usually implemented using a junction table.


Common Beginner Mistakes

✗ Mistake ✓ Correct Understanding
1:N means one table has many rows It describes the relationship between records/entities
M:N is directly stored in one foreign-key column It is normally implemented using a junction table
Cardinality and foreign key are the same Cardinality describes the relationship; a foreign key helps implement it
One student can have only one course in an M:N relationship A student can have many courses

Placement Quick Points

  • 1:1 → One record relates to one record.
  • 1:N → One record relates to many records.
  • M:N → Many records relate to many records.
  • M:N relationships are commonly implemented using a junction table.
  • Cardinality helps define database relationships.

Interview Questions

What is cardinality?

Cardinality describes how many records can participate in a relationship between entities.

What is 1:1?

One record relates to exactly one record.

What is 1:N?

One record can relate to many records.

What is M:N?

Many records can relate to many records.

How is M:N implemented in a relational database?

Using a junction/bridge table containing foreign keys referencing the two related tables.


Practice & Hands-On Exercises

  1. Give one real-world example of 1:1.
  2. Give one example of 1:N.
  3. Give one example of M:N.
  4. Explain why a junction table is needed for M:N.
  5. Identify the cardinality between Department and Employee.

💡 Tip: Test your queries and schema definitions using the in-browser interactive runner above.


Key Takeaway

TEXT
1:1 → ONE TO ONE
1:N → ONE TO MANY
M:N → MANY TO MANY

Cardinality describes how many records can be related, with M:N relationships commonly implemented through a junction table.

End of Cardinality (1:1, 1:N, M:N)