OCR H446 A Level Computer Science · 1.3 Exchanging Data

Stretch tasks Databases

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick box tables in the exam.

  • 12 cards to sort into 4 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

12 cards, about 4 minutes

Task 5

Code Word

Guess the lesson's secret words. Every guess shows which letters are right.

  • A clue for every word
  • Tiles turn green, amber or grey after each guess
  • Fewer guesses win more points

3 words, about 4 minutes

Task 7

Bug Hunt

Two statements are true and one has a bug. Catch the bug before it gets away.

  • Three statements in every round
  • Tap the one with the mistake
  • Streaks win bonus points

5 rounds, about 4 minutes

Brain games

Train your brain on this lesson

Logic, memory and speed, built from this lesson's own key ideas. Win up to three diamonds in each game.

Logic

Odd One Out

Four tiles: three share a link and one does not. Spot the odd one out, then see what links the rest.

  • Three belong together, one does not
  • A hint shows the link, for fewer points
  • Quick answers and streaks win more

8 rounds, about 3 minutes

Memory

Memory Flash

Study the term cards, then they flip over. Find the card that goes with each clue, from memory.

  • Three levels: 3, 4 and 6 cards
  • Two tries to find each card
  • Streaks win bonus points

3 levels, about 4 minutes

Speed

Fact or Fib

Statements fly in one at a time. Is each one a fact or a fib? Decide fast.

  • Swipe, tap or use the arrow keys
  • Every fib comes with its fix
  • Streaks multiply your points

12 statements, about 3 minutes

The final challenge

City Run

Race a robot cat on inline skates through a neon cyber city, from Neon Station to the Hyper Tunnel. Every question is a row of neon gates across the tracks: skate through the one with the right answer, dodge the trains and barriers, and grab diamonds.

  • 20 questions from this lesson, in four parts of the city
  • Swipe, tap or use the arrow keys
  • Dodge trains and holograms, and jump crates and cones

20 questions, about 6 minutes

Bonus challenge

Neon Roll

Roll a glowing ball down an endless neon slope, past towers lit up with neon signs of Pixel the cat. Steer, jump the gaps and dodge the blocks. Questions from this lesson wait at gates along the way: every right answer keeps the ball rolling.

  • Questions from this lesson at every gate
  • Hold the arrow keys or a side of the slope to steer
  • 8 right answers win two diamonds, 15 win three

Endless, about 5 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Databases

Databases: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. Which key links one table to another?

    • Secondary key
    • Composite key
    • Foreign key
    • Primary key
  2. How is a many to many relationship implemented?

    • With a foreign key in each of the two tables
    • By merging the two tables
    • By making both primary keys composite
    • With a linking table holding foreign keys to both tables
  3. A table in third normal form has no transitive dependencies.

    • True
    • False
  4. A table has a composite key and a field that depends on only part of it. Which normal form does it break?

    • Second normal form
    • First normal form
    • Third normal form
  5. Which THREE anomalies does normalisation remove?

    Tick 3.

    • Indexing anomalies
    • Sorting anomalies
    • Update anomalies
    • Insertion anomalies
    • Deletion anomalies
  6. Order these clauses as they appear in an SQL query.

    Number these 1 to 4.

    • FROM
    • WHERE
    • ORDER BY
    • SELECT
  7. What does this query return?

    SELECT Name FROM Students
    WHERE Year = 12 AND Grade >= 7;
    • Every student in Year 12
    • Every student with a grade of exactly 7
    • The number of Year 12 students
    • The names of Year 12 students with a grade of at least 7
  8. UPDATE Students SET Grade = 9 with no WHERE clause changes only the first row.

    • True
    • False
  9. Which ACID property means a committed change survives a power cut?

  10. What is the cost of adding an index to a field?

    • Inserts, updates and deletes become slower
    • Searches on the field become slower
    • The table can no longer be sorted
    • The field can no longer be a key
  11. Two transactions each wait for a record the other has locked. What is this?

    • A transitive dependency
    • A deletion anomaly
    • Deadlock
    • Atomicity
  12. Which ACID property means every operation in a transaction succeeds, or none do?

    • Durability
    • Isolation
    • Consistency
    • Atomicity

Quiz Challenge, round 2: Quick Fire

  1. Explain why a database designer normalises tables. [2 marks]

  2. Describe the difference between a primary key and a foreign key. [2 marks]

  3. Explain why indexing every field of a table is a bad idea. [2 marks]

  4. Explain what isolation means for database transactions. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Describe the first three normal forms. [6 marks]

  2. Explain how the ACID properties protect a bank transfer between two accounts. [4 marks]

This or That: tick the right answer

  1. Where does the foreign key go in a one to many relationship?

    • On the one side
    • On the many side
  2. A field holds 'Maths, Physics, Art' for one student. Which normal form does this break?

    • Third
    • First
  3. Which makes searching on a field faster?

    • A foreign key on that field
    • An index on that field
  4. Which SQL clause filters groups after GROUP BY?

    • HAVING
    • WHERE
  5. What happens if DELETE FROM Students has no WHERE clause?

    • Nothing is deleted
    • Every row is deleted
  6. Which concurrency control avoids deadlock?

    • Record locking
    • Timestamp ordering
  7. Which ACID property keeps concurrent transactions from interfering?

    • Isolation
    • Durability
  8. Why might an analytics system denormalise its tables?

    • To remove redundancy
    • To make complex reads faster

Memory Match: match each term to its meaning

TermMeaning
A Composite key1 Resolves a many to many relationship
B Foreign key2 Committed changes survive a crash
C Linking table3 Links to the primary key of another table
D Transitive dependency4 Two transactions each waiting for the other's lock
E Deadlock5 A primary key made of two or more fields
F Durability6 A non key field depending on another non key field

Sort It: tick one box in each row

Which ACID property does each statement describe?

StatementAtomicityConsistencyIsolationDurability
A failed transaction is rolled back completely
One transaction cannot see another's unfinished changes
The database moves from one valid state to another
Every operation in a transaction succeeds, or none do
A crash just after a commit loses nothing
A transaction cannot leave data that breaks a constraint
Committed changes survive a power cut
Changes are written to non volatile storage
A transfer cannot debit one account and stop before the credit
The result matches running them one at a time in some order
Concurrent transactions do not interfere
Every rule and constraint still holds afterwards

Code Word: write the word that fits each clue

  1. Something data is stored about, which becomes a table. (6 letters)

  2. A structure that maps field values to records to speed up searches. (5 letters)

  3. Two transactions each waiting for a record the other has locked. (8 letters)

Link Up: find the three groups

These 12 tiles make 3 groups of 4. Write each group in the table, and what links its tiles.

  • GROUP BY
  • Consistency
  • Isolation
  • HAVING
  • Secondary
  • SELECT
  • Composite
  • Foreign
  • WHERE
  • Atomicity
  • Primary
  • Durability

Bug Hunt: tick the statement that is wrong

In each set, two statements are true and one has a mistake in it.

    • A foreign key holds the primary key of another table.
    • A many to many relationship can be built directly with two foreign keys.
    • A primary key uniquely identifies each record.
    • Third normal form allows one non key field to depend on another.
    • First normal form has no repeating groups.
    • Second normal form removes partial dependencies on a composite key.
    • An index makes searches on a field faster.
    • Every index must be updated when records change.
    • An index makes inserts and updates faster too.
    • Isolation means a transaction is saved even if the power fails.
    • Durability means committed changes survive a crash.
    • Atomicity means all of a transaction happens or none of it does.
    • WHERE filters rows before they are grouped.
    • HAVING filters the groups made by GROUP BY.
    • DELETE with no WHERE clause deletes only the first row.

Brain game: Odd One Out

Three tiles in each set share a link. Tick the odd one out, then write what links the other three.

    • GROUP BY
    • HAVING
    • SELECT
    • Atomicity

    What links the other three?

    • Consistency
    • Atomicity
    • Primary
    • Durability

    What links the other three?

    • Secondary
    • Composite
    • WHERE
    • Primary

    What links the other three?

    • GROUP BY
    • SELECT
    • WHERE
    • Atomicity

    What links the other three?

    • Isolation
    • SELECT
    • Atomicity
    • Durability

    What links the other three?

    • HAVING
    • Secondary
    • Foreign
    • Primary

    What links the other three?

Brain game: Memory Flash, on paper

Which term means this? Write your answer from memory.

  1. A non key field depending on another non key field

  2. Resolves a many to many relationship

  3. Committed changes survive a crash

  4. Links to the primary key of another table

  5. Two transactions each waiting for the other's lock

  6. A primary key made of two or more fields

Brain game: Fact or Fib

Tick Fact if the statement is true and Fib if it is not.

  1. Isolation means a transaction is saved even if the power fails.

    • Fact
    • Fib
  2. An index makes inserts and updates faster too.

    • Fact
    • Fib
  3. Third normal form allows one non key field to depend on another.

    • Fact
    • Fib
  4. An index makes searches on a field faster.

    • Fact
    • Fib
  5. DELETE with no WHERE clause deletes only the first row.

    • Fact
    • Fib
  6. Durability means committed changes survive a crash.

    • Fact
    • Fib
  7. A many to many relationship can be built directly with two foreign keys.

    • Fact
    • Fib
  8. UPDATE Students SET Grade = 9 with no WHERE clause changes only the first row.

    • Fact
    • Fib
  9. Atomicity means all of a transaction happens or none of it does.

    • Fact
    • Fib
  10. A primary key uniquely identifies each record.

    • Fact
    • Fib
  11. A foreign key holds the primary key of another table.

    • Fact
    • Fib
  12. WHERE filters rows before they are grouped.

    • Fact
    • Fib

City Run

City Run is a race through a neon cyber city, played on screen. It asks 20 of the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.

Neon Roll

Neon Roll is a ball rolling down an endless neon slope, played on screen. Every right answer keeps it rolling. It asks the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.

Answers

Round 1: Quiz Blitz

  1. Foreign key A foreign key is a field holding the primary key of another table, which forms the link.
  2. With a linking table holding foreign keys to both tables A many to many relationship cannot be built directly, so a linking table sits between the two.
  3. True In 3NF no non key attribute depends on another non key attribute: each depends on the key, the whole key and nothing but the key.
  4. Second normal form 2NF demands that every non key attribute depends on the whole of the primary key.
  5. Update anomalies; Insertion anomalies; Deletion anomalies Normalisation stops copies of a fact disagreeing, records needing unrelated data, and deletions destroying unrelated facts.
  6. SELECT → FROM → WHERE → ORDER BY Choose the fields, name the table, filter the rows, then sort the result.
  7. The names of Year 12 students with a grade of at least 7 Both conditions must be true, and >= includes 7 itself.
  8. False Without WHERE, UPDATE changes every row in the table, one of the most damaging mistakes in practice.
  9. durability Committed changes are written to non volatile storage, so they survive a crash.
  10. Inserts, updates and deletes become slower The index must be updated on every write, and it takes extra storage.
  11. Deadlock Neither can go on until the other lets go, so both are stuck.
  12. Atomicity Atomicity treats the transaction as one indivisible unit, so a transfer cannot stop halfway.

Round 2: Quick Fire

    • It removes redundancy, so each fact is stored once
    • It prevents update, insertion and deletion anomalies
    • It saves storage
    Model answer

    Normalising removes redundancy, so each fact is stored only once, which prevents update, insertion and deletion anomalies.

    • A primary key uniquely identifies each record
    • A foreign key holds the primary key of another table, linking them
    Model answer

    A primary key uniquely identifies each record in its table. A foreign key is a field that holds the primary key of another table, which links the two tables.

    • Every index must be updated on each write, so writes slow down
    • Each index takes extra storage
    • Fields that are rarely searched gain nothing
    Model answer

    Every index must be updated whenever a record is inserted, changed or deleted, so writes become slower, and each index takes extra storage.

    • Transactions running at the same time do not interfere
    • The result is as if they had run one after another
    Model answer

    Transactions running at the same time do not interfere with each other, so the result is the same as if they had run one after another.

Round 3: Big Think

    • 1NF has no repeating groups
    • In 1NF every field holds a single atomic value
    • In 2NF every non key attribute depends on the whole key
    • 2NF removes partial dependencies on part of a composite key
    • In 3NF no non key attribute depends on another non key attribute
    • The key, the whole key and nothing but the key
    Model answer

    In first normal form there are no repeating groups and every field holds a single atomic value. In second normal form the table is in 1NF and every non key attribute depends on the whole key, so there are no partial dependencies on part of a composite key. In third normal form the table is in 2NF and no non key attribute depends on another non key attribute, so there are no transitive dependencies: every attribute depends on the key, the whole key and nothing but the key.

    • Atomicity: the debit and the credit both happen, or neither does
    • Consistency: the database moves from one valid state to another
    • Isolation: transfers running at the same time cannot interfere
    • Durability: once committed, the transfer survives a crash
    Model answer

    Atomicity means the debit and the credit both happen or neither does, so money cannot vanish halfway. Consistency means the database moves from one valid state to another, with the total balance unchanged. Isolation means two transfers running at the same time cannot interfere with each other. Durability means that once the transfer is committed it survives a crash or power cut.

This or That

  1. On the many side Each record on the many side holds the key of the one record it belongs to.
  2. First 1NF needs atomic values, one value per field. A list in a field is a repeating group.
  3. An index on that field An index maps field values to record locations, so the whole table need not be scanned.
  4. HAVING WHERE filters rows before grouping. HAVING filters the groups that GROUP BY produces.
  5. Every row is deleted Without a WHERE clause the command applies to every row, which is why it is so dangerous.
  6. Timestamp ordering Timestamps order the transactions, so none waits forever, though some are restarted. Locks can leave two transactions waiting for each other.
  7. Isolation Isolation makes the result match some sequential order. Durability is about surviving a crash.
  8. To make complex reads faster Fewer tables mean fewer joins, so queries run faster. The price is the redundancy that normalisation removes.

Memory Match

  • A 5 Composite key: A primary key made of two or more fields
  • B 3 Foreign key: Links to the primary key of another table
  • C 1 Linking table: Resolves a many to many relationship
  • D 6 Transitive dependency: A non key field depending on another non key field
  • E 4 Deadlock: Two transactions each waiting for the other's lock
  • F 2 Durability: Committed changes survive a crash

Sort It

  1. Atomicity A failed transaction is rolled back completely Rolling back everything keeps the transaction all or nothing.
  2. Isolation One transaction cannot see another's unfinished changes Unfinished work stays hidden from other transactions.
  3. Consistency The database moves from one valid state to another Consistency means every rule still holds after the transaction.
  4. Atomicity Every operation in a transaction succeeds, or none do All or nothing is atomicity.
  5. Durability A crash just after a commit loses nothing Once committed, the change is safe whatever happens next.
  6. Consistency A transaction cannot leave data that breaks a constraint Consistency keeps the data valid.
  7. Durability Committed changes survive a power cut Durability means a commit is permanent.
  8. Durability Changes are written to non volatile storage Writing to non volatile storage is how durability is guaranteed.
  9. Atomicity A transfer cannot debit one account and stop before the credit Atomicity makes the transfer one indivisible unit.
  10. Isolation The result matches running them one at a time in some order Isolation makes concurrent transactions behave as if they ran in sequence.
  11. Isolation Concurrent transactions do not interfere Isolation keeps transactions running at the same time apart.
  12. Consistency Every rule and constraint still holds afterwards A transaction may not leave the database breaking its own rules.

Code Word

  1. ENTITY Something data is stored about, which becomes a table.
  2. INDEX A structure that maps field values to records to speed up searches.
  3. DEADLOCK Two transactions each waiting for a record the other has locked.

Link Up

  • SQL keywords SELECT; WHERE; GROUP BY; HAVING
  • ACID properties Atomicity; Consistency; Isolation; Durability
  • Types of key Primary; Foreign; Composite; Secondary

Bug Hunt: the wrong statement, and why

  1. A many to many relationship can be built directly with two foreign keys. It needs a linking table holding foreign keys to both tables.
  2. Third normal form allows one non key field to depend on another. That is a transitive dependency, which 3NF removes: every non key field depends only on the key.
  3. An index makes inserts and updates faster too. Every write must also update the index, so inserts, updates and deletes get slower.
  4. Isolation means a transaction is saved even if the power fails. That is durability. Isolation means concurrent transactions do not interfere with each other.
  5. DELETE with no WHERE clause deletes only the first row. Without WHERE, DELETE removes every row in the table.

Odd One Out

  1. Atomicity is the odd one out: it goes with ACID properties. The other three: SQL keywords.
  2. Primary is the odd one out: it goes with Types of key. The other three: ACID properties.
  3. WHERE is the odd one out: it goes with SQL keywords. The other three: Types of key.
  4. Atomicity is the odd one out: it goes with ACID properties. The other three: SQL keywords.
  5. SELECT is the odd one out: it goes with SQL keywords. The other three: ACID properties.
  6. HAVING is the odd one out: it goes with SQL keywords. The other three: Types of key.

Memory Flash

  1. Transitive dependency A non key field depending on another non key field
  2. Linking table Resolves a many to many relationship
  3. Durability Committed changes survive a crash
  4. Foreign key Links to the primary key of another table
  5. Deadlock Two transactions each waiting for the other's lock
  6. Composite key A primary key made of two or more fields

Fact or Fib

  1. Fib Isolation means a transaction is saved even if the power fails. The fix: That is durability. Isolation means concurrent transactions do not interfere with each other.
  2. Fib An index makes inserts and updates faster too. The fix: Every write must also update the index, so inserts, updates and deletes get slower.
  3. Fib Third normal form allows one non key field to depend on another. The fix: That is a transitive dependency, which 3NF removes: every non key field depends only on the key.
  4. Fact An index makes searches on a field faster.
  5. Fib DELETE with no WHERE clause deletes only the first row. The fix: Without WHERE, DELETE removes every row in the table.
  6. Fact Durability means committed changes survive a crash.
  7. Fib A many to many relationship can be built directly with two foreign keys. The fix: It needs a linking table holding foreign keys to both tables.
  8. Fib UPDATE Students SET Grade = 9 with no WHERE clause changes only the first row. The fix: Without WHERE, UPDATE changes every row in the table, one of the most damaging mistakes in practice.
  9. Fact Atomicity means all of a transaction happens or none of it does.
  10. Fact A primary key uniquely identifies each record.
  11. Fact A foreign key holds the primary key of another table.
  12. Fact WHERE filters rows before they are grouped.