DB Fundamentals Lecture #

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

09/11/2020 Badakhshan University Faculty of Computer 1

Science
Islamic Republic of Afghanistan
Ministry of Higher Education
Badakhshan University
Computer Science Faculty

JAVA PROGRAMMING

Lecturer: Mohammad Qias (Mohammadi)

09/11/2020 Badakhshan University Faculty of Computer 2


Science
Lecture #7
Relationship Types
Unary
Binary
Ternary

Ternary Relationship

09/11/2020 Badakhshan University Faculty of Computer 3


Science
3. Ternary Relationship :
Ternary Relationship is a type of relationship which is established
between the instance of three entity types
Contract

The above relationship means that one or many manager with one
or many clients sign contract in one or many projects

09/11/2020 Badakhshan University Faculty of Computer 4


Science
Example of Ternary Relationship:

Works on

Badakhshan University Faculty of Computer


Science

The above relationship means that one or many analyst with one or many
programmers works on one or many projects

09/11/2020 5
Cardinality constraints
 Cardinality constraints specifies the number of instance of one
entity that can (or must) be associated with each instance of
another entity.
 There are three types of symbols used to show cardinality
 1. circle : It means that the minimum number of relationship
between each instance of first entity and instance of second
entity is zero. It is also called the optional relationship

09/11/2020 Badakhshan University Faculty of Computer 6


Science
Cardinality constraints ……
2. line : it means that the minimum number of relationship between each
instance of first entity and instance of second entity is one. It is also
called mandatory relationship

3. Crows-foot : it means that many relationships between instance of the


first entity and instance of second entity

09/11/2020 Badakhshan University Faculty of Computer 7


Science
Continue…
Optional Relationship :
It means that the minimum number of relationship between each
instance of first entity type and instance of second entity is zero.
It is called optional relationship.
Mandatory Relationship :
It means that the minimum number of relationship between each
instance of first entity type and instance of second entity type is
one.
It is called mandatory relationship

09/11/2020 Badakhshan University Faculty of Computer 8


Science
Examples

09/11/2020 Badakhshan University Faculty of Computer 9


Science
Example : One-to-Many Relationship(Optional)

STUDENT BOOK

The shape with STUDENT show that minimum cardinality of


STUDENT is zero and maximum is one. The shape with
BOOK shows that minimum cardinality is zero and maximum
cardinality is many
It means that one student can get zero or many books and one book
can get by one or no student

09/11/2020 Badakhshan University Faculty of Computer 10


Science
Example : Many-to-One Relationship(Mandatory)

EMPLOYEE PROJECT

In the employee section the minimum cardinality is one and maximum is


many, and in the project section the minimum and maximum cardinality is
one
It means, that one or many employee may be working on one project, but
one employ must work on exactly one project

09/11/2020 Badakhshan University Faculty of Computer 11


Science
Example : Many-to-Many Relationship(Optional)

The minimum cardinality on both side is zero and the maximum cardinality
on both side is many
It means, that one student can take many or no course to study, similarly one
course can be taken by many students or no students.

09/11/2020 Badakhshan University Faculty of Computer 12


Science
Notation Guide

• Entity Type

• Weak Entity Type

• Relationship Type

• Associative Entity

09/11/2020 Badakhshan University Faculty of Computer 13


Science
Notation Guide…
• Attribute

_____
• Key Attribute

• Multi value Attribute

• Derived Attribute

• Composite Attribute

09/11/2020 Badakhshan University Faculty of Computer 14


Science
Keys
A key is an attribute or set of attributes that uniquely identify a row in a
relation.
The key are defined in table to access or sequence the stored data quickly.
They are also used to create relationship between different tables
1.Super key
2.Candidate key
3.Primary key
4.Alternate key
5.Composite key
6.Foreign key

09/11/2020 Badakhshan University Faculty of Computer 15


Science
1.Super key :
Super key is an attribute or combination of attributes in a relation that
identifies a row uniquely within relation.
Any combination of attributes with the super key is also a super key. It
means any attribute or set of attributes combined with super key is also
become a super key.
A STUDENT entity with different attributes such us :
RegID, Name, Father Name, Class, Address, etc
RegID : super key
{RegID, Name} : super key
{RegID, Class} : super key

09/11/2020 Badakhshan University Faculty of Computer 16


Science
2. Candidate Key :
Candidate key is a super key that contains no extra attribute.
A super key with single attribute which uniquely identify a row in relation
is as well as candidate key.
A STUDENT entity with different attributes such us :
RegID, Name, Father Name, Class, Address
{RegID} : Super key and candidate key
{RegID, Class} : Super key but not candidate key because it contains
an extra field of Class.

09/11/2020 Badakhshan University Faculty of Computer 17


Science
3. Primary Key :
Primary key is a candidate key that is selected by the database designer to
identify a row uniquely in a relation or table.
A relation may contain many candidate keys, when the designer selects one
of them to identify a row in the relation, it become a primary key.
Some important points about primary key :
1. A relation can have only one primary key.
2. Each value in primary key attribute must be unique.
3. primary key cannot contain null values.

09/11/2020 Badakhshan University Faculty of Computer 18


Science
4. Alternate Key :
The candidate keys that are not selected as primary key are known as
alternate key.
Suppose student relation contain different attributes such us :
RegNo, RollNo, Name, Class, Address etc. the attributes of RegNo and
RollNo can be used to uniquely identify each student in table.
In this situation the designer select one of them as primary key which is
most important to organization.

09/11/2020 Badakhshan University Faculty of Computer 19


Science
5. Composite Key :
A primary key that consist of two or more attributes is known as composite
key.
Sometimes its required to select composite primary key to identify a row
uniquely in relation.
for example : each student must pay their fee only once in per months. In
this situation we must select composite primary key to solve this problems.
We select the student ID and months us composite primary key.

09/11/2020 Badakhshan University Faculty of Computer 20


Science
6. Foreign Key :
Foreign key is an attribute or set of attributes in a relation whose values
match a primary key in another relation.
The relation in which foreign key is created is known as dependent or child
Table
The relation to which the foreign key refers is known as parent Table.
A relation is also contain many foreign keys.

09/11/2020 Badakhshan University Faculty of Computer 21


Science
Example of foreign key

09/11/2020 Badakhshan University Faculty of Computer 22


Science
Any Questions & Suggestions

Email: mqm.dacaar@gmail.com
Phone: +0789152242

09/11/2020 Badakhshan University Faculty of Computer 23


Science

You might also like