Database Section (1) - 3CS
Database Section (1) - 3CS
Lab Content:
Introduction to database
- What is database
- Differences between database and files
- Entity-Relationships (ER) model
- Case Study for Students
What is database?
A database (DB) is a collection of a logically related persistent data, designed to meet the
information needs of an organization. Can be generated & maintained manually or automatically.
ENTITY
WEAK ENTITY
RELATIONSHIP
IDENTIFYING RELATIONSHIP
ATTRIBUTE
KEY ATTRIBUTE
MULTI-VALUED
COMPOSITE
DERIVED
(min,max)
PARTICIPATIO CONSTRAINTS
STUDENT COURSE
STAFF
Recursive Relationship
Recursive relationship is a relationship type where the same entity type participates more than
once in a different role. It is a unary relationship.
COURSE
require
Roles
Role indicates the purpose that each participating entity type plays in a relationship. (e.g.
prerequisite, requester)
COURSE
requester prerequisite
require
Role can be used when two entities are associated through more than one relationship to classify
the purpose of each relationship.
Attributes of Entities
STUDENT
Multi-valued attribute is an attribute that may hold multiple values, of the same type, for a
single entity.
initial
e.g. tel_no, degrees,… LName
FName
Area_cd
name DOB
no
St_no Tel_no
EX
STUDENT
Derived attribute is an attribute that represents a value that is derived from the value of a
related attribute,not necessarily in the same entity type.
name DOB
e.g. age is derived from date_of_birth
total_cost is derived from quantity*unit_price St_no
Tel_no
age
STUDENT
Keys
Candidate key(CK) is the minimal set of attributes that uniquely identifies an entity. It cannot
contain null.
e.g. student_no, social_security_no, branch_no…
Primary Key(PK) is a candidate key that is selected to uniquely identify each entity.
Alternate Key(AK) is a candidate key that is NOT selected to be the primary key.
Keys Example
Candidate Key
Keys
STUDENT
A key can be:
- simple key is a candidate key of one attribute.
e.g. student_no, branch_no…
- composite key is a candidate key that consists of two or more attributes.
CLASS
Cardinalities
Cardinality ratio expresses the number of relationships an entity can participate in.
Most useful in describing binary relationship types.
For a binary relationship type the mapping cardinality must be one of the following types:
– One to one (1:1) – One to many(1:M)
– Many to one (M:1) – Many to many (M:N)
One-To-One Relationship
PROFESSOR chair DEPARTMENT
P1 r1 D002
P2
P3 r2 D001
A professor chairs at most one department; and a department is chaired by only one professor.
One-To-Many Relationship
PROFESSOR teach COURSE
P1 r1 C01
r2 C02
P2 r3 C03
P3 C04
A course is taught by at most one professor; a professor teaches many courses.
Many-To-One Relationship
CLASS require ROOM
C1 r1 R001
C2 r2 R002
C3 r3 R003
R004
A class requires one room; while a room can be scheduled for many classes.
Multiplicity
Multiplicity is the number (range) of possible entities that may relate to a single association
through a particular relationship.
It is best determined using sample data.
Takes the form (min#, max#)
Participation Constraints
Participation constraints determine whether all or only some entities participate in a
relationship.
Two types of participation:
- Mandatory (total)
- Optional (partial)
• Optional (partial) (0:*): if an entity’s existence does not require a corresponding entity in
a particular relationship. (Not existence-dependent).
Minit
Number
Ssn
Bdate 1 1
Manages
1
Salary
Hours Controls
Supervisee
Supervisor
N M N
1 Supervision N
Works-on
Project
Dep_of
N Location
Name
Number
Dependent
Name
Gender Relationship
Birth-date