You are on page 1of 16

Database Systems

By
Syed Bakhtawar Shah Abid
Lecturer in Computer Science

1 Database Systems
Relationship

 Association between instances of entity types


– Degree of Relationship
 The Number of entity types that participates in the
relationship

Unary Relationship
– Binary Relationship
– Ternary Relationship
– Cardinality of Relationship
 The number of instances of one entity type that must be
associated with each instance of another entity type
– One-to-One Relationship
– One-to-Many Relationship
– Many-to-Many Relationship

2 Database Systems
Cardinality of Relationships

 One-to-One
– Each entity in the relationship will have exactly
one related entity
 One-to-Many
– An entity on one side of the relationship can have
many related entities, but an entity on the other
side will have a maximum of one related entity
 Many-to-Many
– Entities on both sides of the relationship can have
many related entities on the other side
3 Database Systems
Cardinality Constraints

 Cardinality Constraints - the number of


instances of one entity that can or must be
associated with each instance of another
entity
 Minimum Cardinality
– If zero, then optional
– If one or more, then mandatory
 Maximum Cardinality
– The maximum number
4 Database Systems
Mandatory cardinalities

A patient history is A patient must have recorded


recorded for one and at least one history, and can
only one patient have many
5 Database Systems
One optional, one mandatory

A project must be An employee can be assigned


assigned to at least one to any number of projects, or
employee, and may be may not be assigned to any
6 assigned to many at all Database Systems
Degree of Relationship

 Unary relationships

7 Database Systems
Degree of Relationship

Binary relationships

8 Database Systems
Degree of Relationship

Ternary relationship

9 Database Systems
Relationship

 Relationship type
– A meaningful relationship between entity types
 Relationship Instance
– A relationship between entity instances where each
relationship instance includes exactly only entity from each
participating entity type

 An entity–has attributes

 A relationship–links entities together


10 Database Systems
Relationship

 A relationship may also have attributes


 E.g.

11 Database Systems
Associative Entity

 An entity type that associates the instances


of one or more entity types and contains
attributes that are peculiar to the relationship
between those entity instances
 relationship with attributes instead can be
represented with an associative entity

12 Database Systems
Associative Entity

 When should a relationship with attributes instead be


an associative entity?
– All relationships for the associative entity should be many
– The associative entity could have meaning independent of
the other entities
– The associative entity preferably has a unique identifier, and
should also have other attributes
– The associative entity may participate in other relationships
other than the entities of the associated relationship
– Ternary relationships should be converted to associative
entities

13 Database Systems
A binary relationship with an attribute

• Here, the date completed attribute pertains specifically to the


employee’s completion of a course…it is an attribute of the
relationship

14 Database Systems
An associative entity (CERTIFICATE)

 Associative entity is like a relationship with an attribute, but it is also


considered to be an entity in its own..

 Note that the many-to-many cardinality between entities is replaced by


two one-to-many relationships with the associative entity.

15 Database Systems
Ternary relationship as an associative entity

16 Database Systems

You might also like