1.8 Database and Data Modelling
1.8 Database and Data Modelling
DATABASE AND
COMPUTER SCI ENCE DATA MODELLING
Compiled: By Engr. Shahzadah Ashraf Bande’Shah
TOPIC 1.1
Notes + Topical Past
Papers + Marking Scheme
STUDENTS NAME:
shahzadah.ashraf 03332076121
SCHOOL NAME: @gmail.com
Follow On Facebook :
DATE ISSUED: https://www.facebook.com/shahzad
ah.ashraf
A Levels With
Sir Bande'Shah
Page 1 of 136
Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content
8 Databases
Page 2 of 136
Cambridge International AS & A Level Computer Science 9618 syllabus for 2021, 2022 and 2023. Subject content
8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
Page 3 of 136
Page 4 of 136
8.1 Database Management Systems (DBMS)
A database is a stored collection of information arranged in a logical, structured manner. Databases have
been a staple of business computing from the very beginning of the digital era.
Flat File
Originally, databases were flat. This means that the information was stored in one long text file, called
a tab delimited file. Each entry in the tab delimited file is separated by a special character, such as a
vertical bar (|). Each entry contains multiple pieces of information (fields) about a particular object or
person grouped together as a record. For example:
Lname, FName, Age, Salary|Smith, John, 35, $280|Doe, Jane, 28, $325|Brown, Scott, 41,
$265|Howard, Shemp, 48, $359|Taylor, Tom, 22, $250
When there is only a single table in the database, this is called a 'flat file database'.
A flat file database is an excellent way of storing a relatively small amount of records (few thousand
perhaps).
For example a spreadsheet application such as Excel can be used as a flat file database. Each row in a
worksheet can be a record and each column, a field. The worksheet is effectively a table.
Everyday things like business contacts, customer lists and so on can be stored and used in a flat file
database.
But they do have some serious disadvantages when it comes to more than a few thousand records.
Page 5 of 136
Disadvantages
1. Potential Duplication
As more and more records are added to the database it becomes difficult to avoid duplicate records. This is
because there is no mechanism built in to the system to prevent duplication. Later you will see how
'primary keys' are used to prevent this.
2. Non-Unique Records
Notice that Mr. & Mrs. Jones have identical ID's. This is because the person producing this database
decided they may want to sort on identical telephone numbers and so has applied identical ID to the two
records. This is fine for that purpose, but suppose you only wanted to extract Mrs. Jones' record. Now it is
much more difficult.
3. Harder To Update
Suppose that this flat file database also stored their work place details - this will result in multiple records
for each person. Again, this is fine - but suppose Sandra Jones now wanted to be known as 'Sandra
Thompson' after re-marrying? This will have to be done over potentially many records and so flat file
updates are more error-prone than other methods
4. Inherently Inefficient
Consider a situation where the database now needs to hold an extra field to hold their email address. If
there are tens of thousands of records, there may be many people having no email address, but each
record in a flat file database has to have the same fields, whether they are used or not. Other methods
avoid this wasted storage.
Page 6 of 136
Relational Database
To overcome the limitations of a simple flat file database that has only a single table, another type of
database has been developed called a 'relational database'.
A relational database holds its data over a number of tables instead of one. Records within the tables are
linked (related) to records held in other tables.
The picture below shows two tables. The main one is called 'customers'. This contains almost the same
fields as we have seen in the flat file database. But there is one key difference - the city is now held in a
separate table called 'city'. The line between them shows there is a link (relationship) between a record in
the city table and records in the main table.
The line between the fields has a '1' on one side and the infinity sign on the other. In Access this indicates a
'one-to-many' relationship. This is described in more detail on the Entity Relationship Diagram.
A small relational database may only contain two tables whilst a large corporate database could contain
hundreds of tables.
Page 7 of 136
Advantages Of A Relational Database
Splitting data into a number of related tables brings many advantages over a flat file database. These
include:
In the previous example, the city data was gathered into one table so now there is only one record per
city. The advantages of this are
A language called SQL has been developed to allow programmers to 'Insert', 'Update', 'Delete', 'Create',
'Drop' table records. These actions are further refined by a 'Where' clause. For example
This SQL statement will extract record number 2 from the Customer table. Far more complicated queries
can be written that can extract data from many tables at once.
3. Better Security
By splitting data into tables, certain tables can be made confidential. When a person logs on with their
username and password, the system can then limit access only to those tables whose records they are
authorized to view. For example, a receptionist would be able to view employee location and contact details
but not their salary. A salesman may see his team's sales performance but not competing teams.
By having data held in separate tables, it is simple to add records that are not yet needed but may be in the
future. For example, the city table could be expanded to include every city and town in the country, even
though no other records are using them all as yet. A flat file database cannot do this.
Page 8 of 136
DBMS (Data Base Management System)
It’s a software that handles the storage, retrieval, and updating of data in a computer system.
A DBMS provides an environment that is both convenient and efficient to use when there is a large volume
of data and many transactions to be processed. Different categories of DBMS can be used, ranging from
small systems that run on personal computers to huge systems that run on mainframes.
Page 9 of 136
Benefits of DBMS:
A DBMS is responsible for processing data and converting it into information. For this purpose, the database
has to be manipulated, which includes querying the database to retrieve specific data, updating the
database, and finally, generating reports.
These reports are the source of information, which is, processed data. A DBMS is also responsible for data
security and integrity.
The benefits of a typical DBMS are as follows:
Data Storage
The programs required for physically storing data, handled by a DBMS, is done by creating complex data
structures, and the process is called data storage management.
Data Definition
A DBMS provides functions to define the structure of the data in the application. These include defining and
modifying the record structure, the type and size of fields, and the various constraints/conditions to be
satisfied by the data in each field.
Data Manipulation
Once the data structure is defined, data needs to be inserted, modified, or deleted. The functions, which
perform these operations, are also part of a DBMS. These functions can handle planned and unplanned data
manipulation needs. Planned queries are those, which form part of the application. Unplanned queries are
ad-hoc queries, which are performed on a need basis.
Data security is of utmost importance when there are multiple users accessing the database. It is required
for keeping a check over data access by users. The security rules specify, which user has access to the
database, what data elements the user has access to, and the data operations that the user can perform.
Data in the database should contain as few errors as possible. For example, the employee number for adding
a new employee should not be left blank. Telephone number should contain only numbers. Such checks are
taken care of by a DBMS.
Thus, the DBMS contains functions, which handle the security and integrity of data in the application. These
can be easily invoked by the application and hence, the application programmer need not code these
functions in the programs.
Recovery of data after a system failure and concurrent access of records by multiple users are also handled
by a DBMS.
Performance
Optimizing the performance of the queries is one of the important functions of a DBMS. Hence, the DBMS
has a set of programs forming the Query Optimizer, which evaluates the different implementations of a
query and chooses the best among them.
Page 10 of 136
Multi-User Access Control
At any point of time, more than one user can access the same data. A DBMS takes care of the sharing of data
among multiple users, and maintains data integrity.
The query language of a DBMS implements data access. SQL is the most commonly used query language. A
query language is a non-procedural language, where the user needs to request what is required and need
not specify how it is to be done. Some procedural languages such as C, Visual Basic, Pascal, and others
provide data access to programmers through these APIs and other tools.
Data Modelling
This shows that a data model can be an external model (or view), a conceptual model, or a physical model.
This is not the only way to look at data models, but it is a useful way, particularly when comparing models.
Conceptual Schema
Describes the semantics of a domain (the scope of the model). For example, it may be a model of the
interest area of an organization or of an industry. This consists of entity classes, representing kinds of
things of significance in the domain, and relationships assertions about associations between pairs of
entity classes. A conceptual schema specifies the kinds of facts or propositions that can be expressed using
the model. In that sense, it defines the allowed expressions in an artificial "language" with a scope that is
limited by the scope of the model. Simply described, a conceptual schema is the first step in organizing the
data requirements.
Page 11 of 136
Logical Schema
Describes the structure of some domain of information. This consists of descriptions of (for example)
tables, columns, object-oriented classes, and XML tags. The logical schema and conceptual schema are
sometimes implemented as one and the same.
Physical Schema
Describes the physical means used to store data. This is concerned with partitions, CPUs, table spaces, and
the like.
According to ANSI, this approach allows the three perspectives to be relatively independent of each other.
Storage technology can change without affecting either the logical or the conceptual schema. The
table/column structure can change without (necessarily) affecting the conceptual schema. In each case, of
course, the structures must remain consistent across all schemas of the same data model.
Database Schema
Database schema is the skeleton of database. It is designed when database doesn't exist at all and very
hard to do any changes once the database is operational. Database schema does not contain any data or
information.
A database schema defines its entities and the relationship among them. Database schema is a descriptive
detail of the database, which can be depicted by means of schema diagrams. All these activities are done
by database designer to help programmers in order to give some ease of understanding all aspect of
database.
Physical Database Schema: This schema pertains to the actual storage of data and its form of storage like
files, indices etc. It defines the how data will be stored in secondary storage etc.
Logical Database Schema: This defines all logical constraints that need to be applied on data stored. It
defines tables, views and integrity constraints etc.
Every database software provides the interface to design schemas and manipulate data through the query
processors.
Page 12 of 136
1.8.2 Relational Database Modelling
A relational database consists of at least two tables along with a definition of the relationships between
the two tables.
At this level of complexity, it is straightforward to keep the data consistent. The term used is 'data
integrity'. For example if a record in one table is deleted, then a related record in the other table may have
to be deleted as well because they share a relationship. If the deletion is not done properly then you end
up with 'orphan' records that have no relevance and are just taking up storage.
Another problem might be trying to insert data into a field of the wrong data type, for example inserting a
string into a Boolean field will cause an error.
What is needed is a piece of software that can keep track of all the rules implicit in the database and to
maintain data integrity.
The prime purpose of a relational database management system is to maintain data integrity. This means
all the rules and relationships between data are consistent at all times.
But a good DBMS will have other features as well.
These include:
A command language that allows you to create, delete and alter the database (data description
language or DDL)
A way of documenting all the internal structures that make up the database (data dictionary)
A language to support the manipulation and processing of the data (data manipulation language)
Support the ability to view the database from different viewpoints according to the requirements of
the user
Provide some level of security and access control to the data
The simplest RDBMS may be designed with a single user in mind e.g. the database is 'locked' until that
person has finished with it. Such a RDBMS will only cost a few hundred pounds at most and will have only a
basic capability.
On the other hand an enterprise level DBMS can support a huge number of simultaneous users with
thousands of internal tables and complex 'roll back' capabilities should things go wrong.
Obviously this kind of system will cost thousands along with a need to have professional database
administrators looking after it and database specialists to create complex queries for management and
staff.
Page 13 of 136
Data Dictionary:
A 'data dictionary' describes the structure and attributes of data 'items' to be used within a software
application (usually a database).
A data dictionary includes the names and descriptions of the tables and the fields contained in each table.
It also documents information about the data type, field length and other things such as validation.
The main purpose of the data dictionary is to provide metadata, or information about data. Technically, it
is a database about a database.
There is no one set standard in terms of layout or the level of detail to which a data dictionary should be
written.
Software development teams need a comprehensive data dictionary to refer to during the development
and maintenance of a new database. This is so that they are all working using the same data formats when
reading or writing data.
Page 14 of 136
Keys The primary and foreign keys for each table
Indexes Any field that has been indexed to improve search speed
Field size 15
Surname Text
Indexed
Field size: 12
HomeTelephone Text
Presence check
Page 15 of 136
Terminology Associated With A Relational Database Model
There are a lot of new terms to learn when you begin to cover the database section at AS level. Some of
these terms that you must understand and be able to use are entities and attributes. You must also
understand how to draw and interpret an entity relationship (E-R) diagram.
Entities
An Entity is a person, place, thing or concept about which data can be collected. Examples include
EMPLOYEE, HOUSE, and CAR
- a customer table
- an appointments table
Page 16 of 136
Attributes
Example
Database Relationships
- One-to-one
- One-to-many
- Many-to-many
Page 17 of 136
Diagram Name Description
Page 18 of 136
Designing Relationships
When designing or solving relationships for an E-R diagram, it is helpful to remember the following
information:
- The entities
- The attributes
- The entity relationships
Database Keys
- Primary key
- Secondary key
- Foreign key
- Compound primary Key
Primary Key
Many primary keys are single field values but more complex situations may use several attributes to define
a primary key. Then it is called a 'compound primary key'.
*Additional point
Primary keys do not have to be numbers; they can be anything that makes each record unique.
For example, a username-password table might have a fixed length 'hash' value as its primary key, like this:
ID username password
1dab223bffh joe ninety
Page 19 of 136
Foreign Key
A foreign key points to a record in another table whose primary key is the same value.
What is happening is that a copy of the primary key value in the City table is being stored in the customers
table. For example, a typical record entry looks like this:
Mr. & Mrs. Jones live in the city of Hull and the foreign key in each record contains '2'. This then points to
'Hull' in the city table whose primary key is also '2'.
Note that it’s quite common to have more than one record having the same foreign key.
This simply reflects the fact that a one-to-many relationship exists between the two tables.
Secondary Key
Primary key is the main way that records within a table are defined and sorted. But it is also useful to be
able to select certain category of records without having to use the primary key.
For example, with the customer records shown above perhaps a useful way to view records would be by
title. In which case a 'secondary key' is set up within the database. This secondary key indexes the records
according to title.
Page 20 of 136
The good thing about secondary keys is that the secondary index allows often-queried category of records
to be extracted far quicker. But the downside is that the indexes could make the database significantly
larger. So the database analyst has to carefully weigh up the benefit of adding secondary keys to the
database.
Secondary keys do not have to be single fields, they can be a combination of fields. In the example below a
secondary key is indexing records based on title and surname. so it would be a really quick query to extract
all people called 'Mr. Jones'
Normalization
Desired characteristics of a database include it being efficient in terms of storage and easy to maintain.
The first point, of storage, means redundant data should be avoided and the second point, of maintenance,
means that a good design will logically separate data into tables.
“a technique for designing relational database tables to minimize duplication of information and, in so
doing, to safeguard the database against certain types of logical or structural problems” (wikipedia.com)
For a database to be in first normal form (1NF), the following rules have to be met for each table in
the database
'Atomic' is the word used to describe a data item that cannot be broken down any further.
Page 21 of 136
Which of these tables are NOT in first normal form?
1.
2.
3.
4.
Comments:
Table 1. This is not in 1NF. There is no primary key defined and so this record cannot be guaranteed to be
unique. Also Full name is redundant - data is not atomic - as it is simply a combination of Firstname and
Surname.
Table 2. This is in at least 1NF. It has a primary key identified by the underline. The data is atomic. Each
field has a unique name. There are no repeat data.
Table 3. This is not in 1NF. It has a primary key, so it passes that test, data is atomic - tick in the box, but
the colour the shoe can come in is being repeated - and furthermore the fields have the same name - so
not in 1NF
Table 4. This is in 1NF as it meets all the rules for the first normal form.
Page 22 of 136
1NF Examples 2
Suppose a designer has been asked to compile a database for a fan club web site. Fans visit the web site to
find like-minded friends.
The entities to be stored are
This indicates that each band has many fans. Each person is a fan of only one group.
BAND FAN
The attributes of a fan are:
The attributes of band are:
FanID
BandID
firstname
band name
surname
musictype
email address(es)
The database needs to be in first normal form.
First Attempt
This is the first time this person has designed a database and is not really sure of how to go about it. He
designs the FAN table and loads it with the following records
He has correctly set up a primary key. He also used a foreign key to refer to the band. But this is not in 1NF
because Mary has two email addresses loaded into the email field. The data is not atomic. Loading data in
this way is also going to make it very difficult to extract email addresses. Also the data length of the email
field now has to be long enough to handle many email addresses, this is very inefficient and would be a
problem if exceeded.
Second Attempt
He soon realizes this is not a good idea. So then he decides to create two email fields
This is also a poor approach - note that email2 is not being used in Tom's record and so is causing wasted
storage, so not 1NF which seeks to avoid wasted / redundant data.
Another problem is what if a fan has many more emails? Adding more and more email fields will make the
wasted storage even worse.
Another problem is that the query to extract email addresses is far more complex than it needs to be as it
has to examine each email field.
Page 23 of 136
Solution
After trying out various ideas, he comes up with a good solution - create another entity called 'email' and
use a foreign key in that table to link the fan and email tables together. The ER diagram is as follows:
The ER diagram shows that each fan can have many emails, but an email can only belong to one fan.
The FAN and EMAIL table now look like this
FAN
Mary (FanID = 2) has two entries in the email table. There is no problem adding even more emails for her.
Extracting emails is now simple as there is only one email column. There is no wasted storage.
The tables are now in first normal form (1NF) as they obey the following rules
Page 24 of 136
Second Normal Form 2NF
Most tables tend to have a single-attribute (i.e. simple) primary key. Like this
CUSTOMER
But sometimes a table has a primary key made up of more than one attribute i.e. it has a compound
primary key.
CONCERT
The table above is using both the venue and artist as the compound primary key.
It is in this situation that the extra rule for second normal form comes in handy. The rule states
So inherently, any table that is already in 1NF and has a simple primary key is automatically in second
normal form as well.
Consider the Concert example above - this is NOT in second normal form. Notice the attribute called Style.
This is describing the style of artist - it has nothing to do with where the concert took place! And so its
value does not depend on EVERY part of the primary key, so the rule for second normal form is not being
met.
The reason for this rule is to ensure there is no redundant data being stored.
For example, let's add another Girls Aloud concert to the table
Notice that the 'girl band' value is being repeated and so is causing the database to be bigger than it needs
to be.
Of course there could be more than one attribute related to different parts of the primary key. Consider a
table like this:
Page 25 of 136
CONCERT
As before the Style attribute only depends on Artist, but now No1Hits also only depends on the Artist. This
table also includes City and this only depends on the Venue.
So to make this database into second normal form, four tables need to be created
CONCERT
STYLE
Style ID Style
001 Girl band
002 Solo artist
003 Rap
ARTIST
ArtistID Artist No1Hits StyleID
0112 Girls Aloud 20 001
0115 Leona Lewis 3 002
VENUE
Venue ID Venue City
005 Wembly London
006 NEC Birmingham
Summary
The rules for second normal form are
- It is already in 2NF
- There are no non-key attributes that depend on another non-key attribute
What this is trying to do is to spot yet another source of redundant data. If the value of an attribute can be
obtained by simply making use of another attribute in the table, then it does not need to be there. Loading
that attribute into another table and linking to it will make the database smaller.
CONCERT
Notice that the country could be obtained by referring to the City - if the concert was in London then you
know it is also in the UK - no need to look at the primary key!
So to make this database into third normal form, split the table as follows
CONCERT
CITIES
City Country
London UK
Bimingham UK
New York USA
The new table called CITIES has City as the primary key and country as an attribute. The Concert table has
City as a foreign key. So now you can obtain the country in which any particular concert took place and
there is no redundant data.
Page 27 of 136
3NF Examples
- It is already in 2NF
- There are no non-key attributes that depend on another non-key attribute
Example 1
CUSTOMER
This is not in strict 3NF as the City could be obtained from the Post code attribute. If you created a table
containing postcodes then city could be derived.
POSTCODES
PostCode City
SW7 2AP London
WC2H 7JY London
CV4 7AL Coventry
Example 2
The Description of what the certificate means could be obtained from the certificate attribute - it does not
need to refer to the primary key VideoID. So split it out and use the primary key / secondary key approach.
Page 28 of 136
Example 3
CLIENT
CINEMAS
CinemaID CinemaAddress
LON23 1 Leicester Square. London
COV2 34 Bramby St, Coventry
MAN4 56 Croydon Rd, Manchester
In this case the database is almost in 3NF - for some reason the Cinema Address is being repeated in the
Client table, even though it can be obtained from the Cinemas table. So simply remove the column from
the client table
Example 4
ORDER
In this case the cost of any order can be obtained by multiplying quantity by price. This is a 'calculated
field'. The database is larger than it needs to be as a query could work out the cost of any order. So to be in
strict 3NF you would remove the Cost column.
Benefits Of Normalization
1. The database does not have redundant data; it is smaller in size so less money needs to be spent on
storage.
2. Because there is less data to search through, it is much faster to run a query on the data.
3. Because there is no data duplication there is better data integrity and less risk of mistakes.
4. Because there is no data duplication there is less chance of storing two or more different copies of the
data.
5. Once change can be made which can instantly be cascaded across any related records.
Page 29 of 136
Problems With Normalization
1. You need to be careful with trying to make data atomic. Just because you can split some types
of data further, it isn't always necessarily the correct thing to do. For example, telephone
number might contain the code followed by the number 01234 567890. It wouldn't be sensible
to separate out these two items.
3. The more tables and the more complex the database, the slower queries can be to run
Page 30 of 136
1.8.3 Data Definition Language (DDL) And Data Manipulation Language
(DML)
One of the functions of a RDBMS is to provide a means of manipulating data within the database. This
includes operations such as
Insert
Delete
Update
Process data
This is the role of the data manipulation language (DML) built in to the system.
However, writing commands by hand can be slow and error prone. So to help with this, many systems
allow the user to set up a task by using 'Query by Example'. The users are presented with a graphical view
of the tables and they then use a number of icons such as 'filter' to manipulate the data. With some
systems you can drag fields graphically into appropriate areas on the screen to set up the query.
Behind the scenes, the QBE tool is compiling and running the required DML commands.
It means that users do not need to have a sophisticated understanding of database command languages in
order to use the database.
One of the basic functions of a RDBMS is to provide a method of creating a database from scratch. This is
the role of the data description language (DDL).
Field names
Data type
Data size / length
Validation rules
Default values
Presence check
Auto incrementing requirement
Indexing requirement
Primary key
As each table is defined and the relationships between them is established, then the overall design
emerges. This is called the 'Schema'.
It should be noted that a single large database may have several groups of people using it for different
purposes. In which case a different schema is needed for each of them.
Page 31 of 136
SQL
Structured Query Language (SQL) is used to perform function on a database. There are four main functions
that you should be familiar with: SELECT, INSERT, UPDATE, and DELETE.
Built in SQL commands are normally written in capital letters, making your statements easier to read.
However, you can get away without them.
To help us understand how these things work we are going to use a test data set. Databases are used in all
areas of the computer industry, but for the moment we are going to use a dataset that keeps track of
crooks in England, noting, names, gender, and date of birth, towns and numbers of scars. Take a look at the
crooks data table below:
This would display all the results. But what if we just want to display the names and number of scars of the
female crooks?
name numScars
Jane 1
Kelly 10
Marea 6
SELECT
The SELECT statement allows you to ask the database a question (Query it), and specify what data it
returns. We might want to ask something like Tell me the name and ages of all the crooks. Of course this
wouldn't work, so we need to put this into a language that a computer can understand: Structured Query
Language or SQL for short:
Page 32 of 136
SELECT name, DoB --what to return
FROM crooks --where are you returning it from
But suppose we wanted to filter these results, for instance: Tell me the ID, name and ages of all the crooks
who are male and come from Snape. We need to use another statement, the WHERE clause, allowing us to
give the query some criteria (or options):
Say the police knew that a crime had been committed by a heavily scarred woman (4+ scars), they want a
list of all the scarred women:
However, the police want to quickly sort through and see who is the most heavily scarred. We are going to
use an ORDER command:
ORDER BY numScars sorts your returned data into DESCending (big to small) or ASCending (small to big)
order
Page 33 of 136
INNER JOIN
We spoke earlier about how databases are great because they allow you to link tables together and
perform complex searches on linked data. So far we have only looked at searching one table.
When you use a social network such as Facebook you can often see a list of all your friends in the side bar
as well as details from your record such as your name and place of work. How did they find this data? They
would have searched for all the relationships that involve your ID, returning the names of people involved
AND returned values such as job title from your personal record.
This looks like using two queries: --return relationship information—return personal record information It
would be possible to do this, but it's far easier to use one query for both things.
Take a look at this example. The police want to know the name and town of a criminal (ID = 45) along with
all the descriptions of crimes they have performed:
SELECT name, town, description --select things to return (from different tables)
FROM crooks, crime --name tables that data comes from
WHERE crook.Id = crime.crimId --specify the link dot.notation means table.field. The Ids are the same
AND crook.Id = 45 --specify which crook you are looking at
ORDER BY date ASC --order the results by the oldest first
Similar to "> and <", but also checks for Id1 >= 123
>= and <=
equality Id1 <= 123
Page 34 of 136
DML (Data Manipulation Language)
Insert
Delete
Update
Process data
UPDATE
Database aren't always perfect and there may be times that we want to change the data inside our
database. For example in Facebook if someone is annoying you and you limit their access to your profile,
you'd update the access field from 'normal' to 'restricted'. Or if one of our crooks gets an additional scar
you'd have to update the numScars field.
Let's take a look at that example, where our crook Peter gains a scar on his right cheek. This was his initial
state:
name: Peter
numScars: 7
UPDATE crooks
SET numScars = 8
But we have a problem here, this statement updates all records to numScars = 8. This means that every
crook will now have 8 scars!
We need to specify which crooks we want to update by using a WHERE clause, you saw it earlier in the
SELECT example.
UPDATE crooks
SET numScars = 8
WHERE name = "Peter" --only updates those people who are called Peter
Page 35 of 136
INSERT
We might also want to add new things to our database, for example when we are adding new Criminal
records or a new friendship link on Facebook. To add new records we use the INSERT command with values
of the fields we want to insert:
Sometimes we might not want to insert all the fields, some of them might not be compulsory:
INSERT INTO crooks (ID, name, town) --specific fields to insert into
VALUES (999, 'Frederick', 'Shotley')
DELETE
Sometimes you might fall out with friends on Facebook so that you don't even want them to see your
restricted page. You'd want to delete your relationship (it's actually likely that Facebook retains the
connection but flags it as 'deleted', that isn't important here). The police might also find that a crook is in
fact innocent and then want to delete their criminal record. We need a DELETE command to do all of these
things, to permanently delete records from databases. Imagine that we find out that Geoff was framed and
he is completely innocent:
Page 36 of 136
Data Definition Language (DDL)
CREATE
You need to know what they all do (as listed above), though you only need to know how to implement the
CREATE TABLE command. Let's look at how we could have made the crooks table above:
ALTER
An ALTER statement in SQL changes the properties of a table in a relational database without the need to
access the table manually.
DROP
Dropping a table is like dropping a nuclear bomb. It is irreversible and is frowned upon in modern society.
By running this line of code, the table "crooks" will be removed from the database with no chance of it
being recovered unless backups have been previously made.
Page 37 of 136
Setting Primary Keys
Primary keys can be set after table creation via the alter statement.
To set a primary key made up of two columns during table creation you could do something such as this
Where the constraint name would be UserId and the table's primary key would be made up of the user_id
and the username columns.
This could also be done after table creation:
To set a foreign key or group of foreign keys during table creation, you could do something like this:
Where the primary key is "product_id" and all the other attributes are declared within the ( ) structure and
are followed by a comma.
Page 38 of 136
Page 39 of 136
9 A database has been designed to store data about salespersons and the products they have sold.
The table ShopSales was the first attempt at designing the database.
(a) State why the table is not in First Normal Form (1NF).
...................................................................................................................................................
...............................................................................................................................................[1]
Using the data given in the first attempt table (ShopSales), show how these data are now
stored in the revised table designs.
Table: SalesPerson
FirstName Shop
Table: SalesProducts
[3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) Explain why the SalesProducts table is not in Third Normal Form (3NF).
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
.......................................................................................................................................[1]
(ii) Describe two ways in which the Database Administrator (DBA) could use the DBMS
software to ensure the security of the student data.
1 ........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(iv) The DBMS has replaced software that used a file-based approach with a relational
database.
Describe how using a relational database has overcome the previous problems
associated with a file-based approach.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
CLASS(ClassID, Subject)
CLASS-GROUP(StudentID, ClassID)
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
.......................................................................................................................................[1]
(iii) Write an SQL script to display the StudentID and FirstName of all students who are
in the tutor group 10B. Display the list in alphabetical order of LastName.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
(iv) Write an SQL script to display the LastName of all students who attend the class whose
ClassID is CS1.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
Feature Description
Data security
[3]
A school stores a large amount of data that includes student attendance, qualification and contact
details. The school is setting up a relational database to store these data.
Describe three factors to consider when planning a backup procedure for the data.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[6]
9608/13/M/J/16 Page 45 of 136
(c) The database design has three tables to store the qualifications and grades each student has
attained. The following is a sample of the data from each table.
STUDENT
QUALIFICATION
STUDENT-QUALIFICATION
(i) Draw an Entity-Relationship (E-R) diagram to show the relationships between these
three tables.
[2]
(ii) State the type of relationship that exists between STUDENT and
STUDENT-QUALIFICATION.
.......................................................................................................................................[1]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(d) (i) The database will store each student’s date of birth.
Write an SQL script to add a date of birth attribute to the appropriate table.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) Write an SQL script to display the StudentID, Grade and DateOfAward for the
QualCode value of SC12.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(iii) Write an SQL script to display the FirstName and LastName and QualCode for all
STUDENT-QUALIFICATIONs for which the Grade value is A.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
9608/13/M/J/16 Page 47 of 136
1 Some shops belong to the Rainbow Retail buying group. They buy their goods from one or more
suppliers.
• a unique shop ID
• a single retail specialism (for example, food, electrical, garden).
• a unique supplier ID
• a similar single specialism recorded.
Rainbow Retail creates a relational database to record data about the shops and their suppliers.
The entity-relationship (E-R) diagram for the relationship between the SHOP and SUPPLIER tables
is shown.
SHOP SUPPLIER
(a) Explain what the degree of relationship is between the entities SHOP and SUPPLIER.
...................................................................................................................................................
...............................................................................................................................................[1]
SHOP-SUPPLIER(ShopID, SupplierID)
The SHOP–SUPPLIER table stores the suppliers that each shop has previously used.
(b) (i) Label the entities and draw the relationships to complete the revised E-R diagram.
SUPPLIER
[3]
SHOP
SUPPLIER
SHOP–SUPPLIER
[5]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(c) (i) Write an SQL query to display the shop ID and location of all shops with a ‘GROCERY’
specialism.
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(ii) The existing shop with ID 8765 has just used the existing supplier SUP89 for the first
time.
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
A number of nurses are based in Area A. These nurses always work on the same ward. Each
nurse has a unique Nurse ID of STRING data type.
A-NURSE A-WARD
...................................................................................................................................................
...............................................................................................................................................[1]
(b) A relational database is created to store the ward and nurse data. The two table designs for
Area A are:
A-WARD(WardName, NumberOfBeds)
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(c) In Area B of the hospital, there are a number of wards and a number of nurses.
A nurse can be asked to work in any of the Area B wards where their specialism matches with
the ward specialism.
B-NURSE B-WARD
(i) Explain what the degree of relationship is between the entities B-NURSE and B-WARD.
...........................................................................................................................................
.......................................................................................................................................[1]
B-WARD-NURSE( ............................................................................................................ )
Complete the attributes for the third table. Underline its primary key. [2]
B-NURSE B-WARD
B-WARD-NURSE
[2]
(i) Write an SQL query to display the Nurse ID and family name for all Area B nurses with a
specialism of ‘THEATRE’.
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(ii) Fatima Woo is an Area B nurse with the nurse ID of 076. She has recently married, and
her new family name is Chi.
UPDATE .............................................................................................................................
SET ....................................................................................................................................
WHERE ...............................................................................................................................
[3]
The database has three tables to store users’ details, and details of the images and text that they
post.
(a) (i) Explain how the relationship between the tables USER and PHOTO has been implemented.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) Draw the entity-relationship (E-R) diagram to show the relationships between the three
tables.
[2]
Use an example from the database WEBDATA to explain what is meant by referential
integrity.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
1NF ............................................................................................................................................
...................................................................................................................................................
2NF ............................................................................................................................................
...................................................................................................................................................
3NF ............................................................................................................................................
...................................................................................................................................................
[3]
(d) The following shows sample data from the USER table.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
Write an SQL script to add the field Country to the USER table.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
The database has three tables to store player’s details, dates when they have logged into the app
and in-app purchase details.
(a) Draw the entity-relationship (E-R) diagram to show the relationships between the three tables.
[2]
State what is meant by data integrity. Give an example of how the manager can ensure data
integrity in the PURPLEGAME database.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
Tick (3) one box to indicate whether this statement is true or false.
True False
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(d) (i) The following table shows some sample data for the PLAYER table.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]
Write an SQL script to add the DateOfBirth field to the PLAYER table.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) The software company decides to use a database to overcome the limitations of a
file-based system. Some of these limitations are addressed through the logical schema.
Name 1 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
Name 2 ..............................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
[4]
CUSTOMER(CustomerID, CompanyName)
(i) Identify the type of relationship that exists between the tables CUSTOMER and LICENCE.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Describe how the relationship is created between the tables CUSTOMER and LICENCE.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) The company needs a list of all software licences that have an expiry date on or before
31/12/2019.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(a) Moheem has been told a relational database addresses some of the limitations of a file-based
approach by reducing data redundancy.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Explain how a relational database can help to reduce data redundancy.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(b) Moheem uses a Database Management System (DBMS) to ensure the security and integrity
of the data.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
Feature 1 ...........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Feature 2 ...........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
© UCLES 2019 9608/12/M/J/19 Page 60 of 136
12
(iii) The DBMS provides software tools for the database developer.
Fill in the names of the missing software tools in the following statements.
3 A company uses a relational database, EMPLOYEES, to store data about its employees and
departments.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(b) Relationships are created between tables using primary and foreign keys.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
EMPLOYEE_DATA
DEPARTMENT_MANAGER DEPARTMENT
[3]
(d) Give three reasons why the EMPLOYEES database is fully normalised.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
(i) Write a Data Definition Language (DDL) statement to create the EMPLOYEES database.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Write a DDL statement to define the table EMPLOYEE_DATA, and declare EmployeeID
as the primary key.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(iii) Write a Data Manipulation Language (DML) statement to return the first name and last
name of all female employees in the department named Finance.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
7 A driving school teaches people how to drive cars. The school has a relational database,
DRIVING_SCHOOL, to store information about instructors, students, lessons and the cars used by
instructors.
INSTRUCTOR_CAR(InstructorID, Registration)
(a) Give two benefits to the driving school of using a relational database instead of a flat file.
1 .................................................................................................................................................
...................................................................................................................................................
2 .................................................................................................................................................
...................................................................................................................................................
[2]
INSTRUCTOR INSTRUCTOR_CAR
LESSON CAR
STUDENT
[4]
(c) The table shows some sample data for the table INSTRUCTOR.
Complete the Data Definition Language (DDL) statement to create the table INSTRUCTOR.
InstructorID VARCHAR(5),
FirstName VARCHAR(15),
LastName VARCHAR(15),
DateOfBirth DATE,
Level ………………………………………………………………………… ,
………………………………………………………………………… (InstructorID)
);
[3]
(d) The table STUDENT needs an additional field to store the student’s telephone number, for
example 012-3456.
Write a Data Definition Language (DDL) statement to add the new field to the table STUDENT.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(e) Write a Data Manipulation Language (DML) statement to return the date and time of all future
lessons booked with the instructor whose InstructorID is Ins01.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
© UCLES 2020 9608/11/M/J/20 Page 67 of 136
11
(a) Explain why this database is not in Third Normal Form (3NF). Refer to the tables in your
answer.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) Give an example from the database SOFTWARE_MANAGEMENT for each of the following
database terms.
Term Example
Entity
Foreign key
Attribute
[3]
(c) The company also develops computer games. They extend the relational database
SOFTWARE_MANAGEMENT by adding a new table. The new table, GAME_DEVELOPMENT,
stores details about the games and the software development teams creating them.
(i) Complete the Data Definition Language (DDL) statement to create the table
GAME_DEVELOPMENT.
GameName VarChar,
Genre VarChar,
………………………………………………………… ………………………………………………………… ,
DevelopmentStage VarChar,
ManagerID VarChar,
………………………………………………………… (GameName)
);
[5]
Complete the Data Manipulation Language (DML) statement to return the game name,
genre and team number of all games managed by the product manager with the first
name ‘James’ and the last name ‘Fitz’.
AND …………………………………………………………………………………………………
= …………………………………………………………………………………………………… ;
[3]
© UCLES 2020 9608/12/M/J/20 Page 69 of 136
10
6 Sheila creates a relational database for her hotel using a Database Management System (DBMS).
(a) Draw one line from each database term to its most appropriate description.
Primary key
A collection of records and fields
Attribute
The type of data that is being stored
[4]
(b) Identify three tasks that Sheila can perform using the DBMS developer interface.
1 ................................................................................................................................................
2 ................................................................................................................................................
3 ................................................................................................................................................
[3]
(c) Sheila creates the database HOTEL with the following table structure:
ROOM(RoomNumber, RoomType)
(i) The following table shows some sample data for the table ROOM.
RoomNumber RoomType
1 Standard
2 Double
3 Executive
4 Standard
Complete the Data Definition Language (DDL) statement to create the table ROOM.
RoomNumber Integer,
RoomType ................................................,
................................................ (RoomNumber)
);
[3]
Complete the Data Manipulation Language (DML) statement to add the details for room
number 5 to the table ROOM.
VALUES(......................................................................................................);
[2]
(iii) The table BOOKING needs an additional field to store the number of nights (for example,
3) a customer is staying.
Write a Data Definition Language (DDL) statement to add the new field to the table
BOOKING.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
© UCLES 2020 9608/13/M/J/20 Page 71 of 136
12
PJF
Interiors
(a) Describe how one typical feature of bitmapped graphics software was used to create the
logo.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(b) The finished logo is 160 pixels wide and 160 pixels high. The image has a colour depth of
3 bytes per pixel.
Calculate an estimate of the file size for the logo. Give your answer in kilobytes. Show your
working.
Working .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Answer ........................................................ KB
[3]
(c) Xiaoming needs to use his logo on his business card, on his website and on large display
boards. He is told that he should have created a vector graphic logo instead of a bitmapped
graphic logo.
Describe one benefit of creating a vector graphic logo instead of a bitmapped graphic logo.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(a) The health club employs a programmer to update the class booking system. The programmer
has to decide how to store the records. The choice is between using a relational database or
a file-based approach.
Give three reasons why the programmer should use a relational database.
1 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[6]
(b) The programmer decides to use three tables: MEMBER, BOOKING and CLASS.
Complete the Entity-Relationship (E-R) diagram to show the relationships between these
tables.
MEMBER CLASS
BOOKING
[2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[6]
Candidate key
Dataset organised in rows and columns;
the columns form the structure and the
rows form the content
Entity
Primary key
Attribute(s) in a table that link to the
primary key in another table to form a
relationship Table
Tuple
Attribute or combination of attributes that
is used to uniquely identify a record
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
The client
• The client names are unique.
A visit
• The company arranges a date for a visit to gather feedback from a client.
• A visit to a client never takes more than one day.
• Over time, the client receives many visits.
Staff (Interviewers)
• One or more staff attend the visit.
• If there is more than one staff member visiting, each performs a separate interview.
Interviews
• Each interview is classified as either ‘general’ or by some specialism, for example, marketing,
customer service or sales.
• A report is produced for each interview, InterviewText.
• Each interview is conducted by a single staff member.
The client, visit, staff and interview data will be stored in a relational database.
(a) (i) Underline the primary key for each table in the following suggested table designs.
VISIT(ClientName, VisitDate)
(ii) For each of the pairs of entities, A, B and C, draw the relationship between the two
entities.
A CLIENT VISIT
B VISIT INTERVIEW
C INTERVIEW STAFF
[3]
This text will be produced from the one or more interview texts obtained at the visit.
State how one or more of the given table designs can be changed to add this attribute.
...................................................................................................................................................
...............................................................................................................................................[1]
(c) Client ABC Holdings are now trading under the name of Albright Holdings.
(i) Write an SQL script to update this client’s record in the database.
UPDATE .............................................................................................................................
SET ....................................................................................................................................
WHERE ...............................................................................................................................
[3]
(ii) Describe why this update could cause problems with the existing data stored.
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(d) Write an SQL script to display the Staff ID of each member of staff who performed an interview
when they visited New Age Toys on 13/10/2016.
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(e) At present, all interviews are performed in the UK. Many clients now operate in other countries
in Europe. The company wants to perform interviews with the client’s staff in other countries.
Not all interview staff are willing to travel outside of the UK.
State how one or more of the table designs should be revised to store this information.
...................................................................................................................................................
...............................................................................................................................................[1]
The clinic stores patient, doctor and appointment data in a relational database.
(a) (i) Underline the primary key for each table in the following suggested table designs.
(ii) Complete the following entity-relationship (E-R) diagram for this design.
[2]
(b) The doctors are concerned that many patients make appointments but do not attend them.
Describe the changes to the table designs that could be made to store this information.
...................................................................................................................................................
...............................................................................................................................................[2]
A new table is designed to store the ID of the doctor who is able to work at each site.
DOCTOR-AVAILABILITY(DoctorID, Site)
DoctorID Site
098 SITE-A
074 SITE-A
117 SITE-B
098 SITE-B
033 SITE-B
(i) State what this data shows about the availability of the doctor with the ID of 098.
...........................................................................................................................................
.......................................................................................................................................[1]
(ii) Opening a new clinic in the neighbouring village will not require any additional table for
storing appointments. It will need a change to the existing appointment table design.
APPOINTMENT( ................................................................................................................
................................................................................................................................... ) [1]
(d) The doctor with the ID of 117 has recently been allocated a new DoctorID of 017.
(i) Write an SQL script to update this doctor’s record in the database.
UPDATE .............................................................................................................................
SET .....................................................................................................................................
WHERE ...............................................................................................................................
[3]
(ii) Describe why this update could cause problems with the existing data stored.
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(d) The bank uses a relational database, ACCOUNTS, to store the information about customers
and their accounts.
The database stores the customer’s first name, last name and date of birth.
The bank has several different types of account. Each account type has a unique ID number,
name (for example, regular or saving) and bonus (for example, $5.00, $10.00 or $15.00).
Each customer’s account has its own ID number and stores the amount of money the
customer has in that account.
The bank creates a normalised, relational database to store the required information. There
are three tables:
• CUSTOMER
• ACCOUNT_TYPE
• CUSTOMER_ACCOUNT
(i) Write the attributes for each table to complete the database design for the bank.
CUSTOMER( .......................................................................................................................
...........................................................................................................................................
.........................................................................................................................................)
ACCOUNT_TYPE( ..............................................................................................................
...........................................................................................................................................
.........................................................................................................................................)
CUSTOMER_ACCOUNT( ......................................................................................................
...........................................................................................................................................
.........................................................................................................................................)
[3]
(ii) Identify the primary key for each table that you designed in part (d)(i).
CUSTOMER .........................................................................................................................
ACCOUNT_TYPE ................................................................................................................
CUSTOMER_ACCOUNT ........................................................................................................
[2]
(iii) Identify one foreign key in one of the tables that you designed in part (d)(i).
Write the correct database term in the table for each definition.
Definition Term
(a) Anushka has a file-based storage system. She wants a relational database.
(i) Describe the features of a relational database that address the limitations of Anushka’s
file-based system.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(ii) The relational database design needs to be normalised. The following statements
describe the three stages of database normalisation.
groups of attributes.
For a database to be in Second Normal Form (2NF), it must be in 1NF, and contain no
For a database to be in Third Normal Form (3NF), it must be in 2NF, and all attributes
(b) The normalised relational database, SPORTS_CLUB, has the following table design.
MEMBER_SESSION(MemberID, SessionID)
SESSION_TRAINER(SessionID, TrainerID)
MEMBER SESSION
MEMBER_SESSION SESSION_TRAINER
TRAINER
[2]
(ii) Anushka first needs to create the database that she has designed.
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) The table shows some sample data for the table SESSION.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(iv) Write a Data Manipulation Language (DML) script to return the first name and last name
of all members who have Peak membership type.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(a) The hotel has two types of room: double and family. Each room has a unique room number.
The hotel stores information about the customers including their name, address and contact
details.
When a customer books a room, they give the start date and the number of nights they want
to stay. If a customer wants more than one room, each room must have a separate booking.
Each booking has an ID number.
The hotel creates a normalised, relational database to store the required information. There
are three tables:
• CUSTOMER
• ROOM
• BOOKING
(i) Complete the database design for the hotel by writing the attributes for each table.
CUSTOMER( .......................................................................................................................
...........................................................................................................................................
........................................................................................................................................ )
ROOM( ...............................................................................................................................
...........................................................................................................................................
........................................................................................................................................ )
BOOKING( .........................................................................................................................
...........................................................................................................................................
........................................................................................................................................ )
[3]
(ii) Identify the primary key for each table that you designed in part (a)(i).
CUSTOMER .........................................................................................................................
ROOM ..................................................................................................................................
BOOKING ...........................................................................................................................
[2]
(iii) Identify one foreign key in the tables that you designed in part (a)(i).
(b) The hotel wants to use a Database Management System (DBMS) to set up and manage the
database.
Describe, using examples, how the hotel can use the following DBMS tools:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[5]
Tick (✓) one box in each row to identify whether the script is an example of a Data Definition
Language (DDL) statement or a Data Manipulation Language (DML) statement.
2 A veterinary surgery cares for sick animals. The surgery has a file-based database that stores
data about the pets, their owners, and appointments made with the surgery.
(a) Explain the reasons why the surgery should upgrade their database.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(i) Give one reason why the database design for SURGERY is not in Third Normal Form
(3NF).
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) The database needs to be normalised to 3NF. A pet may have more than one owner and
an owner may have more than one pet.
The appointment table does not need to change and has been repeated below.
Give the name and attributes of three additional tables in 3NF. Identify the primary
key(s) in each table.
Table 1 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Table 2 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Table 3 ...............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(c) Part of the table APPOINTMENT is shown. The veterinary surgery uses Data Manipulation
Language (DML) statements to search for appointments.
(i) Identify the industry standard language that provides both DML and Data Definition
Language (DDL) statements.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Write a DDL statement to update the table APPOINTMENT and define AppointmentID
as the primary key.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) Complete the DML script to display the times and Pet IDs of all appointments on
02/02/2021 with staff ID of ‘JK1’, in descending order of time.
FROM APPOINTMENT
(d) New pet owners complete a paper-based form to register their pets at the surgery.
(i) Describe two verification checks that can be carried out when the data from the paper-
based form is entered into the database.
1 ........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(ii) Appointments can be booked between 09:00 and 16:50 on Monday to Friday.
Describe the ways in which the appointment date and time can be validated to make
sure they are reasonable.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(e) The surgery has five computers that can all access the database. A copy of the database is
stored centrally.
(i) Complete the description of this type of network model by filling in the missing terms.
the data for the surgery. The other computers are ......................................... . When a
(ii) The surgery wants to keep all data secure. The surgery network is not connected to the
Internet.
Identify two authentication techniques the surgery could use to restrict access to the
data.
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
5 A teacher uses a relational database, RESULTS, to store data about her students and their test
results.
(a) Describe the benefits to the teacher of using a relational database instead of a file-based
approach.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) The teacher sets up the RESULTS database using a Database Management System (DBMS).
(i) Explain the ways in which the developer interface of a DBMS will help the teacher set up
the database.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) The DBMS creates a data dictionary for the RESULTS database.
1 ........................................................................................................................................
2 ........................................................................................................................................
3 ........................................................................................................................................
[3]
(i) Complete the following table by giving one example of each database term from the
database RESULTS. Give both the field name and the corresponding table name.
Primary key
Foreign key
Attribute
[3]
(ii) Tick (✓) one box to identify whether the database RESULTS is in 1NF, 2NF or 3NF.
Justify your choice.
Justification: ......................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(iii) Complete the Data Manipulation Language (DML) script to display the Student ID, mark
and maximum marks for all tests with the topic of ‘Programming’.
(iv) The teacher wants to implement validation to make sure that all data entered into the
database RESULTS are reasonable.
Name three different methods of data validation that can be used in the RESULTS
database. Describe how each method will limit the data that can be entered in this
database.
Method 1 ...........................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
Method 2 ...........................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
Method 3 ...........................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
[6]
(d) The teacher stores the database on the desktop computer in her classroom.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Explain the ways in which the teacher can use data backup and disk mirroring to limit the
amount of data lost in the event of hardware failure.
Data backup
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Disk mirroring
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
© UCLES 2020 9608/12/O/N/20 Page 94 of 136
Page 95 of 136
Page 12 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2015 9608 12
table: SalesPerson
FirstName Shop
Nick TX
Sean BH
John TX
Page 96 of 136
Page 13 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2015 9608 12
table: SalesProducts
Nick refrigerator 2 WP
John toaster 3 GK
Page 97 of 136
MMM
1 mark for correct attributes in SalesProducts and Product tables and 1 mark for
correct identification of both primary keys [2]
Page 98 of 136
Page 7 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 12
(ii) One mark for identifying the way in which the data security is ensured, and one mark
for a further description.
Page 99 of 136
Page 8 Mark Scheme Syllabus Paper
Cambridge International AS/A Level – May/June 2016 9608 12
(iii) One mark per statement. Several statements may be on the same line. [4]
(iv) One mark per statement. Several statements may be on the same line. [4]
SELECT STUDENT.LastName
FROM STUDENT, CLASS-GROUP
WHERE ClassID = "CS1" // WHERE (ClassID = "CS1")
AND CLASS-GROUP.StudentID = STUDENT.StudentID;
One mark per statement. Several statements may be on the same line.
SELECT STUDENT.LastName
FROM STUDENT INNER JOIN CLASS-GROUP
ON CLASS-GROUP.StudentID = STUDENT.StudentID
WHERE ClassID = "CS1" // WHERE (ClassID = "CS1");
Data Dictionary
A file/table containing all the data about the
detail of the database design
(b) One mark for procedure point, one mark for justification. [6]
• How often should the data be backed up? e.g. at the end of each day
• Justification e.g. student’s progress may be edited each day and should not be lost
• What medium should the data be backed up to? e.g. external hard disk drive
• Justification e.g. it has large enough capacity
STUDENT STUDENT-
QUALIFICATION
QUALIFICATION
(d) (i) One mark per statement. Several statements may be on one line. [2]
(ii) One mark per statement. Several statements may be on one line. [3]
(iii) One mark per statement. Several statements may be on one line. [4]
Alternative answer:
1(b)(i) 3
• SHOP has primary key ShopID and SUPPLIER has primary key
SupplierID 1
• SHOP-SUPPLIER has primary key ShopID + SupplierID 1
• Both SHOP and SUPPLIER show foreign key as ‘None’ 1
• SHOP-SUPPLIER shows foreign key ShopID or SupplierID 1
• Explanation for SHOP-SUPPLIER foreign key describes ShopID or
SupplierID creating a link 1
1(a) Many-to-one 1
1(c)(iii) 2
B-NURSE B-WARD
B-WARD-NURSE
7(a)(i) 1 mark p er
e bullet 2
• UserName iss the primary key in USSER
• UserName iss (included as) a foreig
gn key in PH
HOTO
1NF
• No repeated groups of attributes
• All attributes should be atomic
• No duplicate rows
e.g.
• Validation rules
• Referential integrity
• Verification
• Input masks
• Setting data types
• Removing redundant data
• Backup data
• Access controls
• Audit trail
True False
9
• Commercial Licence
• Free Software Licence
• Shareware Licence
• Open Source Licence
2(b)(ii) 1 mark for each correct name, 1 mark for each matching description, max 2 4
marks per level
• External
• The individual’s view(s) of the database
• Conceptual
• Describes the data as seen by the applications making use of the
DBMS
• Describes the ‘views’ which users of the database might have
• Physical / Internal
• Describes how the data will be stored on the physical media
• Logical
• Describes how the relationships will be implemented in the logical
structure of the database
3(a)(i) 1 mark for each advantage, 1 mark for a valid expansion to max 2 × 2 4
Commercial Software
• The program is purchased for a fee
• It restricts the number of users/possible time period for use // Limited
number of installations allowed // Software key needed to install
• Source code not provided // source code protected / cannot be edited
• Anyone can purchase/download if agree to the terms
Shareware
• The program is free for a trial period // The (free) program may have
limited functionality // Need to purchase / enter details after trial
• Users do not have access to the source code // source code may not be
edited
• Users may re-distribute the software.
Freeware
• There is no charge for the software
• The software could still be copyrighted
• She can set her own restrictions on what a user can do with the
program
• Security ensures that data is safe from unauthorised access // safe from
loss
• Integrity ensures that data is accurate / consistent / up to date
For example:
• Access rights // User accounts
• Restrict actions (e.g. read / read-write) of specific users // unauthorised
users cannot access the database
• Views
• Restrict which parts of the database specific users can see
• Automatic Backup
• Create regular copies of data in case of loss
• Encryption
• Data is incomprehensible to unauthorised users
• Query Processor
• Developer Interface
By example:
• Identification of a primary key in a table
• Describing that primary key in another table as a foreign key
• LDM #300 The (denary) number 300 is loaded (into the register)
• LDD 300 The contents of address 300 are loaded (into the
register)
6(b) 1 mark for correctly naming register, 1 mark for appropriate role 4
• Program counter // PC
• Stores the address of the next instruction to be fetched
INSTRUCTOR INSTRUCTOR_CAR
LESSON CAR
STUDENT
• CREATE (line 1)
• INTEGER (line 6)
• PRIMARY KEY (line 7)
Term Example
CustomerID
Foreign Key
(in SOFTWARE_PURCHASED table)
Primary key
A collection of records and tables
Attribute
The type of data that is being stored
Foreign key
A unique identifier for each tuple
• Create a table
• Set up relationships between tables
• Create / design a form
• Create / design a report
• Create / design a query (NOT run a query)
7(a) 1 mark for each feature and 1 mark for further related expansion to max 2 2
• Colour select
• Select all pixels of the same colour
• Add text
• To show the name of the company
• Select
• ‘Grab’ a number of pixels to perform a task with/to
• Copy
• Replicate a number of pixels
9 (a) ONE mark for each reason and ONE mark for a further explanation. MAX THREE reasons.
• The database (generally) stores data only once / data need only be updated once
• Improved data consistency / integrity / associated data will be automatically
updated / easier to maintain the data / elimination of unproductive maintenance
• Security is improved
• Each application only has access to the fields it needs // different users can be given
different access rights
• Different users can be given different views of the data / data privacy is maintained
• So they do not see confidential information
[2]
Mark as follows:
1 mark for CREATE TABLE CLASS and ();
1 mark for PRIMARY KEY(ClassID)
1 mark for both ClassID VARCHAR(5),and Description VARCHAR(30),
1 mark for both StartDate DATE, and ClassTime TIME,
1 mark for NoOfSessions INT,
1 mark for AdultsOnly BIT,
[6]
Secondary key
Any object, person or thing about
which it is possible to store data
Candidate key
Primary key
Attribute(s) in a table that link to a
primary key in another table to form a
relationship
Table
[5]
7(a)(i) 1 Mark for correct primary key identified in both STAFF and CLIENT 3
STAFF(StaffID, StaffName, Department)
CLIENT(ClientName, Address, Town)
CLIENT VISIT
VISIT INTERVIEW
INTERVIEW STAFF
UPDATE CLIENT
SET ClientName = 'Albright Holdings'
WHERE ClientName = 'ABC Holdings';
• There may be records in the VISIT and INTERVIEW tables / other tables with
client name ABC Holdings
• The ClientName in the VISIT and INTERVIEW tables / other tables might not
be automatically updated
• Records in the VISIT and INTERVIEW tables / other tables will become
orphaned
7(a)(i) PatientID 2
(1)
DoctorID
7(a)(ii) 2
Special case for 1 mark only (only if no one to many relationships shown)
Many PATIENTs are seen by many DOCTORs
7(b) Two marks from: 2
Either:
• Add an attribute (for example Attended )
• To the appointment table // APPOINTMENT
Or:
• Add an attribute (for example AppointmentsMissed )
• To the patient table // PATIENT
UPDATE DOCTOR
SET DoctorID = '017'
WHERE DoctorID = '117';
4(d)(ii) 1 mark for 1 or 2 correct Primary Keys, 2 marks for 3 correct Primary Keys 2
CUSTOMER: CustomerID
ACCOUNT_TYPE: AccountID
CUSTOMER_ACCOUNT: ID
Table: CUSTOMER_ACCOUNT
Foreign Key: CustomerID / AccountID
Definition Term
4(a)(i) 1 mark per bullet point, max 3 marks from any group to max 4 4
For a database to be in Third Normal Form (3NF), it must be in 2NF, and all
attributes must be fully dependent on the primary key.
3(a)(ii) 1 mark for 1 or 2 correct Primary Keys, 2 marks for 3 correct Primary Keys 2
CUSTOMER: CustomerID
ROOM: RoomNumber
BOOKING: BookingID
Table: BOOKING
Foreign Key: CustomerID / RoomNumber
3(b) 1 mark per bullet point to max 2 plus 1 mark for suitable example for each 5
DBMS tool
Developer Interface
• To create user friendly features e.g. forms to enter new bookings
• To create outputs e.g. report of bookings on a given date
• To create interactive features e.g. buttons and menus
Query processor
• To create SQL/QBE queries
• To search for data that meets set criteria, e.g. all bookings for next
week
• To perform calculations on extracted data, e.g. number of empty rooms
tomorrow
3c 1 mark for at least two correct rows, 2 marks for all four correct rows 2
4(a) 1532 1
4(c) 101 1
4(d) 65 1
4(e) DE 1
• Privacy is improved
• … e.g. different views can be given to different users in the surgery.
E.g. the receptionists cannot see the pet’s medical notes
• More complex searches and queries can be executed … e.g. the staff in
the surgery can set up a query to only return the names of pets who
have not been seen for over a year
• Composite primary key made up of the primary keys of the other two
tables and no extra attributes in the linking table, for example,
PET_OWNER(PetID, OwnerID)
• Double entry // The data from the form is entered twice (by two different
people)
• and automatically compared
• Visual check // the data is compared (by two different people) after entry
• ... to the paper form manually
For example:
• Time can have range check to make sure it is within the opening hours
of 09:00 and 16:50
• Date can have existence check to compare against list of dates they are
open
The client-server model has one server that stores all the data for the
surgery. The other computers are clients. When a user requests data, a
request is sent to the server.
Product:
For example:
• Ensure product is of a high standard
• Ensure product meets requirements
• Ensure the product is delivered within time
• Ensure the product is delivered within budget
• Ensure product development is well-documented
• Ensure product is tested thoroughly // free of bugs
Colleagues:
For example:
• Need to be fair// do not show any prejudices
• To be supportive of colleagues
• Work together as a team
• Listen to each other’s ideas
• Assist colleagues in professional development
• Fully credit the work of other members of the team
• Make colleagues aware of expected standard ways of working
3(b) 1 mark for naming licence, 1 mark for description to max 2 per licence 4
• Commercial / proprietary...
• ...Software is sold for a fee therefore giving the client the income
• Shareware...
• ...Free for a trial period / limited features, and then users must pay for it
• Privacy is improved
• … e.g. the teacher can prevent student access to the data (using views
etc.)
For example:
• Table / entity names
• Field / attribute names
• Data types
• Validation
• Primary Keys
5(c)(iv) 1 mark for correct name and 1 mark for corresponding description applied to 6
RESULTS database. Max 2 per rule to max 3 rules
The descriptions are examples only, there are many correct answers
• Length check
• Limit the target grade to 1 character
• Range check
• The mark for each test must be between 0 and MaxMarks
• Existence check
• The test topic must be in a pre-existing list
• Presence check
• A mark must be entered / not null
• Format check
• The data for a class must be one digit followed by one letter, e.g.3A
• Type check
• The maximum marks for a test must be an integer
5(d)(ii) 1 mark per bullet point to max 3 for each, max 4 in total 4
Backup
• A copy of the RESULTS database is made
• ... at regular intervals // Sensible frequency of backups, e.g. daily, weekly
etc.
• ... and stored in a different location
• So, in the event of data loss, (most of) the original data may be
recovered.
Disk mirroring
• Data is written to different disks simultaneously
• So, in the event of hardware failure, a second identical copy is
immediately available.