Cardinality in ER Diagram: Definition and Examples
ER diagram, cardinality defines the number of instances of one entity that can or must be associated with instances of another entity. It shows the minimum and maximum relationships, such as one-to-one, one-to-many, or many-to-many.How It Works
Cardinality in an ER diagram tells us how many objects in one entity relate to objects in another entity. Imagine a classroom: one teacher can teach many students, but each student has only one teacher for a subject. This relationship is described by cardinality.
It uses numbers or symbols near the connecting lines between entities to show the minimum and maximum number of relationships. For example, a "one-to-many" cardinality means one entity instance links to many instances of another entity, while "one-to-one" means each instance links to exactly one instance.
Example
This example shows cardinality between two entities: Author and Book. An author can write many books, but each book has exactly one author.
Entity: Author Entity: Book Relationship: Writes Cardinality: Author (1) --- (1..*) Book
When to Use
Use cardinality when designing databases to clearly define how entities relate to each other. It helps avoid confusion about data rules, like how many orders a customer can place or how many employees work in a department.
In real life, cardinality is useful for modeling systems such as school databases, online stores, or employee management, ensuring the database structure matches actual relationships.
Key Points
- Cardinality shows the number of possible relationships between entities.
- Common types are one-to-one, one-to-many, and many-to-many.
- It helps define database rules and constraints clearly.
- Cardinality is represented near relationship lines in ER diagrams.