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:
- 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.
- 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.
- 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.
- 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.
Do the full course: SQL Course
Comments
Post a Comment