In terms of data models, cardinality refers to the relationship between two tables.
Relationship can be of four types
Here,
2. One-to-many:
3. Many to One
4. Many to Many:
For example,
Relationship can be of four types
- One-to-One Relationships
- One-to-Many Relationships
- May to One Relationships
- Many-to-Many Relationships
1. One-to-one:
One entity from entity set X can be associated with at most one entity of entity set Y and vice versa. A single row of first table associates with single row of second table.
For example,
Here,
- One student can enroll in at most one course.
- One course can be enrolled by at most one student.
2. One-to-many:
One entity from entity set X can be associated with multiple entities of entity set Y, but an entity from entity set Y can be associated with at least one entity. A single row of first table associates with more than one rows of second table.
For example,
Here,
- One student can enroll in any number (zero or more) of courses.
- One course can be enrolled by at most one student.
3. Many to One
More than one entity from entity set X can be associated with at most one entity of entity set Y. However, an entity from entity set Y may or may not be associated with more than one entity from entity set X. Many rows of first table associate with a single row of second table.
For example,
Here,
- One student can enroll in at most one course.
- One course can be enrolled by any number (zero or more) of students.
4. Many to Many:
One entity from X can be associated with more than one entity from Y and vice versa. Many rows of first table associate with many rows of second table.
For example,
Here,
- One student can enroll in any number (zero or more) of courses.
- One course can be enrolled by any number (zero or more) of students.
0 comments:
Post a Comment