Database Systems Instructor Name: Lecture-10
Contents Participation Constraints Mandatory and Optional Cardinalities Modeling Time Dependent Data Multiple Relationships Keys 2
Participation Constraint It defines whether the existence of an entity depends on its being related to another entity via relationship type. This is also alternative way to define minimum cardinality constraint and its implications (optional, mandatory) 3
Participation Constraint Types Total Participation Partial Participation 4
Case I – Total Participation If company policy states that Every Employee Must work for a department, Then Employee Entity Only Exist if it participate in at least ONE work-for relationship It is total participation as Every Entity Instance in the EMPLOYEE entity type must be related to a department via work-for relationship Total Participation is also called Existence Dependency 5
Case II – Partial Participation We do not expect every employee to manage a department, so the participation of employee in manage relationship is Partial Some or part of employees from employee set are related to some departments; and not all employees. 6
Maximum Cardinality Maximum Number of One Entity that may be associated with each instance of another Entity Crow’s Foot 7
Crow’s Foot - Notations 8
Relationships and Cardinalities – Mandatory Cardinality - Example 9
Relationships and Cardinalities –Optional Cardinality - Example 10
Cardinality Constraints on Ternary Relationship 11
Multiple Relationship In some situations an organisation may want to model more than one relationship between the same entity types The following figure shows two relationships between PROFESSOR and COURSE The relationship Is_Qualified associates professors with the courses they are qualified to teach A given course may have more than one person qualified to teach it, or (optionally) may not have any qualified instructors (such as a new course) Each professor should be qualified to teach at least one course (we hope!) 12
Multiple Relationship – Contd. The second relationship in this figure associates professors with the courses they actually teach during a given semester (where the maximum cardinality for a given semester is 4) This shows how a fixed constraint (upper or lower) can be recorded The attribute ‘Semester’ (which could be a composite attribute with components ‘Semester_Name’ and ‘Year’) is on the relationship Is_Scheduled) 13
Multiple Relationship – Contd. The second relationship in this figure associates professors with the courses they actually teach during a given semester (where the maximum cardinality for a given semester is 4) This shows how a fixed constraint (upper or lower) can be recorded The attribute ‘Semester’ (which could be a composite attribute with components ‘Semester_Name’ and ‘Year’) is on the relationship Is_Scheduled) 14
Multiple Relationship – Example 15
Multiple Relationship – Example 16
Keys Primary Key: An attribute or combination of attribute that uniquely identifies each row in a relation Composite Key: A primary key that consists of more than one attributes Foreign Key: An attribute in a relation that serves as primary key of another relation in the same database 17
Resolve Multivalued, Composite and Many-to-Many Relationship Keys – Contd. Resolve Multivalued, Composite and Many-to-Many Relationship 18
Primary Key and Foreign Key Notations 19
Table with Constraints CREATE TABLE Show ( show_id NUMBER NOT NULL, category_id NUMBER NOT NULL, act_id NUMBER NOT NULL, venue_id NUMBER NOT NULL, showdate DATE NULL, CONSTRAINT XPKShow PRIMARY KEY (show_id), CONSTRAINT FKShow_Cat FOREIGN KEY (category_id) REFERENCES Category, CONSTRAINT FKShow_Venue FOREIGN KEY (venue_id) REFERENCES Venue, CONSTRAINT FKShow_Act FOREIGN KEY (act_id) REFERENCES Act ); 20
???????????????? 21
Erroneous Relationship Receives or summarize the data, transfer, translate or calculate data 22