0% found this document useful (0 votes)
8 views

Database Notes

The document provides an overview of data, databases, and Database Management Systems (DBMS), explaining their definitions, characteristics, and purposes. It discusses the advantages of DBMS over traditional file systems, outlines the structure of relational databases, and introduces the concept of Entity Relationship (ER) diagrams for database design. Additionally, it covers normalization processes to avoid data anomalies and improve data integrity within databases.

Uploaded by

angtonem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Database Notes

The document provides an overview of data, databases, and Database Management Systems (DBMS), explaining their definitions, characteristics, and purposes. It discusses the advantages of DBMS over traditional file systems, outlines the structure of relational databases, and introduces the concept of Entity Relationship (ER) diagrams for database design. Additionally, it covers normalization processes to avoid data anomalies and improve data integrity within databases.

Uploaded by

angtonem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Database System

MANGOLA BRIAN
WHAT IS DATA, DATABASE, DBMS

• Data - means "known facts“ which can be


numbers, words, sounds, images, etc.
• Database - is a system for storing and taking care
of data (any kind of information) e.g. Teaching
File
• Database system - a computer program for
managing electronic databases
• Example of a database system would be an
electronic phonebook on your mobile phone
WHAT IS DATA, DATABASE, DBMS …CONT’D

•Database system is referred to as DBMS


(Database Management System)
•DBMS = Database + Management System.
•Database is a collection of data and
Management System is a set of programs to
store and retrieve those data
•DBMS is a collection of inter-related data and
set of programs to store & access those data in
an easy and effective manner.
WHAT IS DATA, DATABASE, DBMS …CONT’D
•Examples of popular DBMS used these
days:
• MySQL • SQLite
• Microsoft Access • IBM DB2
• Oracle • LibreOffice Base
• PostgreSQL • MariaDB
• dBASE • Microsoft SQL Server etc
• FoxPro

•This course will look at Microsoft Access (MS Access)


CHARACTERISTICS OF DBMS

•Data stored into Tables: Data is never directly stored


into the database. Data is stored into tables, created
inside the database.
•DBMS also allows to have relationships between
tables which makes the data more meaningful and
connected.
•Reduced Redundancy: Unnecessary repetition of
data in database is sorted out.
•DBMS follows Normalisation which divides the data
in such a way that repetition is minimum.
CHARACTERISTICS OF DBMS …CONT’D

•Data Consistency: On Live data, i.e. data that is


being continuously updated and added,
maintaining the consistency of data can become a
challenge.
•But DBMS handles it all by itself.
•Support Multiple user and Concurrent Access:
DBMS allows multiple users to work on it(update,
insert, delete data) at the same time and still
manages to maintain the data consistency.
CHARACTERISTICS OF DBMS …CONT’D

•Query Language: DBMS provides users with a simple


Query language, to easily fetch, insert, delete and
update a database.
•Security: takes care of the security of data,
protecting the data from un-authorised access by
creating user accounts with different access
permissions,
•This can easily secure our data by restricting
user access.
•DBMS supports transactions, which allows us to
better handle and manage data integrity in real world
applications where multi-threading is extensively used.
MAIN PURPOSE OF DBMS…CONT’D…

•The main purpose of database systems is to


manage the data.
•Consider a university that keeps the data
of students, teachers, courses, books etc.
•To manage this data we need to store this data
somewhere where we can add new data, delete
unused data, update outdated data, retrieve data,
•It’s the job of a DBMS to do all the
CRUD operations efficiently.
EXAMPLES OF APPLICATIONS THAT USE DBMS

Sector Use of DBMS


Banking For customer information, account activities, payments, deposits,
loans, etc.
Airlines For reservations and schedule information.
Universities For student information, course registrations, colleges and grades.
Telecommunication It helps to keep call records, monthly bills, maintaining balances, etc.
Finance For storing information about stock, sales, and purchases of financial
instruments like stocks and bonds.
Sales Use for storing customer, product & sales information.
Manufacturing Used for management of supply chain and for tracking production of
items. Inventories status in warehouses.
HR Management For information about employees, salaries, payroll, deduction,
generation of paycheques, etc.
DRAWBACKS OF FILE SYSTEM
•Data redundancy - refers to the duplication of data
•Data inconsistency – data not being same for the
same student. Example a student registers details at
dining, hostel, accounts, registry, etc. When phone
number changes, one or two records could be
updated while others not.
•Data Isolation - data are scattered in various files,
and files may be in different formats
•Data Security - data may easily be seen
by unauthorized persons
ADVANTAGE OF DBMS OVER FILE SYSTEM
•No redundant data
•Data Consistency and
Integrity
•Data Security
•Easy access to data
•Easy recovery
•Flexible
DISADVANTAGES OF DBMS
•DBMS implementation cost - is high compared to
the file system
•Complexity - Database systems are complex
to understand
•Performance - Database systems are generic,
making them suitable for various applications.
However this feature affect their performance for
some applications
RELATIONAL DBMS
•A relational database is a database divided into logical units called
tables, where tables are related to one another within the database.
•Relational database allows data to be broken down into logical,
smaller, and manageable units for easier maintenance and better
performance.
•Tables are related to one another through common keys or fields in a
relational database system,
•Even though the desired data may exist in more than one table, you
can easily join multiple tables together to get combined data set
using a single query.
•The approach of breaking down data into tables is based on the
theory of normalization (to be covered later in this Presentation)
DATABASE DESIGN
•The data is stored in database objects called tables
•A table is a collection of related data entries and it consists
of columns and rows
•Every table is broken up into smaller components called
fields
•A field is a column in a table that is designed to
maintain specific information about every record in the
table
•The fields (attributes) in the Students table can consist
of StudentID, FirstName, LastName, District, Province
and Country
DATABASE DESIGN …CONT’D

Milimo Name Sex Tribe


Sosca
Musinza
Shila
Female Tonga

Likezo
Male

Carol
DATABASE DESIGN …CONT’D

ParentID FirstName LastName CellNumber


CourseID CourseName CourseDescription

StudentID FirstName LastName Email


20180066
20180067
Inutu
John
Database
Muyunda
Muleya
[email protected]
[email protected]
20180068 Mary Mulenga [email protected]
20180069 Julie Phiri [email protected]
20180070 Abel Kalaluka [email protected]
ER DIAGRAM
•ER Diagram stands for Entity Relationship Diagram
•Displays the relationship of entity sets stored in
a database.
•ER diagrams help to explain the logical structure
of databases.
•They are created based on three basic concepts:
entities, attributes and relationships.
•ER Diagrams contain different symbols that use
rectangles to represent entities, ovals to define attributes
and diamond shapes to represent relationships.
ER Diagram …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

Primary Key 101 Mabbola Choma


123 Moomba Choma
Table 1 166 Mweemba Lusaka
Foreign Key lecturer_id lecturer_dept
101 EPS
Table 2 101 MAT
Relationship
123 SCI
• 1 to many
166 EPS

NORMALIZATION IN DBMS
Second normal …CONT
form ’D
(2NF)
•1NF table has been divided into two tables.
•Table 1 contains lecturer information. Table 2 contains
department information.
•A new column has been introduced called
lecturer_id which is the primary key for table 1.
•Records can be uniquely identified in Table 1
using lecturer_id

NORMALIZATION IN DBMS
Second normal …CONT
form ’D
(2NF)
•In Table 2, lecturer_ID is the Foreign Key
•Foreign Key references the primary key of Table 1
•It helps connect the two tables.

NORMALIZATION IN DBMS
Third Normal form…(3NF)
CONT’D
•A table design is said to be in 3NF if both the
following conditions hold:
•Table must be in 2NF
•Has no transitive functional dependencies
(an indirect relationship between data
elements)
•A transitive functional dependency is when changing
a non-key column, might cause any of the other non-
key columns to change

NORMALIZATION IN DBMS
Third Normal form…CONT’D
(3NF) Relationship
Table 1 lecturer_id lecturer_name district_id
• 1 to many
101 Mabbola 1
123 Moomba 1 • many to 1
166 Mweemba 2
Table 3
Table 2 lecturer_id lecturer_dept
district_id district_name
101 EPS
1 Choma
101 MAT
2 Lusaka
123 SCI
3 Monze
166 EPS

NORMALIZATION DBMS …Form)
IN Normal
3NF (Third CONT’D

•Lecturers’ table has again been divided and created


a new table which stores Districts.
•There are no transitive functional dependencies,
and hence our table is in 3NF
•In Table 3 district_id is primary key, and in Table 1
district_id is foreign to primary key in Table 3

NORMALIZATION IN DBMS
Boyce Codd …CONT
normal form’D(BCNF)
•It is an advance version of 3NF that’s why it is
also referred as 3.5NF.
•BCNF is stricter than 3NF.
•A table complies with BCNF if
•it is in 3NF and
•for every functional dependency X->Y, X should
be the super key of the table
DBMS KEYS
•A key in DBMS is an attribute or set of attributes
which helps identify a row(tuple) in a relation(table).
•Also helps to find the relation between two tables.
•Keys help you uniquely identify a row in a table by
a combination of one or more columns in that
table.
•Key is also helpful for finding unique record or
row from the table.
DBMS KEYS …CONT’D
•In the table below, StudentID is a primary key
because
it uniquely identifies a student record.
•In this table, no other student can have the
same StudentID
StudentID FirstName LastName
2019000064 Peter Chulu
2019000065 Ishmael Hakoone
2019000072 Grace Mangani
DBMS KEYS …CONT’D
•Various Keys in Database Management
System
•Super key
•Primary Key
•Alternate key
•Candidate Key
•Foreign key
•Compound key
•Composite key
DBMS KEYS …CONT’D
•Super key
•A super key is a group of single or multiple keys which identifies rows
in a table.
•A Super key may have additional attributes that are not needed for
unique identification.
•In the table, LecturerNRC and LecturerID or a combination
(LecturerNRC,LecturerID) of these are super keys.
LecturerNRC LecturerID LecturerName
193505/71/1 CLCE05 Mabbola
293515/72/1 CLCE06 Zimba
393505/73/1 CLCE07 Choongo
DBMS KEYS …CONT’D
•Primary Key
•Is a column or group of columns in a table that uniquely identify
every row in that table.
•The Primary Key can't be a duplicate meaning the same value can't
appear more than once in the table.
•A table cannot have more than one primary key.
•In table below, StudID is a Primary Key
StudID ExamNo First Name LastName Email
1 202011 Tom Mudenda [email protected]
2 202012 Nick Sitali [email protected]
3 202013 Diana Mulenga [email protected]
DBMS KEYS …CONT’D
• Alternate key
•Is a column or group of columns in a table that uniquely identify
every row in that table.
•A table can have multiple choices for a primary key but only one can
be set as the primary key.
•All the keys which are not primary key are called an Alternate Key.
•In the table on the previous slide, StudID, ExamNo, Email all
qualified to be primary keys.
•But since StudID is the primary key, ExamNo, Email becomes the
alternative key.
DBMS KEYS …CONT’D
• Candidate Key
•Is a set of attributes that uniquely identify tuples(rows) in a table.
•Candidate Key is a super key with no repeated attributes.
•The Primary key should be selected from the candidate keys.
•Every table must have at least a single candidate key.
•A table can have multiple candidate keys but only a single primary
key.
DBMS KEYS …CONT’D
• Illustration of candidate key, alternative key and primary key
Primary Key Candidate Key

StudID ExamNo First Name LastName Email


1 202011 Tom Mudenda [email protected]
2 202012 Nick Sitali [email protected]
3 202013 Diana Mulenga [email protected]

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

Terms and Basic Objects


•Database File:
•It is a file which stores the entire database.
•Can be saved to your hard drive or other storage devices.
•Datatypes:
•Datatypes are the properties of each field.
•Every field has one datatype like text, number, date, etc.
MICROSOFT ACCESS …CONT’D

Terms and Basic Objects


•Table
•A Table is an object which stores data in Row & Column format to
store data.
•A Table is usually related to other tables in the database file.
•Each column must have Unique name
•We can also define Primary Key in a table.
MICROSOFT ACCESS …CONT’D

Terms and Basic Objects


•Query
•Queries answer a question by selecting and sorting and
filtering data based on search criteria.
•Queries show a selection of data based on criteria (limitations) you
provide.
•Queries can pull from one or more related Tables and other Queries.
•Types of Query can be SELECT, INSERT, UPDATE, DELETE.
MICROSOFT ACCESS …CONT’D

Terms and Basic Objects


•Form
•A form is a database object that you can use to create a
user interface for a database application.
•Forms help to display live data from the table.
•It’s mainly used to ease the process of data entry or editing.
•Report
•A report is an object in desktop databases primarily used for
formatting, calculating, printing, and summarizing selected data.
•You can even customize the report's look and feel.
MICROSOFT ACCESS DATA TYPES
Type of Data Description
Short Text Text, including numbers which does not need calculation.
Long Text Used for lengthy text or alphanumeric data.
Number Used for storing mathematical calculations.
Date/Time Store Date/time for the years 100 through 9999.
Currency Stores currency values and numeric data with decimal places.
Auto Number Assigns a unique number when any new record is created. Usually used as the
primary key
Yes/No It only stores logical valuesYes and No.
Attachment Stores files, such as digital photos. Multiple files can be attached per record.
OLE objects OLE objects can store audio, video, other Binary Large Objects.
Hyperlink Used as hyperlink address.
Calculated Helps to create an expression that uses data from one or more fields.
DIFFERENCES BETWEEN ACCESS AND EXCEL

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

You might also like