Database Notes
Database Notes
MANGOLA BRIAN
WHAT IS DATA, DATABASE, DBMS
Likezo
Male
Carol
DATABASE DESIGN …CONT’D
ER Diagram
Entity Relation
WHY USE ER DIAGRAMS?
•Helps you to define terms related to entity
relationship modeling
•Provide a preview of how all your tables should connect,
what fields are going to be on each table
•Helps to describe entities, attributes, relationships
•ER diagrams are translatable into relational tables
which allows you to build databases quickly
•ER diagrams can be used by database designers as a
blueprint for implementing data in specific software
applications
•The database designer gains a better understanding of the
information to be contained in the database with the help of
ER diagram
ER DIAGRAMS SYMBOLS & NOTATIONS
•Rectangle: Represents Entity sets.
Ellipses: Attributes
Diamonds: Relationship Set
Lines: They link attributes to Entity Sets and Entity
sets to Relationship Set
Double Ellipses: Multivalued Attributes
Dashed Ellipses: Derived Attributes
Double Rectangles: Weak Entity Sets
Double Lines: Total participation of an entity in a
relationship set
ER DIAGRAMS SYMBOLS & NOTATIONS
COMPONENTS OF A ER DIAGRAM
•ER diagram has three main
components:
1. Entity
2. Attribute
3. Relationship
1. ENTITY
•An entity is an object or component of data.
•An entity is represented as rectangle in an
ER diagram.
•Example: In the following ER diagram we have
two entities Student and College and these two
entities have many to one relationship as many
students study in a single college.
1. ENTITY …CONT’D
•Weak Entity:
An entity that cannot be uniquely identified by its
own attributes and relies on the relationship with
other entity is called weak entity.
•The weak entity is represented by a double
rectangle.
•Example – a bank account cannot be uniquely
identified without knowing the bank to which the
account belongs, so bank account is a weak entity.
2. ATTRIBUTE
•An attribute describes the property of an entity.
•An attribute is represented as Oval in an ER
diagram.
•There are four types of attributes:
1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute
2. ATTRIBUTE …CONT’D
•Key attribute:
•A key attribute can uniquely identify an entity
from an entity set.
•Example, student ID number can uniquely identify
a student from a set of students
•Key attribute is represented by oval same as
other attributes however the text of key
attribute is underlined as demonstrated on next
slide
2. ATTRIBUTE …CONT’D
Text of key
StudentID attribute is
underlined
2. ATTRIBUTE …CONT’D
•Composite attribute:
•An attribute that is a combination of other attributes. Example,
In student entity, the student District is a composite attribute as
an District is composed of other attributes such as district,
province, country.
Distric
t
Province
2. ATTRIBUTE …CONT’D
•Multivalued attribute:
•Hold multiple values
•It is represented with double ovals in an ER
Diagram
•Example – A person can have more than one
phone numbers, so the phone number attribute is
multivalued
E-R DIAGRAM WITH MULTIVALUED AND DERIVED
ATTRIBUTES
Multivalue Derived
attribute attribute
3. RELATIONSHIP
•A relationship is represented by diamond shape in
ER
diagram
•It shows the relationship among entities.
•There are four types of relationships:
1. One to One
2. One to Many
3. Many to One
4. Many to Many
3. RELATIONSHIP …CONT’D
•One to one relationship
•This is when a single instance of an entity is
associated with a single instance of another entity.
•Example, a person has only one passport and
a passport is given to one person.
3. RELATIONSHIP …CONT’D
•One to Many Relationship
•This is when a single instance of an entity is
associated with more than one instances of another.
•Example – a customer can place many orders but
an order cannot be placed by many customers.
3. RELATIONSHIP …CONT’D
•Many to One Relationship
•This is when more than one instances of an entity
is associated with a single instance of another
entity.
•Example – many students can study in a single
college but a student cannot study in many colleges
at the same time.
3. RELATIONSHIP …CONT’D
•Many to Many Relationship
•This is when more than one instances of an entity
is associated with more than one instances of
another
entity.
•Example, a student can be assigned to many
projects and a project can be assigned to many
students.
TOTAL PARTICIPATION OF AN ENTITY SET
•A Total participation of an entity set represents that
each entity in entity set must have at least one
relationship in a relationship set
•For example: In the below diagram each college
must have at-least one associated Student.
CARDINALITY AND MODALITY
CARDINALITY AND MODALITY …CONT’D
NORMALIZATION IN DBMS
•Normalization is a process of organizing the data
in
database to avoid data redundancy, insertion
anomaly, update anomaly & deletion anomaly.
NORMALIZATION IN DBMS …CONT’D
•Anomalies in DBMS
•There are three types of anomalies that occur when the
database is not normalized. These are – Insertion, update
and deletion anomaly.
•Example: Suppose a college stores the lecturer details in
a table named lecturers that has four attributes:
lecturer_id for storing lecturer’s id, lecturer_name for
storing lecturer’s name, lecturer_District for storing
lecturer’s District and lecturer_dept for storing the
department details in which the lecturer works.
NORMALIZATION IN DBMS …CONT’D
•At some point of time the table looks like this :
Table 1
lecturer_id lecturer_name lecturer_district lecturer_dept
101 Mabbola Choma EPS
101 Mabbola Choma MAT
123 Moomba Choma SCI
166 Mweemba Lusaka EPS
166 Moya Mazabuka LLE
• The above table is not normalized. We will see the problems
that we face when a table is not normalized.
•
NORMALIZATION IN DBMS …
Update anomaly: the ’above
InCONT D table we have two
rows for lecturer Mabbola as he belongs to two
departments
•If we want to update the District, then we have to
update the same in two rows otherwise the data will
become inconsistent.
•If somehow, the correct District gets updated in one
department but not in other, the he would be having
two different Districtes, which is not correct and
would lead to inconsistent data
•
NORMALIZATION IN DBMSSuppose
Insert anomaly: …CONT’Da new lecturer joins the
college, who is under training and currently not
assigned to any department then we would not be
able to insert the data into the table if lecturer_dept
field doesn’t allow nulls
•Delete anomaly: Suppose at some point the
college closes the SCI department then deleting
the rows that are having lecturer_dept as SCI would
also
delete the information of lecturer Moomba since he
is assigned only to this department
•
NORMALIZATION IN DBMS
To overcome these…anomalies
CONT’D we need to
normalize
the data
•Here are the most commonly used normal forms:
•First normal form(1NF)
•Second normal form(2NF)
•Third normal form(3NF)
•Boyce & Codd normal form (BCNF)
•
NORMALIZATION IN DBMS
First normal …CONT’D
form(1NF)
•The table below is not normalized because
some table cells have multiple values
Table 1
lecturer_name lecturer_district lecturer_dept
Mabbola Choma EPS, MAT
Moomba Monze SCI
Mweemba Lusaka EPS
Moya Mazabuka LLE
•First normalINform(1NF)
NORMALIZATION DBMS …CONT’D
•1NF (First Normal Form) rules are that
•Each table cell should contain a single/atomic value
•Entries in a column must be same.
•All the columns in a table should have unique names.
Table 1 lecturer_name lecturer_district lecturer_dept
Mabbola Choma EPS
Mabbola Choma MAT
Moomba Choma SCI
Mweemba Lusaka EPS
•Second normal
NORMALIZATION form…(2NF)
IN DBMS CONT’D
•A table is said to be in 2NF if both the following
conditions hold:
•Table is in 1NF (First normal form)
•The data in each row are dependent on each row's
primary key
•A primary key is one or more columns in a row that is
used to identify and index that row of the table.
•Columns that are not related to the primary key are
removed and only columns related to the primary key are
retained
•
NORMALIZATION IN DBMS
Second normal …CONT’D
form
(2NF) lecturer_id lecturer_name lecturer_district
Alternative Key
DBMS KEYS …CONT’D
• Foreign key
•Is a column that creates a relationship between two tables.
•The purpose of Foreign keys is to maintain data integrity and allow
navigation between two different instances of an entity.
•It acts as a cross-reference between two tables as it references the
primary key of another table.
DBMS KEYS …CONT’D
• Compound key
•Has two or more attributes that allow you to uniquely recognize a
specific record.
•It is possible that each column may not be unique by itself within the
database.
•However, when combined with the other column or columns the
combination of composite keys become unique.
•The purpose of the compound key in database is to uniquely identify
each record in the table.
ExamNo First Name LastName Email
202011 Tom Mudenda [email protected]
DBMS KEYS …CONT’D
• Composite key
•A combination of two or more columns that uniquely identify rows
in a table.
•The combination of columns guarantees uniqueness, though
individually uniqueness is not guaranteed.
•Hence, they are combined to uniquely identify records in a table.
•The difference between compound and the composite key is that
any part of the compound key can be a foreign key, but the
composite key may or maybe not a part of the foreign key.
DBMS KEYS …CONT’D
• Surrogate key
•An artificial key which aims to uniquely identify each record.
•This kind of partial key in DBMS is unique because it is created when
you don't have any natural primary key.
•They do not lend any meaning to the data in the table.
•Surrogate key is usually an integer.
•A surrogate key is a value generated right before the record is
inserted into a table.
MICROSOFT ACCESS
•Microsoft Access is a Database Management System offered by
Microsoft.
•It uses the Microsoft Jet Database Engine and comes as a part of
the Microsoft Office suite of application.
•Microsoft Access offers the functionality of a database and the
programming capabilities to create easy to navigate screens
(forms).
•It helps analyze large amounts of information, and manage
data efficiently.
MICROSOFT ACCESS …CONT’D
Access Excel
Deals with text, numbers, files and all Microsoft Excel generally deals with
kinds of data numerical data
All the data is stored one time, in one Lots of worksheets or documents are
place. a store with similar, repeated data.
Helps you to build highly functional Only the primary data entry screen is
data entry forms and report available.
templates.
Users will be able to enter the data Data accuracy and speed is not much
more efficiently and accurately. because of the format.
ADVANTAGES OF MS ACCESS
•Access offers a fully functional, relational database management system in
minutes.
•Easy to import data from multiple sources into Access
•You can easily customize Access according to personal and company needs
•It is robust and flexible, and it can perform any challenging office or
industrial database tasks.
•Can link to data in its existing location and use it for viewing, updating,
querying, and reporting.
•Allows you to create tables, queries, forms, and reports, and connect with
the help of Macros
•Can use macros to add functionality to your database.
DISADVANTAGES OF MS ACCESS
•Useful for small-to-medium business sectors. Not useful
for large-sized organizations
•Lacks robustness compared to other DBMS systems like
MS SQL Server or Oracle
•All the information from the database is saved into one
file. This can slow down reports, queries, and forms
•Technical limit is 255 concurrent users. However, the real-
world limit is only 10 to 80 (depending on the type of
application which you are using)
CREATE A DATABASE IN ACCESS
•Reference sites for creation of MS Access database
•tutorialspoint.com/ms_access/ms_access_create_database.htm
•www.youtube.com/watch?v=eXiCza050ug&list=PLpQQipWcxwt-
EHfE5zXtUrLtFYnOPBRE_
•And otherYouTube videos
E
N
D
T
H
A
N
K
Y
O
U