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.
Lab (1) 1
Database Systems (DBS)
DBS is a single large repository of data, defined once and managed using DBMS while used by
many application programs.
Lab (1) 2
ERD notations
ENTITY
WEAK ENTITY
RELATIONSHIP
IDENTIFYING RELATIONSHIP
ATTRIBUTE
KEY ATTRIBUTE
MULTI-VALUED
COMPOSITE
DERIVED
Lab (1) 3
1 M
CARDINALITY RATIO
(min,max)
PARTICIPATIO CONSTRAINTS
STUDENT COURSE
Lab (1) 4
A relationship of degree three (3 entity types) are ternary.
e.g. registration of a student in a course by a staff.
STAF
F
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.
Lab (1) 5
Attributes
Attributes are descriptive properties for an entity type or a relationship type.
All entities in one entity type have the same attributes.
Attributes of Entities
STUDENT
Lab (1) 6
Single-valued & Multi-valued Attributes
Single-valued attribute is an attribute that holds a single value for a single entity. It is not
necessarily a simple attribute.
e.g. student_no, age, gender,...
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,… FName
LName
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
Lab (1) 7
Choice of PK
Choice of Primary Key (PK) is based on:
• Attribute length
• Number of attributes required
• Certainty of uniqueness
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
Lab (1) 8
LName FName
dep_no FName
emp_no DOB
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.
Lab (1) 9
Many-To-Many Relationship
CLASS enroll STUDENT
C1 r1 S1
C2 r2 S3
C3 r3 S4
r5 S5
A class enrolls many students; and each student is enrolled in 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).
Lab (1) 10
Case Study for Students Company:
Ssn
Start-date No.of-Emp Department
Employee
Bdate 1 1
Manages
Salary 1
Hours Controls
Supervisee
Supervisor
N
1 M N
Supervision N
Works-on
Project
Dep_of
N Location
Name
Number
Dependent
Name
Gender Relationship
Birth-date
Lab (1) 12