Recent from talks
Nothing was collected or created yet.
Cardinality (data modeling)
View on WikipediaWithin data modelling, cardinality is the numerical relationship between rows of one table and rows in another. Common cardinalities include one-to-one, one-to-many, and many-to-many. Cardinality can be used to define data models as well as analyze entities within datasets.
Relationships
[edit]For example, consider a database of electronic health records. Such a database could contain tables like the following:
- A
doctortable with information about physicians. - A
patienttable for medical subjects undergoing treatment. - An
appointmenttable with an entry for each hospital visit.
Natural relationships exist between these entities:
- A many-to-many relationship between records in
doctorand records inpatientbecause doctors have many patients and patients can see many doctors. - A one-to-many relationship between records in
patientand records inappointmentbecause patients can have many appointments and each appointment involves only one patient.[1] - A one-to-one relationship is mostly used to split a table in two in order to provide information concisely and make it more understandable. In the hospital example, such a relationship could be used to keep apart doctors' own unique professional information from administrative details.[citation needed]
Modeling
[edit]In data modeling, collections of data elements are grouped into "data tables" which contain groups of data field names called "database attributes". Tables are linked by "key fields". A "primary key" assigns a field to its "special order table". For example, the "Doctor Last Name" field might be assigned as a primary key of the Doctor table with all people having same last name organized alphabetically according to the first three letters of their first name. A table can also have a foreign key which indicates that field is linked to the primary key of another table.[2]
Types of models
[edit]A complex data model can involve hundreds of related tables. Computer scientist Edgar F. Codd created a systematic method to decompose and organize relational databases.[3] Codd's steps for organizing database tables and their keys is called database normalization, which avoids certain hidden database design errors (delete anomalies or update anomalies). In real life the process of database normalization ends up breaking tables into a larger number of smaller tables.[3]

In the real world, data modeling is critical because as the data grows voluminous, tables linked by keys must be used to speed up programmed retrieval of data. If a data model is poorly crafted, even a computer applications system with just a million records will give the end-users unacceptable response time delays. For this reason, data modeling is a keystone in the skills needed by a modern software developer.[citation needed]
Database modeling techniques
[edit]The entity–relationship model proposes a technique that produces entity–relationship diagrams (ERDs), which can be employed to capture information about data model entity types, relationships and cardinality. A Crow's foot shows a one-to-many relationship. Alternatively a single line represents a one-to-one relationship.[4]
Application program modeling approaches
[edit]In the object-oriented application programming paradigm, which is related to database structure design, UML class diagrams may be used for object modeling. In that case, object relationships are modeled using UML associations, and multiplicity is used on those associations to denote cardinality. Here are some examples:[5]
| Relationship | Example | Left | Right | Narrative |
|---|---|---|---|---|
| One-to-one | person ↔ birth certificate | 1 | 1 | A person must have their own birth certificate, it is specific to that person by its Id number. |
| One-to-one (optional on one side) |
person ↔ driving license | 1 | 0..1 or ? | A person may have a driving license, it is specific to that person by its Id number. |
| One-to-many | order ↔ line item | 1 | 1..* or + | An order contains at least one item |
| Many-to-one | person ↔ birthplace | 1..* or + | 1 | Many people can be born in the same place, but 1 person can only be born in 1 birthplace |
| Many-to-many | course ↔ student | 1..* or + | 1..* or + | Students follow various courses |
| Many-to-many (optional on both sides) |
person ↔ book | 0..* or * | 0..* or * | A person may own many books(copies), and a book may be owned by many people(readers). |
See also
[edit]References
[edit]- ^ Clarke, Alex; Hasnani, Aleen; Al-Ahasan, Abdullah; Islam, Nazmul (7 September 2022). "Data Modeling and Entity Relationship Diagram (ERD)". University of Regina - Computer Science Department.
- ^ "Entity Relationship Mapping". Oracle Corporation. Retrieved 1 August 2002.
- ^ a b Codd, E. F. (1990). The relational model for database management : version 2. Reading, Mass.: Addison-Wesley. ISBN 0-201-14192-2. OCLC 19590880.
- ^ "Crow's Foot Notation". University of Regina.
- ^ "Cardinality". datacadamia. 7 September 2022.
External links
[edit]- UML multiplicity as data model cardinality - http://www.agiledata.org
- Cardinality in Data Modeling - Adam Alalouf, Temple University
- Cardinality on Techopedia
- Cardinality on Geeksforgeeks
- Database Cardinality on SQL World
Cardinality (data modeling)
View on GrokipediaFundamentals
Definition
In data modeling, entities and relationships serve as the fundamental building blocks for representing real-world concepts in a structured manner. An entity represents a distinguishable object or thing, such as a person, place, or event, about which data is collected, while a relationship defines the associations between these entities, capturing how they interact or connect in the modeled domain. Cardinality specifies the minimum and maximum number of instances of one entity set that may or must associate with instances of another entity set through a given relationship, thereby defining the constraints on permissible mappings between them.[5] This concept distinguishes between possible participation levels, such as whether an entity instance relates to exactly one or multiple others, providing constraints on how data elements interconnect.[2] The term cardinality in this context originated with the entity-relationship (ER) modeling approach introduced by Peter Chen in his seminal 1976 paper, where it was used to describe the numerical structure of relationship sets between entity sets.[5] Cardinality is crucial for maintaining data integrity by enforcing consistent associations that prevent invalid or orphaned records, while also enhancing query efficiency through optimized indexing and join strategies in subsequent database implementations; it forms a foundational element in relational algebra and schema design by guiding the translation of conceptual models into physical structures.[6][7]Basic Types
In data modeling, particularly within the entity-relationship (ER) model, cardinality constraints define the permissible associations between entity instances, categorized into four primary types based on the maximum number of related instances: one-to-one (1:1), one-to-many (1:N), many-to-one (N:1), and many-to-many (N:M). These classifications, introduced in the foundational ER model, specify the structural constraints on relationships to ensure data integrity and semantic accuracy.[8][9] A one-to-one (1:1) cardinality exists when each instance of entity A can be associated with at most one instance of entity B, and conversely, each instance of B with at most one of A. This type is commonly applied in scenarios requiring attribute partitioning, such as separating sensitive personal data into a secure entity, or in modeling inheritance where a subclass entity relates uniquely to its superclass. For example, a person and their passport might form a 1:1 relationship, as each person holds at most one valid passport at a time.[8][9] A one-to-many (1:N) cardinality allows a single instance of entity A to associate with zero or more instances of entity B, while each instance of B associates with at most one instance of A. This structure is prevalent in hierarchical data representations, such as parent-child relationships in organizational models. A classic example is the association between a department and its employees, where one department can have multiple employees, but each employee is assigned to only one department.[8][9] The many-to-one (N:1) cardinality is the inverse perspective of the one-to-many type, emphasizing the side where multiple instances of entity A (the "many") connect to a single instance of entity B (the "one"). It highlights constraints from the viewpoint of the dependent entities, such as employees (many) reporting to a single manager (one), without altering the underlying relational semantics. This notation aids in clarifying directionality in asymmetric relationships.[8][9] A many-to-many (N:M) cardinality permits multiple instances of entity A to associate with multiple instances of entity B, and vice versa, accommodating complex interconnections that cannot be directly implemented in relational schemas without decomposition. To resolve this in practice, an associative entity (or junction entity) is introduced to break the relationship into two one-to-many associations, often incorporating additional attributes about the linkage. For instance, the relationship between students and courses typically follows an N:M pattern, as multiple students can enroll in multiple courses, resolved via an enrollment entity tracking grades or dates.[8][9]Relationships
Unary and Binary
In data modeling, binary relationships represent associations between two distinct entity sets, which is the most prevalent form of relationship in entity-relationship (ER) models.[5] These relationships specify cardinality constraints pairwise, indicating the maximum number of instances from one entity set that can relate to instances in the other; common types include one-to-one (1:1), one-to-many (1:N), and many-to-many (N:M).[5] For instance, in a supply chain model, a supplier entity set might have a 1:N relationship with a product entity set, where each supplier provides one or more products, but each product is supplied by exactly one supplier.[10] This pairwise specification ensures that the structural constraints of the relationship are clearly defined for database implementation. Unary relationships, also known as recursive relationships, occur when a single entity set relates to itself, often modeling hierarchical or self-referential structures within the same domain.[5] Like binary relationships, unary ones can exhibit various cardinalities, such as 1:N or N:M, depending on the business rules.[10] A classic 1:N example is an employee-supervisor hierarchy, where each employee (except the top level) reports to exactly one supervisor, but a supervisor can manage multiple employees.[10] In contrast, an N:M unary relationship might model a bill of materials for parts, where a part can be composed of multiple subparts, and a subpart can be used in multiple parent parts.[2] Participation constraints further refine cardinality by distinguishing between total and partial involvement of entity instances in a relationship, applicable to both unary and binary cases. Total participation requires that every instance of the entity set must participate in the relationship, ensuring no isolated entities; for example, in a mandatory employee-supervisor unary relationship, every employee must have a supervisor.[10] Partial participation, however, allows some instances to remain unassociated, providing flexibility for optional links.[10] To express these constraints more precisely, the min-max notation uses pairs (min, max) attached to each entity's participation in the relationship, where min indicates the minimum required associations (often 0 for partial or 1 for total) and max denotes the upper limit (e.g., 1 or N for unbounded). In a binary supplier-product relationship, the supplier side might be denoted as (0, N) for partial participation allowing suppliers without products, while the product side could be (1, 1) for total participation requiring each product to have exactly one supplier. For the unary employee-supervisor example, the subordinate role might use (0, 1) to allow top-level employees without supervisors while ensuring at most one, with the supervisor role as (0, N) to permit supervisors without subordinates.[10] This notation integrates both cardinality ratios and participation rules, facilitating accurate translation to relational schemas.Participation Constraints
Participation constraints govern the degree to which entity instances must engage in relationships within data models, specifically delineating mandatory (total) versus optional (partial) involvement to reflect real-world dependencies accurately. In the entity-relationship (ER) model, these constraints ensure that the structural semantics of associations are preserved, preventing invalid states during data manipulation. Total participation requires that every instance of an entity type connects to at least one instance of the relationship, while partial participation permits some instances to remain unconnected.[11] Mandatory participation, also known as total participation, mandates that each entity instance fully engages in the relationship for its existence to be valid. For example, in modeling an organizational structure, every employee must belong to a department via the "employs" relationship, as an employee cannot exist without departmental affiliation; this corresponds to a minimum cardinality of 1 on the employee side. Such constraints are integral to binary relationships, where they specify the obligatory nature of one entity's role relative to another.[11] In contrast, optional participation, or partial participation, allows entity instances to exist independently without requiring involvement in the relationship. Continuing the example, a newly formed department may initially have no employees, permitting a minimum cardinality of 0 on the department side while still allowing future associations. This flexibility accommodates scenarios where entities can stand alone until conditions for relating them are met.[11] Mandatory participation frequently implies an existence dependency, wherein the survival of a dependent entity hinges on its association with a parent entity, thereby shaping referential integrity requirements in the model. For instance, deleting a department would necessitate handling linked employees to avoid inconsistencies. In database implementations, these conceptual constraints translate to enforcement mechanisms like foreign key declarations with NOT NULL attributes, which prevent the insertion of orphaned records and uphold referential integrity by ensuring all referenced entities exist and are properly linked.[5][12]Modeling Techniques
Entity-Relationship Diagrams
Entity-relationship diagrams (ERDs) serve as a graphical tool for developing conceptual schemas in data modeling, representing entities as rectangles and relationships as diamonds connected by lines. This notation, introduced by Peter Chen in 1976, facilitates the visualization of data structures at a high level, independent of any specific database management system, enabling designers to capture the semantics of real-world scenarios before implementation.[5] Cardinality in ERDs is denoted through various conventions to specify the number of entity instances participating in relationships. In Chen's original notation, symbols such as "1," "N," or "M" are placed near the connecting lines to indicate the maximum cardinality for each participating entity set, with participation constraints shown via single (partial) or double (total) lines on the connecting lines.[5] An extension known as min-max notation, proposed by Jean-Raymond Abrial in 1974, refines this by placing ordered pairs like (0,N) or (1,1) directly on the relationship edges to explicitly denote both minimum and maximum cardinalities, addressing limitations in expressing optional or partial participations more precisely.[13] A popular variant, Crow's Foot notation, originated in Gordon C. Everest's 1976 paper and uses intuitive line-end symbols on relationship connectors: a crow's foot (three prongs) for "many," a circle for zero or optional participation, and a bar for one or mandatory participation, making cardinality constraints visually distinct without textual labels.[14] For instance, this notation commonly visualizes a one-to-many (1:N) relationship with a bar on the "one" side and a crow's foot on the "many" side. ERDs offer significant advantages in conceptual modeling by aiding early identification of design flaws through visual inspection and supporting iterative refinement as requirements evolve, which enhances overall schema quality and reduces downstream implementation errors.[15]Unified Modeling Language
In the Unified Modeling Language (UML), cardinality is primarily represented in class diagrams, which model the static structure of object-oriented systems. Classes are depicted as rectangular boxes divided into compartments for the class name (top, bolded), attributes (middle), and operations (bottom), allowing for a comprehensive view of both data and behavior. Associations between classes are shown as solid lines connecting these boxes, with multiplicity indicators placed at each end of the line to specify the allowable number of instances participating in the relationship. This notation enables precise modeling of how objects interact, emphasizing navigability through optional arrowheads that indicate directionality—such as an open arrow for one-way navigation from source to target, or a cross ("x") to denote non-navigability.[16] Multiplicity in UML uses a range-based syntax to denote cardinality, expressed as [lower..upper] where lower is the minimum number of instances and upper is the maximum (unbounded by default with ""). Common notations include: 1 for exactly one instance, 0..1 for zero or one (optional), * or 0.. for zero or more, and 1..* for one or more. These can be adorned with stereotypes like {ordered} or {unique} to further constrain the collection of instances. For example, in a diagram modeling a library system, an association between "Book" and "Author" might show multiplicity 1 on the Book side (each book has exactly one author) and 0..* on the Author side (an author can write zero or more books). This syntax ensures that the diagram enforces constraints on object instantiation and linkage during design and implementation.[16] For many-to-many (N:M) relationships, UML employs association classes, which are classes attached to an association via a dashed line, allowing attributes or operations to be added directly to the relationship itself. This transforms a simple line into a reified entity, such as an "Enrollment" association class between "Student" and "Course" classes, where attributes like enrollment date can be modeled on the link rather than on the participating classes. Unlike purely structural approaches, UML's integration of association classes supports behavioral aspects, such as methods for managing the relationship.[16] UML class diagrams extend beyond database-centric notations like entity-relationship diagrams by incorporating behavioral elements (e.g., operations and state transitions) and inheritance hierarchies (e.g., generalization arrows), providing a more holistic view for software engineering while retaining foundational concepts of structural modeling.[16]| Multiplicity Syntax | Description | Example Usage |
|---|---|---|
| 1 | Exactly one instance | Each department has one manager |
| 0..1 | Zero or one instance | A project may have an optional sponsor |
| or 0..* | Zero or more instances | A user can have multiple addresses |
| 1..* | One or more instances | Each order requires at least one item |
