cardinality and participation constraints
TRANSCRIPT
![Page 1: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/1.jpg)
Cardinality & Participation
Constraint in DBMS
![Page 2: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/2.jpg)
Constraints
Relationship types usually have certain constraints that limit the possible combinations of entities that may participate in the corresponding relationship set.
![Page 3: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/3.jpg)
Constraints ?
![Page 4: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/4.jpg)
Why to use Constraints ?• To limit the type of data that can go into a table• To maintain the accuracy and integrity of the data inside table.
Most used constraints:• NOT NULL• UNIQUE• PRIMARY KEY• FOREIGN KEY• CHECK• DEFAULT
![Page 5: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/5.jpg)
Type of Constraints
We can distinguish two main types of relationship constraints:•Cardinality constraints•Participation constraints
![Page 6: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/6.jpg)
Employee DepartmentWork for
Entity Relationship typeEntity
Every relation in relationship type is an association between employee and department
![Page 7: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/7.jpg)
Requirement Analysis:• Every employee work for one department•An department can have many employees•New department need not have employee
Degree:In every relationship how many entities are participating.
![Page 8: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/8.jpg)
E1E2E3E4E5E6
D1D2D3
123456
employeeWork for Department
Degree-2(binary)
![Page 9: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/9.jpg)
Work For
Work For
EmployeeDepartment
Employee Department
1N
(1,1) (0,N)
Min/Max Representation
ER diagram
More info could be represented using MIN/Max Method
![Page 10: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/10.jpg)
E1E2E3E4
1234
D1D2D3D4
Employee Manager Department
Degree-2(binary)
Every Department should have a manager & only one employee manages a department.
An Employee can manage only one department.
Requirement Analysis:
![Page 11: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/11.jpg)
Cardinality
My Cardinal Is Bigger Than Yours
![Page 12: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/12.jpg)
Cardinality
The term cardinality actually has two different meanings depending on the context of it’s usage – one meaning is in the context of Data modeling and the other meaning is in the context of SQL statements.
![Page 13: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/13.jpg)
Relationship one table can have with another table
![Page 14: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/14.jpg)
In The Context Of Data Modeling
It simply refers to the relationship that one table can have with another table. These relationships include: many-to-many, many-to-one/one-to-many, or one-to-one – whichever one of these characteristics a table has in relationship with another table is said to be the cardinality of that table.
![Page 15: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/15.jpg)
![Page 16: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/16.jpg)
Example:Suppose we have three tables that are used by a company to store employee information: an Employee table, an Employee_Salary table, and a Department table.The Department table will have a one to many relationship with the Employee table, because every employee can belong to only one department, but a department can consist of many employees.In other words, the cardinality of the Department table in relationship to the employee table is one to many. The cardinality of the Employee table in relationship to the Employee_Salary table will be one to one, since an employee can only have one salary, and vice versa.
![Page 17: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/17.jpg)
There are three degrees of Cardinality, known as:• One-to-One (1:1):One occurrence of an entity relates to only one occurrence in
another entity.
• One-to-Many (1:M): One occurrence in an entity relates to many occurrences in another entity.
• Many-to-Many (M:N) Many occurrences in an entity relate to many occurrences in another entity.
![Page 18: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/18.jpg)
Cardinality in SQL
Uniqueness of data
![Page 19: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/19.jpg)
Cardinality in SQLCardinality refers to the uniqueness of data contained in a column.If a column has a lot of duplicate data (e.g. a column that stores either "true" or "false"), it has low cardinality,but if the values are highly unique (e.g. Social Security numbers), it has high cardinality.
![Page 20: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/20.jpg)
For example, let’s say we have a table with a “Gender” column which has only two possible values of “Male” and “Female”. Then, that “Gender” column would have a cardinality of 2, because there are only two unique values that could possibly appear in that column .
![Page 21: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/21.jpg)
Let’s say that we have a primary key column on a table with 10,000 rows. What do you think the cardinality of that column would be?
Primary key: It is a key in a relational database that is unique for each record.
![Page 22: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/22.jpg)
It is 10,000.Because it is a primary key column, we know that all of the values in the column must be unique.
Cardinality of a primary key column will always be equal to the number of records in the same table.
![Page 23: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/23.jpg)
Participation Constraint
![Page 24: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/24.jpg)
Participation Constraint
There are two types of participation constraints—total and partial.The participation of an entity set E in a relationship set R is said to be total if every entity in E participates in at least one relationship in R. If only some entities in E participate in relationships in R, the participation of entity set E in relationship R is said to be partial.
![Page 25: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/25.jpg)
ER model
Double line indicates the total participation constraint in an ER model.
Single line indicates the partial participation constraint in an ER model.
![Page 26: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/26.jpg)
Cardinality Constraints : At most
Participation Constraints : At least or Minimum
![Page 27: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/27.jpg)
ConstraintsCardinality Participation
Data modeling
SQL statements
One-to-One
One-to-Many
Many-to-Many
low cardinality
high cardinality
TotalPartial
![Page 28: Cardinality and participation constraints](https://reader033.vdocuments.mx/reader033/viewer/2022061517/586fa54e1a28abcc238b7e57/html5/thumbnails/28.jpg)