igcse-8-databases-2021
igcse-8-databases-2021
Imagine you have been tasked to create a database for a School assessment/reports system.
Identify the fields and datatypes you anticipate needing for this scenario. It may help to
imagine example outputs/printouts the system may require.
Relational databases
Relational databases
The power of
databases comes
from being able to
link information from
one table to related
information in other
tables.
Foreign key
Links to the primary key
of an alternate table.
Composite key
Multiple fields being
combined to act as the
primary key.
Relationship types
Normalising data
Normalising data
Consider the following data
StudentID Name Subjects Teachers Grades
101 Alex Physics, Chemistry Murdoch, Lewis 5, 6
103 Elizabeth Java, Math Baumgarten, 7, 6
Wilson
102 Brian Math, English Wilson, Pegg 3, 4
1st normal form
Each column must contain only one value.
Address records are a good example. Is everything below really dependent on the primary key?
https://shinesolutions.com/2018/01/08/falsehoods-programmers-believe-about-names-with-
examples/
Software should be built to meet your requirements while trying to anticipate strange
situations. Context remains important. Address edge cases in some reasonable way.
Exercise
Previously you created a list of fields & data types for a School assessment/reporting system.
We just saw a similar example in the most recent slides. Using the principles of normalisation,
how would you extend this example to include:
● Information on each individual assessment and
● Information on each student's achievement in each individual assessment
SQL: Structured query language
SQL databases
SQLite3
Download and install the DB Browser for SQLite
https://sqlitebrowser.org/
SQL: Creating a table
The rule:
CREATE table (
field datatype,
field datatype,
...
PRIMARY KEY (field, ...)
);
SQL: Creating a table
Examples
INSERT INTO table (field, field, ...) VALUES (value, value, ...);
Examples:
Get records that match where two fields have set values.
SELECT … FROM table WHERE field = value AND field = value;
Example:
Be careful of your WHERE clause. Leave it out and you will change EVERY RECORD. Test it
with a SELECT before using it to UPDATE.
SQL: Deleting records
The rule:
Example:
Be careful of your WHERE clause. Leave it out and you will change EVERY RECORD. Test it
with a SELECT before using it to UPDATE.
igcse "query-by-example"
igcse "query-by-example"
https://github.com/paulbaumgarten/gcse-query-tool
igcse "query-by-example"
Challenge
Solve the murder!
There's been a Murder in SQL City!
https://mystery.knightlab.com/
Tasker
tasker.db