Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views4 pages

Cs CH 9

This chapter covers the fundamentals of single-table databases, including their structure, basic data types, primary keys, and the use of SQL for querying data. It emphasizes the importance of data validation, the classification of data types, and provides examples of SQL commands for data retrieval. Additionally, it includes sample questions and answers to illustrate the application of these concepts in a practical context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Cs CH 9

This chapter covers the fundamentals of single-table databases, including their structure, basic data types, primary keys, and the use of SQL for querying data. It emphasizes the importance of data validation, the classification of data types, and provides examples of SQL commands for data retrieval. Additionally, it includes sample questions and answers to illustrate the application of these concepts in a practical context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

318489_09_IGCSE_CO_SE_OL_133-136.

indd Page 133 12/07/22 1:15 PM F-0250 /145/HO02580/work/indd

9 Databases

Key objectives
The objectives of this chapter are to revise:
● 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 Databases
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. Data can include text,
numbers and pictures. For example, a simple database of items for sale
could include a description, the price and a picture of the item.
A single-table database contains only one table. A table consists of many
records. The number of records in a table will vary, as new records can be
added and deleted from a table as required. Each record consists of several
fields. The number of fields in 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
● each field is a column in the table.
Data is often validated when input into a field. For more on validation, see
Section 7.5.
Column
Table structure
Record 1 Field 1 Field 2 Field 3 Field 4
Record 2 Field 1 Field 2 Field 3 Field 4 Row
Record 3 Field 1 Field 2 Field 3 Field 4
Record 4 Field 1 Field 2 Field 3 Field 4
Record 5 Field 1 Field 2 Field 3 Field 4
Record 6 Field 1 Field 2 Field 3 Field 4
It is illegal to photocopy this page

9.1.2 Basic data types


A data type classifies how the data is stored, displayed and the
operations that can be performed on the stored value. Each field requires
a data type to be selected.

Hodder & Stoughton Limited © David Watson and Helen Williams 2022 133
318489_09_IGCSE_CO_SE_OL_133-136.indd Page 134 12/07/22 1:15 PM F-0250 /145/HO02580/work/indd

9.1 Databases

These are the database data types you need to be able to use. They are
available to use as Access data types, but the names Access uses may be
different from the terms in the syllabus.
Data type Description Access data type
Text/alphanumeric A number of characters Short text/long text
Character A single character Short text with a field size of one
Boolean One of two values: either True or Yes/No
False, 1 or 0, Yes or No
Integer Whole number Number formatted as fixed with zero decimal places
Real A decimal number Number formatted as decimal
Date/time Date and/or time Date/Time

9.1.3 Primary keys


Each record within a table contains data about a single item, person or
event. It is important to be able to uniquely identify each record. The
primary key is a field that uniquely identifies the record. Each primary
key contains a unique value; it must contain data values that are never
repeated in the table.

9.1.4 Structured Query Language


Structured Query Language (SQL) is the standard query language for
writing scripts to obtain information from a database. An SQL script is a
list of SQL commands that perform a given task.
Here are some examples of the SQL statements you need to be able to use.
Here are some examples of commands.
SQL query statement Description of statement
SELECT Fetches specified fields (columns) from a table; queries always begin with SELECT
FROM Identifies the table to use.
WHERE Includes only records (rows) in a query that match a given condition.
ORDER BY Sorts the results from a query by a given column either alphabetically or
numerically.
SUM Returns the sum of all the values in a field (column). Used with SELECT
COUNT Counts the number of records (rows) where the field (column) matches a specified
condition. Used with SELECT

Here are some examples of commands.


SELECT ItemDescription, Price Displays the description and price of all items for sale with a
price of more than 10.00
FROM ItemsForSale
It is illegal to photocopy this page

WHERE Price > 10.00


ORDER BY Price;
SELECT SUM(Price) Displays the total value all items for sale with a price of more
than 10.00
FROM ItemsForSale
WHERE Price > 10.00
SELECT COUNT(Price) Displays the number of items for sale with a price of more than
10.00
FROM ItemsForSale
WHERE Price > 10.00

134 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition
318489_09_IGCSE_CO_SE_OL_133-136.indd Page 135 12/07/22 1:15 PM F-0250 /145/HO02580/work/indd

9 Databases

Sample questions and answers


A database, StudentRoom, was set up to show the room numbers for
students living in student accommodation.
Name Block RoomNumber
David Smith A 129
Su Wong B 124
David Chow A 129
Amy Tang A 123
Joe Higgs B 124
David Smith B 125
Adel Hoo A 125
Peter Patel B 129

a) Explain why none of the fields in the database can be used as a primary
key.
b) State, with a reason, a field that could be added as a primary key and
give an example of some sample data for that field.
c) SELECT *
FROM StudentRoom
WHERE Block = 'A'
ORDER BY RoomNumber;
Show the output from this SQL command.
[6]

Tips
Part a) of this question involves ‘explain’. This means your answer needs
to give a reason why each field is not suitable to be a unique identifier.
In part b), you are asked to identify an item of data that would uniquely
identify the record and give the field/column a suitable name. Often if
there is no suitable unique fact a short code or number is used. In part c),
you are to show the output from the SQL query; make sure you show all
the rows and columns required in the appropriate order that satisfy the
question.
When practising questions, if you are unsure about what an SQL query
would show, build the database and write the query to check your
answer.

High-level sample answer


a) All the fields contain duplicate values as there are many students housed in
each block, some students share the same room and two of the students have
It is illegal to photocopy this page

the same name.


b) A field that gives each student a unique code could be added, for example
StudentID. This code should be easy to validate and have enough characters to
ensure no repeats would be required, for example ST12345.
c) Name Block RoomNumber
Amy Tang A 123
Adel Hoo A 125
David Smith A 129
David Chow A 129

Hodder & Stoughton Limited © David Watson and Helen Williams 2022 135
318489_09_IGCSE_CO_SE_OL_133-136.indd Page 136 12/07/22 1:15 PM F-0250 /145/HO02580/work/indd

9.1 Databases

Low-level sample answer


a) Use the Name.
b) No need for an extra field the Name is good.
c) Block A
Adel Hoo, 125
Amy Tang, 123
David Chow, 129
David Smith, 129

Teacher’s comments
The first answer is clearly set out and readable.

For part a), all the fields have been considered and each reason is given
in the context of the question. For part b), a new field with a suitable
name has been identified, a reason has been given for the choice and some
appropriate sample data provided. For part c), the use of a table gives the
output a clear structure, only students in Block A have been shown, and
they are in room number order. Where two students are sharing the room,
the order is the same as in the original table.

The second answer short and some of the questions seem to have been
misunderstood. For part a), the question answered is choose a suitable
primary key. Not the question set but a common error. For part b), the
student now sees no need for a new primary key even though the data in
the name has been repeated, indicating that the completed table given was
not read carefully enough. For part c), a heading and extra punctuation
have been added, the block field has been removed and the ordering is on
the name field.

Exam-style questions
1 In this question you will be given a statement 2 a) Explain what is meant by Structured
followed by four possible answers. Query Language (SQL).
Select which of the four answers you think is b) Describe two SQL commands.
correct and tick (✔) the box next to your answer.
 [6]
You may need to tick more than one box.
3 A company that sells cakes is setting up a
a) What is meant by the term table?
single-table database, to store information
® a collection of fields about the same item
about cakes that can be ordered. The
® it uniquely identifies a record
information includes, name of cake, number
® a single piece of data
of portions, price of cake, main ingredients
® a collection of related records
and decoration available.
b) What is meant by the term record?
It is illegal to photocopy this page

® a collection of fields about the same item State, with reasons, the structure required,
® a column of data including names of the data items to be
® a structured collection of data stored, the data type and sample data for
® it uniquely identifies a row of data each item.
c) What is meant by the term field?
 [8]
® a collection of rows about the same item
® it uniquely identifies a row of data
® a column of data
® a single piece of data [3]

136 Cambridge IGCSE™ and O Level Computer Science Study and Revision Guide Second Edition

You might also like