DATABASE LECTURE01 Part2
DATABASE LECTURE01 Part2
has
Employee Dependent
1..1 0..*
Strong weak
Entity Entity
has
Customer Loan
1..1 0..*
Attributes
• Attributes describe the Property of an entity or a
relationship type.
• Attribute Domain
Set of allowable values for one or more attributes.
Types of Attributes
Simple Attribute
Attribute composed of a single component with an
independent existence. which cannot be divided
further. Ex: phone_number, SSN Passport number
Composite Attribute
Attribute composed of multiple components, each with
an independent existence.
Ex: name – first_name, middle_name, last_name
address – street, city, postcode
Types of Attributes
Single-valued Attribute
Attribute that holds a single value for each occurrence of an entity
type.
Ex: passport_number, driving_license_number
Multi-valued Attribute
Attribute that holds multiple values for each occurrence of an entity
type.
Ex: phone_number, email_address
Derived Attribute
Attribute that represents a value that is derivable from value of a
related attribute, or set of attributes, not necessarily in the same entity
type.
Ex: average_salary, age
Example of entities and attributes
Types of Keys in DBMS
What is a key in DBMS
std_id std_name course gpa email city
What is a key?
Candidate Key
A minimal super key. (If any proper subset of a super key is a super key,
then that cannot be a candidate key)
Ex: std_id
email
Types of Keys in DBMS
Primary Key
Almost every entity must have one!
A candidate key chosen to uniquely identify each row in a table.
Alternative Key
All the candidate keys which are not selected as PK call as alternative keys.
Types of Keys in DBMS
Foreign Key
Attribute in a table which is used to define it’s relationship with another table.
A key from another table maintain referential integrity for tables in
relationship
A referring attribute in an entity, pointing back to a primary key in another
(parent) table.
Student Course
E.g. a table representing library loans with attributes StudentID, BookID and
date.
StudentID on its own is not unique (as a student can borrow many bookss)…
…nor is BookID (as a book can be borrowed by many students at various times
But StudentID + BookID + Date will be unique – unless?
This is a composite primary key.
Compound key
If a composite key has at-least one attribute which is a FK then it is called a
compound key.
Ex: IITNo{PK}, courseId{FK}
Types of Keys in DBMS
Natural Key
A key that has some external meaning
Ex: ISBN book number, vehicle registration number etc.
Surrogated Key
Is supervised by
Employee
Recap - Cardinality constraints
• 1:1
this relationship constraint is sometimes removed
by merging the two connected entities
• 1:m
a common constraint which often models
referential integrity
• m:m
this relationship constraint is often simplied into two
relationships; 1 : m and m:1
• (minN, maxN) : (minM, maxM)
the most specific constraint, min and max may be numeric
but are often just 0, 1 or M.
One to One – optional.
has
Student 1..1 0..1
Laptop
has
Student 1..1 1..1
Student_ID
has registered
Student 1..* 1..*
Module
Normalization
logical model - model of the real world expressed in term
of entities, relationships and attributes, domains, primary
keys and foreign keys.
1..*
Lecturer
Course
Module
NIC {pk}
courseId {pk}
moduleId {pk} lecName
courseName
modName address
courseLeader
modLeader salary
hireDate
Student
stdId {pk}
stdName
payment
Answer Department
offers
deptId {pk}
deptName
1..1 location
1..*
Lecturer
Course Module
make up NIC {pk}
courseId {pk} moduleId {pk} lecName
courseName modName
courseLeader 1..* 1..* address
modLeader salary
hireDate
A number of modules make up each course.
Student
stdId {pk}
stdName
payment
Answer Department
offers
deptId {pk}
deptName
1..1 location
1..*
Lecturer
Course Module
make up NIC {pk}
courseId {pk} moduleId {pk} lecName
courseName 1.. modName
courseLeader 1..* address
* modLeader salary
hireDate
1..1 1..*
Students enroll in a particular course
take and take modules towards the
completion of that course.
0..*
Student
1..*
stdId {pk}
enroll in stdName
payment
Answer Department
offers employ
deptId {pk}
deptName
1..1 location
1..1
take
0..*
Student
0..* 0..*
stdId {pk}
enroll in stdName tutors
payment
char(max_size) and varchar(max_size)
char(10) – Fix length
Ex: NIC 1 2 3 4 5 6 7 8 9 V
Name O l i v i a
Wasting space
Ex: Name O l i v i a
C l e m e n t i n e