09 Databases
09 Databases
Databases
• In this chapter, you will learn about:
• ★ the design and use of single table databases
• – fields
• – records
• – validation
• ★ the use of basic data types
• – text/alphanumeric
• – character
• – Boolean
• – integer
• – real
• – date/time
• ★ the identification, purpose and use of primary keys
• ★ SQL scripts, used to query data stored in a single table database.
9.1.1 Single-table databases
A database is a structured collection of data that allows people
to extract
information in a way that meets their needs. The data can
include text, numbers,
pictures; anything that can be stored in a computer. Relational
databases will be
studied at A Level but for IGCSE only single-table databases will
be studied.
A single-table database contains only one table.
Fields and records – the building blocks for any database
Inside a database, data is stored in tables, which consists of
many records. Each
record consists of several fields. The number of records in a
table will vary as
new records can be added and deleted from a table as required.
The number of
fields in a table is fixed so each record contains the same number
of fields.
Validation is the automated checking by a program that
data is reasonable
before it is accepted into a computer system. When data is
validated by a
computer system, if the data is rejected a message should
be output explaining why the data was rejected and another
9.1.2 Basicgiven
opportunity data to
types
enter the data.
There are six basic data types that you need to be able to
use in a database:
» text/alphanumeric
» character
» Boolean
» integer
» real
» date/time.
What is a data type?
Each field will require a data type to be selected. A data type
classifies how the
data is stored, displayed and the operations that can be
performed on the stored
value. For example, a field with an integer data type is stored
and displayed as a
whole number and the value stored can be used in calculations.
9.1.3 Primary keys
As each record within a table contains data about a single item, person,
or event, it is important to be able to uniquely identify this item. In order
to reliably identify an item from the data stored about it in a record there
needs to be a field that uniquely identifies the item.
This field is called the primary key.
A field that is a primary key must contain data values that are never
repeated in
the table.
The primary key can be a field that is already used, provided it is unique,
for
example the ISBN in the book table. The PATIENT table would need an extra
field
for each record as all of the existing fields could contain repeated data. To
create
a primary key, we could add a new field to each record, for example a
unique
9.1.4 SQL
Structured Query Language (SQL) is the standard query
language for writing
scripts to obtain useful information from a database. We will be
using SQL
to obtain information from single-table databases. This will provide
a basic
understanding of how to obtain and display only the information
For example,
required fromsomebody
a needing to visit a patient would only require
the ward SQL is pronounced as es-queue-el.
database.
number and the bed number of that patient in order to find where
they are in the
hospital. Whereas a consultant could need a list of the names of all
the patients
that they care for.
SQL scripts
An SQL script is a list of SQL commands that perform a given task,
often stored
in a file so the script can be reused.
In order to be able to understand SQL and identify the output from
an SQL script,
you should have practical experience of writing SQL scripts. You can
write scripts
using SQL commands in Access.