9 Databases
9 Databases
9 Databases
Syllabus 2023-2025
34
Databases
Single databases
A database is a structural collection of data that allows people to extract information in a way
that meet their needs. The data can be include text, numbers, and pictures, anything that can
be stored in a computer.
1. If any changes or addition are made it only has to be done once – data is consistent.
2. The same data is used by everyone
3. Data is only stored once in relational database which means no data duplication
1. Patients in a hospital
2. Pupils at a school
1. Cars to be sold
2. Books in a library
1. hotel bookings
2. result of races
Inside a database, data is stored in tables, which consist of many records. Each record consist
of several fields. The number of record 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.
An easy way to remember this is: each record is a row in the table and each field is a column
in the table.
35
A table contains data about one type of item or person or event, and will be given a
meaning name, for example:
Each record in a table contain data about a single item, person or event, for example:
As every record contain the same number of fields, each field in a record contains a specific
piece of information about the single item, person or event stored in that record. Field will have
a meaningful name to identify the data stored in it, for example:
36
The patient’s table structure could look like this:
Validation
For example, the DATE OF ADDMISSION field will automatically be checked by the
software to make sure that any data input is a valid date before it can be stored in the
PATIENT TABLE.
37
Basic data types
There are six basic data types that you need to be able to use in a database:
1. Text/alphabetic
2. Character
3. Boolean
4. Integer
5. Real
6. Date/time
38
What is a data type?
Each field will require a data type to be select. A data type classifies how the data is stored,
displayed and the operation 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 calculation.
Primary keys
As each record within a table contain data about a single item, person, or event, it is important
to be able 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 fields 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 number could be added to each patient’s record. The
extra field is: Primary key field called hospital number
SQL
Structed Query Language (SQL) is the standard quary language for writing scripts to obtain
useful information from a database. We will be using SQL to obtain useful information from
single – table databases. This will provide a basic understanding of how to obtain and display
only the information required from a database. SQL is pronounced as es – queue – el.
For example, somebody needing to visit a patient would only require the ward 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
39
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.
You will need to be able to understand and identify the output from the following SQL
statement.
40
41
42