Sie sind auf Seite 1von 31

PRINCIPLES OF DATABASE MANAGEMENT

By:
Namanga
COURSE OUTLINE
 Introduction to Databases
 Database Environment
 Entity-Relationship Modeling
 Enhanced Entity-Relationship Modeling
 The Relational Model
 Relational Algebra (Introduction)
 Normalization
 SQL: Data Manipulation and Data Definition
 Query-By-Example
 Commercial DBMS: Access and Oracle
 Database Planning, Design, and Administration
 Fact-Finding Techniques (Introduction)
 Methodology: Conceptual, Logical, and Physical Database Design
 Lab practical sessions
DATABASES INTRODUCTION
 Every system in the world uses storage locations for its
data and information. These range from simple storage
locations to complex computerized locations.
 Traditional databases were used in storing information
such as files, where files containing important
information were kept in a tray in different shelves of a
cupboard.
 Similar to traditional approach, computerized records
are kept in databases, which refer to organized
structures for keeping computerized records for future
use, manipulation of data or simply reference.
DATABASES
 Definition
 An application program for storing, retrieving,
updating records at any given time.
 Storage of records entails inserting records into an
application for future use.
 Retrieval of records involves pulling the records
from stored area for particular use.
 Updating records is the process of inserting or
amending stored information for better reading or
intepretation.
TYPES OF DATABASES
 There are different types of databases that
exist currently.
 Variations in databases are due to differences
in applications and requirements by different
organizations.
 There are broad categories of databases,
namely:
 Traditional
File Databases
 Computerized File Databases
TRADITIONAL FILE DATABASES
 These refer to the filing system that involves a tray and a cabinet for
keeping files. Simple electronic gadgets like a calculator can be
incorporated for calculation of numeric values.
 Advantages of Traditional File Systems
 Easy to manage
 Requires no technical expertise to run
 Disadvantages of Traditional File Systems
 Difficult to update records as continuous rubbing of records destroy files
 No authenticity as anyone could access the files within the given room
 In the event of fires and calamities, the files are vulnerable to
destruction, and no backups are provided for
 Files are vulnerable to rodents and termites destruction.
 Security is issue in traditional filing system.
 Poor organization of files increases such time and retrieval time.
COMPUTERIZED DATABASE SYSTEM
 Refers to the use of computers to store, update, retrieve and create records. Majorly done using databases. Examples
of these computerized database systems include:
 Microsoft Access
 SQL
 MySQL
 MongoDB
 Oracle Database
 NoSQL
 SQLite
 Informix
 Advantages of Computerized Database Systems
 Allow easy access to records
 Easy to update and retrieve information
 Search features allow for easy access to data
 Cleanliness can be maintained, since it does not entail manual erasing
 Files are organized into clear records, as opposed to manual filing systems
 Security of records is maintained as passwords can be enforced
 Elimination of redundancy since keys and indexes can be attributed to records to eliminate repetition of data records
 Records can be backed up to eliminate cases of information loss in the events of calamities such as fires or floods
 Disadvantages
 Expensive to purchase computer equipment
 Requires expertise knowledge in order to maintain databases
 In the event of security breaches, data can be lost and result in major calamities.
DATABASE ENVIRONMENT
 A database operates in a set of given variables, and these variables are
contained in a space of parameters that integrate together to achieve the
purpose of creating, storing, and retrieving data and information. These
system components include:
 Hardware components- which refer to the storage components like hard disks
and computer interfaces to allow for access into the database
 Software components- which are the actual application programs that run the
work of storage, retrieval and manipulation of data in a database.
 Liveware or people components- These are the users of the database such as
database administrators, organizations, as well as other users that access the
database.
 Procedures or protocols- Refer to rules governing retrieval and manipulation as
well as storage of data and information in the database.
 Data or Information. Data refers to raw facts and figures to be stored or
manipulated in the database. Information is the processed data that presents
the output or is stored in the database for future reference.
MICROSOFT ACCESS DATABASE OBJECTS
 A typical database is composed of various objects, and these objects
are the functional units of a database. For access databases, the
objects include:
 Tables- Storage locations for data in access db
 Queries- Functional part of the Access DB that is used to retrieve, filter
and perform numerical manipulations on data in the database
 Forms- present the graphical layout of the data in Access Database.
Numerical calculations can also be performed here.
 Reports- Result output of data in databases. Can be created from
queries or tables or a combination of both objects.
 Macros- These are automated features that can be used to automate
and perform particular functions as desired by the user.
 Modules- Application codes that resemble VB codes that can be written
to perform some automated functions within the database.
DEFINITION OF TERMS
 Field- This refers to a database description that will hold data
for a particular purpose. Fields are different entities within the
database, examples being name, Student ID, Age, etc.
 Record- This refers to the data entered into a field in the
database, or we could say it is a description of the field, an
example is for the field Name, we could have Ahmed, Student
ID, 1234, Age 14.
Fields Name Student ID Age Class
Ahmed 1234 18 BBIT
Records
Suriya 1235 10 BIT
Dan 12113 20 IT
ACCESS FIELD DATA ATTRIBBUTES
 These refer to data qualities that apply to data or values contained in the access
database and also determines the kind of data to be entered in the given fields.
 The basic field data types include the following:
 Attachment Files, such as digital photos. Multiple files can be attached per record. This data
type is not available in earlier versions of Access.
 AutoNumber Numbers that are automatically generated for each record.
 Currency Monetary values.
 Date/Time Dates and times.
 Hyperlink Hyperlinks, such as e-mail addresses.
 Memo Long blocks of text and text that use text formatting. A typical use of a Memo field would
be a detailed product description.
 Number Numeric values which can be manipulated or calculated, such as distances. Note that
there is a separate data type for currency.
 OLE Object -Object Linking and Embedding for attaching objects, such as Word documents.
 Text Short, alphanumeric values, such as a last name or a street address that cannot be
manipulated by computation.
 Yes/No Boolean values that are either true or false, e.g .dead or alive, male or female.
 Lookup Fields- These describe text attributes that can be set to provide a dropdown menu when
one is entering values. An example is a list of cities within a country.
ENTITY RELATIONSHIPS
 An entity refers to an object in a system that is to be
modeled and information stored about it. These could be
objects like details of a person, vehicle, event, etc.
 Entity relationship refers to the conceptual and theoretical
approach to describing how data in the objects are related to
each other in the different objects. Normally, we do this by
creating an Entity Relationship Diagram, referred to as an
ERM (Entity Relationship Model).
 In Databases, Data can be related in 3 different ways,
namely:
 One-to-one relationship
 One-to-many relationship
 Many-to-many relationship
CREATING RELATIONSHIPS
 In order to create a relationship, there are some critical aspects of
data that must be taken into account, and these include:
 The field to be used in creating a relationship must be a primary key in
one table and a secondary key in the child table.
 A primary key can be defined as a unique index that cannot accept nulls, and the
data entered therein must be unique for each record.
 A primary table or parent table refers to the table that contains the primary key
used to link up with the child table.
 A child table or secondary table is a table that contains the secondary key joined
to the primary key in the relationship.
 A secondary key is a field similar to one on a parent table used as a primary key,
and is used for creating a relationship.
 The primary and the secondary keys must contain the same field data
types, e.g. if the primary key is text data type, the secondary key must
also be of text data type.
ENTITY RELATIONSHIP MODELS
 This describes relationship where one primary field can only be
related to one secondary field. An example is where an employee can
only be supervised by a single supervisor, and the supervisor cannot
supervise more than one employee.
 In one-to-many relationship, one field acting as the primary key in the
primary table can be related to many records in the secondary table
using a secondary key. An example is the case of a parent having
many students in a given school, so that the parents table can be
related to the students table using parent id as the primary key in the
parents table and parent id as a secondary key in the students table.
 Many-to-many relationship employs the aspect of many records of a
given field in one table relating to many records of a field in another
table. An example is a case scenario of a many students taking many
subjects.
 In diagrammatic representation, this ERM is given as :
ERM DIAGRAM
ENHANCED ERM
 In order to come up with relationships, one must create tables first in MS Access
then define the proper primary keys and secondary keys in child tables.
 Once identified, the relationships tool can be used to come up with appropriate
relationships and relate them, where the related records must be cascaded for
updates and deletes.
 Cascading records means joining records, so that a deletion or update in one of the
tables would delete or update related records in the linked table.
 These representations can be given as follows in real table examples:
Primary Key Secondary Key Secondary Key
Primary Key
REFERENTIAL INTEGRITY
 Data integrity refers to accuracy, timeliness and consistency
of data and information stored within a database.
 Accuracy defines the correctness of data stored within a
database
 Timeliness refers to the application of the data to the current
date and time, or the data being current with the changing
world and technology.
 Consistency refers to the appropriateness of data changes
with changes requested, and its successive applications to
related data in other tables.
 When creating tables, the database administrator should
enforce referential integrity in order to allow for data integrity
in terms of consistency and accuracy.
RELATIONAL ALGEBRA

 Relational algebra is a procedural query language,


which takes instances of relations as input and yields
the same instances of relations as output. It uses
operators to perform queries. An operator can be either
unary or binary.
 The fundamental operations of relational algebra:
 Select
 Project
 Union
 Set different
 Cartesian product
 Rename
SELECT OPERATION (Σ)
 It selects data that satisfy the given predicate from a relation.
 Notation − σp(r)
 Where σ stands for selection predicate and r stands for relation. p is
prepositional logic formula which may use connectors like and, or,
and not. These terms may use relational operators like =, ≠, ≥, <
, >, ≤.
 For example −
 σsubject = "database"(Books) Output − Selects data from books where
subject is 'database'.
 σsubject = "database" and price = "450"(Books) Output − Selects data from books
where subject is 'database' and 'price' is 450.
 σsubject = "database" and price = "450" or year > "2010"(Books) Output − Selects data
from books where subject is 'database' and 'price' is 450 or those
books published after 2010.
PROJECT OPERATION (∏)
 It projects column(s) that satisfy a given predicate.
 Notation − ∏A1, A2, An (r)
 Where A1, A2 , An are attribute names of relation r.
 Duplicate rows are automatically eliminated, as
relation is a set.
 For example −
 ∏subject, author (Books) Selects and projects columns
named as subject and author from the relation
Books.
UNION OPERATION (∪)
 It performs binary union between two given relations and is
defined as −
 r ∪ s = { t | t ∈ r or t ∈ s} Notation − r U s
 Where r and s are either database relations or relation result
set (temporary relation).
 For a union operation to be valid, the following conditions
must hold:
 r, and s must have the same number of attributes.
 Attribute domains must be compatible.
 Duplicate data are automatically eliminated.
 ∏ author (Books) ∪ ∏ author (Articles) Output − Projects the
names of the authors who have either written a book or an
article or both.
SET DIFFERENCE (−)
 The result of set difference operation is data,
which are present in one relation but are not in
the second relation.
 Notation − r − s
 Finds all the data that is present in r but not in
s.
 ∏ author (Books) − ∏ author (Articles) Output −
Provides the name of authors who have written
books but not articles.
CARTESIAN PRODUCT (Χ)
 Combines information of two different relations
into one.
 Notation − r Χ s
 Where r and s are relations and their output will be
defined as −
 r Χ s = { q t | q ∈ r and t ∈ s}
 σauthor = ‘amoud'(Books Χ Articles) Output − Yields a
relation, which shows all the books and articles
written by amoud.
RENAME OPERATION (Ρ)

 The results of relational algebra are also


relations but without any name. The rename
operation allows us to rename the output
relation. 'rename' operation is denoted with
small Greek letter rho ρ.
 Notation − ρ x (E)

 Where the result of expression E is saved with


name of x.
NORMALIZATION
 This refers to breaking down tables to eliminate
cases of data redundancy and improve
instances of data insertion, deletion and
updates.
 The process involves breaking down data into
tables and implementing relationships between
related data in different tables.
 Normalization takes different steps, and could
be from 1st normalization to 3rd normal form.
 Let’s take a case example of the following data:
 First Normal Form
 This table indicates a lot of redundancies for the given
set of data. The data is also disorganized.
Student Name Age Subject Subject Id
ID
40 Ibrahim 22 BBIT 2
10 Ahmed 19 BIT 1
50 Samirya 20 BIT 1
40 Ibrahim 22 BIT 1
20 Amina 21 BBIT 2
30 David 18 BBIT 2
40 Ibrahim 22 BSIT 3
 Second Normal Form (2NF) involves arranging the data in the
table into appropriate order, where related records are
arranged successively. In as much as the data is organized,
there exists a lot of redundancies in the set of data
Student Id Name Age Subject Subject Id

10 Ahmed 19 BIT 1

20 Amina 21 BBIT 2

30 David 18 BBIT 2

40 Ibrahim 22 BBIT 2

40 Ibrahim 22 BIT 1

40 Ibrahim 22 BSIT 3

50 Samirya 20 BIT 1
 Third Normal Form (3NF) entails arranging the data in different tables where
the data is related to each other. In this case, we shall have two tables, for
subjects and student details. Cases of redundancies have been eliminated,
and from here, we introduce concept of relationship in order to relate the
two tables. This can be done by introducing a primary key in the students
table as student Id, and exporting the same field to Subjects table as
secondary key.

Subject Subject ID
Student Name Age
Id BIT 1
10 Ahmed 19 BBIT 2
20 Amina 21 BSIT 3
30 David 18
40 Ibrahim 22
50 Samirya 20
SQL DATA MANIPULATION
 SQL stands for Structured Query Language, and it
is a command-based language used to query the
database for specific actions.
 SQL was developed in order to simplify Relational
Database Management Systems (RDBMS) for
dynamic systems and management of large sites.
 SQL is compatible with all websites, and offers
reliable connection and management of large
volumes of data within a website, as well as
access to the database.
 All SQL commands end in a semicolon (;).
 Some of the commands used in SQL include:
 Create command, which is used to create a database; e.g. create database name; CREATE
TABLE table_name (field names and field attributes);
 Use command- which is used to instruct the editor to use a given database and make it active;
e.g. USE database_name;
 Insert command- which enters data into the database tables created. E.g. INSERT INTO
table_name (field names) VALUES (values for each field);
 Update command- used to update records of a table. E.g. UPDATE table table_name SET
field_name = new_field_record, another_field_name=another_new_record WHERE criteria.
 Delete command- Entered to delete a given record e.g. DELETE FROM table_name WHERE
criteria
 Alter command- Used to make changes to the table attributes, e.g. adding an additional column
to the table. E.g. ALTER TABLE table_name OPERATION (EXAMPLE ‘ADD’) column_name
DATA_DESCRIPTION;
 Select Command- used to select data from tables in the database. This can be performed with a
filter or without a filter to select all the data from the tables. E.g. SELECT * FROM table_name; -
This would select all the data from the table without any conditions or limits. SELECT
(field_names) FROM table_name; - selects specified field names from the table and displays
them all without a filter. SELECT (field_names) FROM table_name WHERE condition –displays
tables that meet the given condition only.

Das könnte Ihnen auch gefallen