You are on page 1of 6

Cambridge International AS and A level IT

database structure, then it may not even be displayed.


In Figure 9.36, there are no key fields displayed for the
inspections or agencies. 1 Define the term primary key.
2 Describe the difference between a simple query and
a complex query.
Switchboards/menus
A menu can be used to help users navigate 3 Give an example of when a dynamic parameter
between elements of a database including forms, query might be used.
reports and action queries. A menu should include 4 Identify the decisions involved in exporting data
a title, clear instructions and buttons to each from a table.
element. 5 Explain the importance of referential integrity.

Export data
In the same way that data can be imported from
common formats, it can also be exported to common 9.02 Normalisation to third
formats. This allows data to be used by other users who
either do not have DBMS software or do not know how normal form
to use it. It can also be used to transfer data to other
systems.
Normalisation: process of structuringdata in a database
Table
Data in tables can be exported as a delimited file in CSV
format, as fixed length fields in text format or as a table Normalisation is the process of structuring data within
within a RTF file. It is sensible to save the field names when a database. The process starts with a flat file and finishes
saving to CSV or text files. with a set of related tables. It is a formal method of
ensuring that each table is structured correctly and does
Query not contain redundant data. There are stages throughout
Data from queries can be exported in the same way as the process known as normal forms. Each normal
tables, but only the data that meets the criteria of the form measures the extent to which the data has been
query will be exported. normalised.
When describing tables, the following conventions will be
Report used:
Reports include formatting, so the best method of export TABLENAME
is to a RTF file which will include all the original formatting. Primary Kev
Data that is exported from a report to a text file will lose its Attribute 1
formatting. Attribute 2
TABLENAME (Primary Key. Attribute 1, Attribute 2)
Table names will be in capitals, primary keys will be
TASK
underlined and all attributes will be listed below the table
CD 9.01 Sales processing.mdb name or within brackets.
Open CD 9.01 Sales processing.mdb and export the
following:
1 The Customer table in CSV format.
Unnormalised form
2 The UK Sales Reps query in fixed length fields text Data in unnormalised form (ONF) is a flat file. It will contain
format. non-atomic data, repeating groups of data and possibly
3 The Categories of Products report in RTF format. redundant data. Non-atomic data is where a field contains
more than one item of data.
Chapter 9: Database and file concepts :

Repeating groups of data is when fields are repeated for


each record or a record appears to have more than one set
of data for a group of fields.
This table contains non-atomic data:
Redundant data exists when data is repeated
Product ID Description Price unnecessarily. This can be spotted when data can be
327BLF Brown, Leather, Female ?3510 identified by knowing it is dependent upon another field.
327BPM Brown, Plastic, Male ? 2540
327CLF Cream, Leather, Female ? 3510 First normal form
The colour, material and gender are three separate Data in first normal form (INF) must satisfy the following
items of data within the description. This causes criteria:
a problem when trying to sort data by a specific • all fields must contain atomic data
characteristic, such as colour, or when trying to
• there must be no repeating groups of data
search by a specific characteristic. (Note: ? is the
symbol for rupees.)
• there must be a unique key.

This table contains fields that are repeated for each record:
Surname Forename Subject 1 Subject 2 Subject 3 Subject 4
Jones Ifor Welsh English History 161 g
:
Rushton Ken Politics Literature Philosophy Physics
Smallwood Steven Maths Physics German

The Subject field has been repeated. This can be a problem when trying to search for all students studying the same
subject or when a student only studies one subject (leaving several blank) or when a student needs to study a fifth
subject.
This table contains more than one set of data fora group of fields:

Surname Forename Book Date Out Date Due


Jones Ifor Everything 12/5/16 12/6/16
in Colour
12/5/16 12/6/16
Guardian
Rushton Ken Saving 14/5/16 14/6/16
Grace
Smallwood Steven Delirious 26/11/16 3/1/17
Stretch Out 5/1/17 5/2/17
Always 5/1/17 5/2/17
Faithful

Each student is borrowing more than one book and so the fields Book, Date Out and Date Due contain more than
one set of data per record. This could also be classed as non-atomic data as there is more than one data item per
field.
£gHrvgftPa* i:j~

Cambridge International AS and A level IT

Indented fields are a repeating group for each order.


The table below contains redundant data: To be in INF, this table needs:

Order Order Product Quantity Price • a unique key (Order Number)


ID Date • atomic data (Customer Name and Customer
3857 12/9/16 Marzipan 1 $1.50 Address need breaking down)
Flour 2 $0.75 • no repeating groups of data (products being
ordered).
2320 15/10/16 Marzipan 3 $1.50
Sugar 1 $0.83 The ORDER table becomes:

Eggs 6 $0.15 ORDER (Order Number. Order Date, Customer ID,


Customer Forename, Customer Surname, Customer
The price is dependent upon the product and Address 1, Customer Address 2, Customer Address
therefore it is being repeated unnecessarily. If we 3, Customer ZIP Code)
know the product, we know the price. A new table for the order of products needs to be
added, but it needs to retain information about
which order each order of products belongs to:
ORDERUNE (Order Number. Product Code.
TASK
Description, Quantity, Price)
Describe the characteristics of data in 0NF using
examples from the table of driving lessons: Order Number is retained in the ORDERUNE table
as a foreign key. However, it is not unique and so
Learner Lesson Instructor Instructor Price cannot be used as the primary key. However, a
Date ID combination of Order Number and Product Code
Rob 30/5/16 4 Marcus $35 are unique and so these becomes a compound
Pocock 6/6/16 4 Brown $35 key
Marcus
Brown
Graham 31/5/16 3 Mike Joyce $30
Alkins 1/6/16 4 Marcus $35 TASK
Brown Normalise the table of driving lessons below to INF:
LESSON (Learner, Lesson Date, Instructor ID, Instructor, Price)

Learner Lesson Instructor Instructor Price


Date ID
Rob 30/5/16 4 Marcus Brown $35
Pocock 6/6/16 4 Marcus Brown $35
The ORDER table below contains details of products Graham 31/5/16 3 Mike Joyce $30
ordered by customers: Alkins 1/6/16 4 Marcus Brown $35

ORDER
Order Date
Customer ID
Second normal form
Customer Name
Data in second normal form (2NF) must have no
Customer Address
partial key dependencies. This means that no non-key
Product Code
fields can be dependent upon part of a primary key.
Description
This therefore only applies to tables with compound
Quantity
keys because they are the only tables that can have
Price
partial keys. Dependencies exist when the data is
Chapter 9: Database and file concepts

known because of its direct relationship to another Third normal form


field. Data in third normal form 3NF must have no non-key
When identifying partial key dependencies, there dependencies. This means that there should be no
will be fields that are dependent on just one part of fields that are dependent upon another field that is not
the compound key. These fields and that part of the a primary key. Therefore primary keys and compound
compound key will form a new table. primary keys can be ignored. All other fields should be
examined to see if they are dependent on any other non¬
key field.

The orders database from the previous example


now contains two tables:
ORDER (Order Number. Order Date, Customer ID, The orders database from the previous example
Customer Forename, Customer Surname, Customer now contains three tables:
Address 1, Customer Address 2, Customer Address
ORDER (Order Number. Order Date, Customer ID,
3, Customer ZIP Code)
Customer Forename, Customer Surname, Customer
ORDERLINE (Order Number. Product Code. Address 1, Customer Address 2, Customer Address
Description, Quantity, Price) 3, Customer ZIP Code)
Only the ORDERLINE table contains partial keys. PRODUCT (Product Code. Description, Price)
Description and Price are dependent on Product Code
ORDERLINE (Order Number. Product Code.
which is part of the compound primary key. Therefore,
Quantity)
a new table needs to be created for products:
In the ORDER table, all the customer data is 163
PRODUCT (Product Code. Description, Price)
dependent on the Customer ID which is a non¬
The information stored in the ORDERLINE table key field. A new table needs to be created called
that is not part of the PRODUCT table needs to be CUSTOMER:
retained:
CUSTOMER (Customer ID, Forename, Surname,
ORDERLINE (Order Number. Product Code. Address 1, Address 2, Address 3, ZIP Code)
Quantity)
The ORDER table now becomes:
The Product Code field is retained in the ORDERLINE
ORDER (Order Number. Order Date, Customer ID)
table as a foreign key because it is still necessary to
know which products were ordered. Customer ID is retained in the ORDER table as
a foreign key so it is still known which customer
placed the order.

TASK
Normalise the table of ingredients below to 2N F:
RECIPE-INGREDIENT (Recipe ID. Ingredient ID. Ingredient TASK
Name, Measure, Quantity) Normalise the table of students below to 3NI :
Recipe Ingredient Ingredient Measure Quantity STUDENT (Student ID. Forename, Surname, Class,
ID ID Name Teacher Forename, Teacher Surname)
1 B Flour Grams 200 Student Forename Surname Class Teacher Teacher
1 D Eggs Eggs 2 ID Title Surname
1 K Water Tablespoons 2 1 Hayley Barrow 3 Mrs Stokes
2 C Milk Millilitres 250 2 Harriet Chew l Miss Spicer
2 B Flour Grams 100 3 Jessica Lang 3 Mrs Stokes
Cambridge International AS and A level IT

Normalise a database to 3NF

TASK
The PROJECT table below contains details of the employees working on projects for clients. It is currently in ONF. Normalise
the data to 3NF.
PROJECT
Description
Start Date
End Date
Client ID
Company
Contact Name
Employee ID
Employee Name
Employee Hours
Here is an example of the data:

Description Start Date End Date Client Company Contact Employee Employee Employee
ID Name ID Name Hours
Barton 28/2/15 31/12/16 512 Barton Jerry PK32 Fred Havers 1052
Towers Estates Dean Janice Spring
JH45 575
Haywood 31/3/15 15/6/15 987 Haywood Peter JH45 Janice Spring 153
Manor Estates Gates Mike Rawson
YR27 372

o DISCUSSION POINT
There are also fourth (4NF) and fifth normal forms (5NF)
The database will perform better if it is normalised
because searches can be carried out on indexed fields
and data can be looked up from related tables. However,
as well as another one called Boyce-Codd Normal Form
(BCNF). However, these have little relevance to a designer
each lookup does take time to perform and will use up
of a database and are used mainly in higher academic processor time, which means that some queries that
studies. require access to more than one table may be slow.
As tables no longer contain redundant data, maintenance
tasks such as rebuilding indexes can be completed more
quickly. However, it can be difficult to understand the
Advantages and disadvantages of data stored in each table because foreign keys consisting
normalisation of numbers or codes are used and they mean very little
Normalisation removes duplicate data from a database. to the user. This means that the user will need to build
Not only does this reduce the size of the database, it also queries to look up data from related tables. These
removes the potential for errors and inconsistencies. queries can be quite complex and require expertise from
Data that is duplicated may be edited for one record but the user.
not another, meaning that it becomes inconsistent. This
causes problems when searching for matching data. The database becomes more flexible in that it is easy to
add new fields to tables without affecting other columns
ibaseand file concepts
*

and it is easy to add new tables without affecting • what sort order to use when displaying data
existing tables. Having smaller tables also means that relationships to othertables
data can fit onto one screen or one page more easily total number of records
because there are fewer fields and security permissions validation rules that apply based on multiple fields
can be applied to individual tables. However, it is within the table
also necessary to design the database properly and permissions and security as to which users can
to understand the process of normalisation. This is
access the table.
a high level skill that requires a database designer to
understand the real world data structures and represent
them in a relational database. An average user would
not be able to do this.

This is part of a data dictionary for fields in a


product table:

6 Identify two characteristics of data in INF. Attribute Data Type Field Size Format
7 Describe one characteristic of data in 3NF. Product Code Alphanumeric 6 XX99XX
8 Explain two advantages of normalisation. Description Alphanumeric 20
Category Integer 4 9999
Code
Price Decimal 3.2 $999.99
9.03 Data dictionary

Data dictionary: metadata (information) about the


Attribute

Product
Validation Rule
Type
Format Must be
Error
Message
Please
m
database Code in the enter a
format code that
of two is two
A data dictionary is a document or file that describes the letters, letters, two
structure of the data held within the database. It is known two numbers,
as metadata which means ‘data about data’. It is a tool numbers, two letters
that is used by database developers and administrators. It two
wilt include the following items: letters
Description Presence Must be Please
• data about fields:
present enter a
field names to identify each field
description
• data types, such as text, integer, date/time
Category Look up in Must Please
field size, such as the length of a text field or the
Code List exist in enter a
maximum value of a numeric field
Category category
format of fields Code in code that
• default values which are values a field is set to be Category exists in the
initially when a new record is created table category list
primary keys, compound keys and foreign keys Price Range Between Enter
indexed fields which improve search times 0.01 and a price
• validation rules that restrict data entry for that 999.99 between
field 0.01 and
• data about tables: 999.99
• the primary key of the table

You might also like