Understanding Flat and Relational Databases
Understanding Flat and Relational Databases
Manipulate data
Present data
AJIRO TECH - BEST IGCSE YOUTUBE CHANNEL
FLAT-FILE DATABASES
CREATE A DATABASE STRUCTURE A flat-file database stores its data in one table, which is organised by rows and
columns. For example, in the following database about teachers, each record
WHAT IS A DATABASE?
(row) in the table contains data about one person. Each column in the table
A database is an organised collection of data. A database program is software contains a field, which has been given a field name, and each cell in that column
which stores and retrieves data in a structured way. This includes the data has the same, predefined data type.
that is stored and the links between the data items. All databases store data
Field name
using a system of files, records and fields: Teacher ID Forename Surname Subject
A field is a single item of data, such as a forename or date of birth. Each 002 Amina Yusuf Maths
field has a field name that is used to identify it within the database. Each 003 Farah Ahmed Physics Records
field contains one type of data, for example numbers, text or a date. 004 Ibrahim Khalid English
A record is a collection of fields, for example, all the information about 005 Hassan Ali Geography
one person or one item. These may contain different data types.
A file (in database terms) is an organised collection of records, usually
Fields
where all the records are organised so that they can be stored together. A
file can have one or more tables within it.
Although all databases have these three elements in common, there RELATIONAL DATABASES
are two types: A relational database stores data in more than one linked table, stored in a file.
flat-file databases Relational databases are designed so that the same data is not stored many times.
relational databases.
KEO
Ajiro
Kelechi
Ndi
Okpara
ICT
Biology
G12345
G12346
Jasmine
James
Hall
Ling
JKW
SJR
AND
AND
KEO
GSD
Most tables will have a primary key field that holds unique data (no two records JKW Jennie Kwong English G12348 Addy Paredes SJR AND KEO
GSD Gideon Sunday Chemistry G12349 Hayley Lemon JKW AND KEO
are the same in this field) and is the field used to identify that record. Some
SJR Sarah Jordan English G12351 Jennie Campbell JKW AND GSD
tables will have one or more foreign key fields. A foreign key field in one data
table stores values from a primary key field in another table. These two tables are linked with a ‘one-to-many’ relationship, because one teacher’s
record is linked to many students’ records. The primary key fields (which must contain
Using the earlier example, if we wanted to add to the table the names of
unique data) are the Student_ID and Teacher_ID.
each student taught by each teacher using a flat-file database, the table
would look like this:
ADVANTAGES AND DISADVANTAGES OF USING FLAT-FILE AND RELATIONAL DATABASES
Teacher_ID Forename Surname Subject Student_ID Student_FName Student_SName There are three common types of changes which can be made to the data contained in a
AND Ajiro Ndi ICT G12345 Jasmine Hall database. Records/data can be added, edited or deleted. Because data is not repeated in a
AND Ajiro Ndi ICT G12346 James Ling
relational database, each change to an item of data or to a record has to be made only
AND Ajiro Ndi ICT G12348 Addy Paredes
You work for a small garage called ‘Dodgy Dave’s Motors’. This garage sells used
For this question, the descriptions help you to work out meaningful field names. These
cars. Using a suitable database package, import the file [Link]. Assign the
following data types to the fields. should always be short enough to allow printouts to fit easily on to as few pages as
Field name Data type Some field names are possible. The first example is Who manufactured the car?; this could be shortened to
Who manufactured the car? Text inappropriate. Create
Manufacturer or even Make. Make is short, meaningful and appropriate, so use that.
Model Text appropriate and meaningful field
Colour Text names for those fields. You may Price that we bought the car for could be changed to Purchase Price, Purchase, P Price,
Price that we bought the car for Numeric/Currency/2 decimal places add another field as a primary P_Price or just PPrice. Although Access will allow any of these, do not use field names
Price that we will sell the car for Numeric/Currency/2 decimal places key field if your software
requires this. Save the database. with spaces in them, as they may cause problems if you try to do more complex
Year Numeric/Integer
Extras Text operations with the database. You could use any of the other three options, as all would
Does the car need cleaning? Boolean/Logical
be acceptable. For this question, use PPrice. Similarly, the next field can be called SPrice.
Note: Consider the final field, Does the car need cleaning?. Simply using the fieldname Clean
It is important to make sure that you use the field names exactly as given in could give the wrong idea, as it could mean ‘Does the car need cleaning?’ or ‘Is the car
a question, unless you are asked to provide appropriate and meaningful field
names. clean?’. It is sensible to plan this and make the changes in the .csv file before importing
For the next part of the wizard, make sure that Comma is selected using the radio buttons
(unless you have changed the .csv file so that it uses semicolons as delimiters). Examine the
first row of the data and decide whether this row contains the field names that you need or if
it contains the first row of data. If the first row contains the field names click on the First Row
Contains Field Names tick box. As you tick this box, the first row changes from 9 to 10
in the Import to Table: box, enter tblCars. This is a meaningful table name as
‘tbl’ shows you that it is a table and ‘Cars’ gives relevance to the data. EDIT DATA TYPES
Changes to the data types, or other properties, can be made from the Home tab. In the
Views section click on the Design View icon.
Note:
The icon in the Views section of the Home tab will let you change between
Datasheet and Design View.
Code Numeric/Integer
If you need percentage values, set an integer or long integer data type and select
Type of product to be sold Text
Percentage from the Format drop-down menu for this field.
Description of the product to be sold Text
Colour Text
Discount Boolean/Logical
Some field names are inappropriate. Create appropriate and meaningful field names
for those fields. Use the Code field as your primary key. Save the database.
Open the database that you saved in Question 1. Add this new car to the database.
Make Model Colour PPrice SPrice Year Extras Valet
Ford Focus Silver 1350 2285 2008 Alarm Central Locking Alloy Wheels Yes
Note:
Once you open the database Do not attempt to enter any other characters, such as the currency symbol. As you
saved in Question 1, First press the Enter key after adding the prices Access will set the data into currency
click on Enable Content format.
button For other data each time you press the Enter key, Access automatically saves the
To open the table in changes you made to the data.
Datasheet View, double
click the left mouse button Note:
on the table name. Check your data entry carefully using visual verification. This is when you compare
the original data on paper (in this case, in Question 2) with the data that you have
To make sure that all the columns are entered into the computer. Data entry errors in a database may cause problems
fully visible, click the left mouse when you try to use the database to search or sort.
button on the grey square to the left
of the ID field name to highlight the
entire datasheet.
Open the database that you saved in Question 2. Add a new field to the database
called PDate. Add the purchase date of 20 December 2020 for the last car added to
the database. Save the database as Question 3.
Open the database
and open the table
tblCars in Design View. You may need to double click to the right of the PDate column to widen the column.
Move to the empty
row below the Valet
field and enter the
Field Name PDate. In Open the file saved in Task 1. Add these three items of stationery to the database.
the Data Type box use
the drop-down list to Code Type Description Quantity Colour SPrice PPrice Discount
select the Date/Time 44282 Lever Arch File Laminated Lever Arch Files 1 Red 57.22 28.96 No
type. 44283 Lever Arch File Laminated Lever Arch Files 1 Yellow 57.22 28.96 No
You work for Ajiro Tech British School. You will edit some data about the
Next
Mathematics Faculty. Using a suitable database package, import the file
[Link]. Use these field names and data types:
Field name Data type Set the SCode field as a key field. Import the
file [Link] as a new table in your
SCode Text
database. Set the Student_ID field as a key
FName Text
field. Create a one-to-many relationship as a This window shows the link between the fields in
SName Text
link between the SCode field in the Teachers’ both of the tables. The bottom of the window
Subject Text table and the Maths field in the Students’ displays the type of relationship that you have
Room Numeric/Integer table. created.
A screenshot of this window taken with <prt
Use the techniques you practised in Question 1 to import the two tables into the sc> key or snipping tool will copy this into the
database so that each table looks like this. clipboard. Paste this into the document that
you will present as evidence of your method.
Open the file saved in Question 4. The best way to create a data entry form is to select
the Create tab, then in the Forms section, click on the Form Wizard.
Open the file saved in Task 2 Import Assign a new field as a key field. The Form Wizard window opens.
Select the table that holds the fields
the file [Link]. Use these field Import the file [Link]. Use
that you will include in the form. If
names and data types: these field names and data types: the form needs fields from more than
one table, then select a query (you
Field name Data type Field name Data type
You can move each field across will use these later in the chapter).
Order_No Numeric/Integer Customer_ID Text into the form using the single We will create the first form by
arrow key, but, as you want all
Customer_No Text Name Text the data from this table on the
selecting tblStudents, so leave that
form, use the double arrow key. selected in the top selection box.
Product_Code Numeric/Integer Address_1 Text
Address_3 Text
Set the Customer_ID field as a key field. Create a Go to the Current Next Last New
one-to-many relationship between the Code field Zip_Code Text first record record record record record
in the Stationery table and the Product_Code field Discount_% Numeric/2 decimal places
in the Orders table. Create a one-to-many
relationship between the Customer_ID field in the Take screenshot evidence showing the:
Customers table and the Customer_No field in the field names and data types used in these
Orders table. two tables
relationships between the three tables.
Open the file saved in Question 7 Change the Tutor field so that the user can select
their tutor from the list of staff codes in tblTeachers.
Open the file saved in Question 7 and open frmStudents
in Design View. Delete the controls for the Tutor field
(both the label and text box). You will replace the text
box with another type of control. From the Form Design Combo List
box box
tab, in the Controls section there are two suitable
options, a combo box or a list box. In the next window select Table:
tblTeachers then click on <Enter>.
If you wish to allow the user to type new items into the drop-down list then a
combo box would be suitable, but for this task, where you do not want the user to
be able to add to the list items, select a List box.
Drag the control onto the form. The List
Box Wizard window opens. Select the
radio button for I want the list box to get Double click the left mouse button on the
the values from another table or query, SCode field to move it from the ‘Available
as the data is held in the teachers table. fields:’ to the ‘Selected fields:’, then click
Click on <Enter>. <Enter>.
PERFORM SEARCHES For this question it would be appropriate to show the customer all the fields except the ID
field, the price that the garage bought the car for (the PPrice field) and the date the garage
You can search for data in Access using a query. This allows you to select a subset
purchased the car (the PDate field).
of the data stored in your table. Each query is created, saved and can be used
again later. If new data is added to the table, when you open a query again it will Move all of the fields into the query using the
select the subset from all the data, including the new data. double arrow key.
Select the ID field, the PPrice field and the
PDate field in turn and click on the single
arrow to remove them from the selection.
Open the file that you saved at the end of Question 3. A customer would like a car You need to enter a name for the query. This query may
made by Ford. Find the customer a list of all the cars in the garage made by Ford. be turned into a report at some point and the name you
give the query may become the title for the report.
Open the database that you saved at the end of
Question 3. You do not need to open the table that
Select the radio button for Modify the query
you created earlier. Select the Create tab and find the
Queries section. Click on the Query Wizard icon. design, then click on <Finish>.
Open the file that you saved at the end of Question 10. The manager would like to see
all the details of all the cars made by Ford or Vauxhall.
Open the file that you saved at the end of Question 9. The manager would like to
see all the details of all the Fords that need valeting. Create a query in a similar way to the one for Question 10. In the Simple Query Wizard window,
make sure that the correct table name has been selected in the Tables/Queries box. If you select
one of the previous queries rather than the table, you are likely to get incorrect results.
Note:
Similar mathematical formulae can be used, with < for less than, > for greater
than, >= for greater than or equal to, and = for equals. These mathematical
formulae cannot be used for queries involving text fields but can be used for
any numeric, date or time fields.
Open the file that you saved at the end of Question 8. Find Mr Varela a list of all
the students that he teaches for Maths; include in this extract his full name and
Click on <Next>. Continue through the wizard until you get to the query in Design View.
teaching room.
Note:
To create a field that is calculated at run time, you must first open a query. For this
question the query will not be used to search for data but to perform the You can use the builder to achieve
calculation. Select the Create tab, then click in the Queries section on the Query this
Wizard icon; select the Simple Query Wizard.
Then click on <Next>. In the Tables/ Queries box select the table tblCars as the Note:
source of the data. Select all fields using the double arrow key. Click on <Next> Use + for addition, - for subtraction,
twice, name the query Profit calculation, select the radio button for Modify the * for multiply and / for divide.
query design, then click on <Finish>.
In the Views section, select the
In the Design View of the query, Datasheet View. Calculate the
use the bottom scroll bar to scroll profit for three or four cars by
to the right and find the first blank hand or using a calculator and
field compare with the results in the
query to check that you have
entered the formula correctly.
Again, check the calculations with a calculator to ensure that you have not made
an error when entering the formula. When you have calculated this field and view
the query in Datasheet View, you may see the values displayed as #####. This
means the column is too narrow to see all the data. Drag the right column handle Open the file saved in Question 16.
to the right so that the data is fully visible. Save the database and close the query. Select only the cars made by Audi, BMW or Mercedes. Produce a new extract from all
the data which, for the each of these makes of car, calculates:
the sum of the sale price
the average sale price
the number of cars in stock.
Sort this data into descending order of average sale price.
This question requires the use of summary data. Open the file and, from the Create
tab, select the Query Wizard, then the Simple Query Wizard followed by <Next>. In
the Tables/Queries box select tblCars and from this table select only the Make and
SPrice fields before clicking on <Next>
Click the radio button for Summary This opens the Summary Options window.
data, then select the Summary To calculate the sum of the sale prices, tick
the check box for Sum. For the average
Options… button.
sale price, tick the check box for Avg. For
the number of cars in stock tick the check
box for Count records in tblCars.
PRESENT DATA
Open the file saved in Task 5. PRODUCE A REPORT
Select all types of items, except for any binder. Produce a new extract from all of the
stationery data which, for each type of item, calculates: The word ‘report’ can be quite confusing. A dictionary definition is ‘a document that
the average purchase price gives information about an investigation or a piece of research’. For our purposes, a
the average sale price report has this generic meaning: ‘a document that gives information’. This is often
the number of items in stock. confused with a report created in Access. The report created in Access will often be
Sort this data into descending order of average purchase price. the most suitable report for questions and tasks, but sometimes it may be better to
Show how you performed the summary query and the results of the calculations. produce a report in a word processor, copying and pasting information into a
document. For each task you will need to decide which method is the most suitable.
Note: Change the report name so that it reads ‘All Ford cars in stock’ (which is the title from
If a question asks for specified fields (as this task asks for ‘displays only the Make, the task). As you still need to add the subtitle and ensure that the layout is correct,
Model, Colour, SPrice, Extras and Valet fields’) make sure you do not add extra select the Modify the report’s design radio button and click on <Next>. The Design
fields. Make sure that you also place the fields in the order specified in the View of the report will look similar to this.
question.
Open the database that you saved at the end of Question 18.
Produce a report that:
displays all the data for the Make, Model, Colour, SPrice, Year and Extras fields
for all the cars with alloy wheels from Question 12, within the width of a portrait
page
has your name in the report header followed by ‘Cars with alloy wheels’.
BREAKDOWN
Open the file Question 18. Select the Create tab and, in the Reports section, click on the
Report Wizard icon. In the Report Wizard window, in the Tables/ Queries box, select the
query for alloy wheels (that you created in Question 12). As the question says ‘display all
the data’, and specifies the fields, use the arrow buttons to move only these fields from
Available Fields: to the Selected Fields: box. Go through the wizard as you did for the
previous question, making sure that you set the page Orientation to Portrait.
You must show all of the required data in full Open the database that you saved in Task 7.
Produce a report that:
Change to Report View and check that all the data and labels fit within the width of a single
displays the data for all the items where the quantity is greater than or equal to
page. Other than the Extras field (which holds the most data), We can enlarge the Extras field
10, selected in Task 4, within the width of a portrait page
by making the control for that field twice as deep.
Change to Design View and click the cursor on the top edge of the Page Footer. Drag has your name in the header of each page
this down about 8mm. In the Detail row, click the cursor on the lower edge of the has a title ‘Quantity > = 10’ centre aligned at the top of the first page.
Extras control. Drag this down to double the height of this control.
Change to Report View and check that all the data and labels fit within the width of a single page
If you need to export a report without any formatting, select the Text File option
Create a new report showing all the data for all the cars in stock made by Audi,
BMW or Mercedes. To set a black background for the
Hide all the labels and data for the ID, Valet and PDate fields from the report. Hide PPrice data, in the Detail row of the
the PPrice data (but not the title) by setting a black background. report select the control for PPrice.
Move the cursor into the Property
Using the methods used so far in this chapter, create a new query from tblCars to Sheet, selecting the Format tab. Find
select the three makes of car. Create a new report set in landscape format to display the Back and Fore Color section and
use the <insert> icon to select the
all fields for these cars, like this.
colour palette.
Select the black colour rather than the white background. Set the Fore Color to black in
the same way. Change from Design View into Report View to see the changes.
Go into the Design View of the report; holding down the <ctrl> key select all the
controls for the ID, Valet and PDate fields. Open the Property Sheet and, in the
Visible section, change the setting from Yes to No, which will hide these controls.
Repeat this process for the Percent field. Click the left mouse button on the control for Percent in
the Detail row of the report. Select the Format tab and use the dropdown menu in the Format
section to select Percent from the drop-down list. Move to the Decimal Places section and select 0.
Open the file saved in Question 22. Using the extract that contains the Go into Report View to check that the formatting for this field is now correct and contains no
calculated fields Profit and Percent, produce a new report from all the data that: decimal places. This is fine, but some field widths may need readjusting so that all data and labels
has the PPrice, SPrice and Profit fields formatted as Euro with two decimal are fully visible. Adjust these before saving the completed report.
places
Note:
has the Percent field formatted as a percentage value with no decimal
places. If a question asks for a currency not held in this drop-down menu, select your local Currency format
Open the file saved in Question 23. Produce a new report from all the data that:
displays at the bottom of the report the total profit if all the cars were sold
displays at the bottom of the report the maximum, minimum and average
profit values
displays the number of cars in this report.
Open the file saved in Question 23. Produce a new report from all the data that:
displays at the bottom of the report the total profit if all the cars were sold
displays at the bottom of the report the maximum, minimum and average
profit values
displays the number of cars in this report.