6.database Systems
6.database Systems
Form 5
OBJECTIVES
Describe the file based
approach database systems
Outline features of a DBMS
describe features of relational
database which address
limitations of a file based
approach
Write SQL commands
develop interfaces and
queries using DBMS tools
Access data in a database
through a high level language
Design database applications
using Entity relationship
diagrams (ERDs)
Convert ERDs to relational
databases schema in standard
normal form
Normalise database tables up
to second normal form
- A database is a single organised collection of structured
and related data, stored with minimum duplication of data
items so as to provide consistent and controlled data within
an organisation.
- Databases can be accessed using different application
software.
- Data stored in databases can be accessed by all system
users, but with different access rights.
- Databases are designed to meet the information needs of
an organisation.
- Database operations may include addition of new
records, deletion of unwanted records, amendments
to existing records, creation of relationships between
files and removal or addition of fields of files.
- Databases ensure controlled redundancy since
redundancy cannot be wholly eliminated.
File Based Approach Database
Systems
- File based Approach is a traditional approach
of collecting and storing data In which data is
stored in files with each unit of organization
having its own files and each file having a
specific set of programs that manipulate the
data in that file.
The early days of computerized data processing, an organizational
data was duplicated in different files for the use of individual
departments eg Personnel department would hold details on name,
address and qualifications of each employee, while payroll
department would hold detals on name, surname, address and
salary of each employee.
Each department has its own set of application programs to
process the data in files.
This led to problems such as data redundancy which cane as a
result of duplication of data,
Duplication of data
Duplication of data
- The same data is duplicated in many files e.g. in the
personnel department along with a lot of other data kept
in the sales department.
- Another problem which came as a result of this
traditional file is inconsistency of data eg address was
updates on one file and not all other files e.g. in the
personnel file and not the payroll file and hence the next
pay slip will be send to the old address which is wrong.
- Another problem was that data was not shareable.
Database Approach Database Systems
- In attempt to solve the above problems mentioned, the data
from different departments was centralized in a common pool
so that all applications can have access to the same sort of data.
- Although this solves problems of duplication and inconsistency
it introduces few problems such as:
- Unproductive maintenance
- Programs were still depended on structure of the data so that
one department needed to add a new field to a particular file and
all programmes accessing that file need to be changed.
- The problem of security, all data in the database even
confidential or commercially sensitive was accessible by all
applications.
Types of databases (Database Models)
These include relational, hierarchical, network databases and
Object oriented databases.
1. Relational databases:
- These are database that organises data in a table format,
consisting of related data in another file, allowing users to link
the files.
- A table is collection of records stored using rows and column
structure.
- Each table is called a relation. A relation is a table with
columns and rows.
- It only applies to logical structure of the database, not the
- Each column represents an attribute (characteristic or field). Attribute is a
named column of a relation. It corresponds to a characteristic of an entity.
They are also called fields.
- Each row represents a record, as shown below.
- Degree is the number of attributes in a relation.
- Cardinality is the number of tuples in a relation
- Each cell of relation contains exactly one atomic (single) value.
- Each attribute has a distinct name.
- Values of an attribute are all from the same domain. Domain is the set of
allowable values for one or more attributes.
- Each tuple is distinct; there are no duplicate tuples.
- Order of attributes has no significance.
- Order of tuples has no significance, theoretically
- Relational databases organize data in a flexible manner.
- They are also simple to construct
- They are easy to use; Easier database design,
implementation, management.
- Ensures structural independence
- Ensures adhoc query capability with SQL
Disadvantages
o Substantial hardware and system software overhead
o May promote “islands of information” problems
o However, it may be difficult to come up with
relationships.
Database Keys:
A simple key contains a single attribute.
A composite key is a key that contains more than one
attribute.
A candidate key is an attribute (or set of attributes) that
uniquely identifies a row. A candidate key must possess the
following properties:
o Unique identification - For every row the value of the
key must uniquely identify that row.
o Non redundancy - No attribute in the key can be
discarded without destroying the property of unique
identification.
Super key: An attribute or a set of attributes
that uniquely identifies a tuple within a relation. A
super key is any set of attributes that uniquely
identifies a
row. A super key differs from a candidate key in
that it does not require the non-redundancy
property.
Primary key: It is a candidate key that is used
to identify a unique (one) record from a relation. A
candidate key which is selected as the
principal unique identifier. Every relation
must contain a primary key. The primary
key is usually the key selected to identify a
row when the database is physically
implemented. For example, a part number
is selected instead of a part description
Foreign key: A primary key in one file that is used/found in
another file. Foreign key is set of fields or attributes in one
relation that is used to “refer” to a tuple in another relation. Thus
it is a filed in one table but also used as a primary key in another
table.
Secondary Key: A field used to identify more than one record
at a time, e.g. a surname.
QUERY RESULT
• SELECT * FROM • All those only
StudentDetails
playing soccer will
WHERE
Games=‘Soccer’ be displayed
DISTINCT Clause
• The DISTINCT keyword is used in conjunction with the
SELECT statement to eliminate all the duplicate
records and fetching only unique records.
• Syntax: SELECT DISTINCT column1, column2….
FROM table_name
WHERE [condition];
QUERY
DISTINCT clause
RESULT
QUERY RESULT
• DELETE FROM StudentDetails• All students above the age of 20
(WHERE age is > 20); are eliminated from the table
The Update
QUERY RESULT
• UPDATE StudentDetails SET • The LastName of Rima is
LastName =‘Dube’ WHERE changed to Dube
LastName = ‘Rima’;
Dube
CREATE
• LecturerDetails