Full Marks

A-level Computer Science Year 12 · Topic 15

Databases

Databases at A-level covers how to design, query and protect large collections of data.

We will use keys, entity relationship diagrams and indexing, and normalise data to third normal form.

Then we write S Q L to query, define and change data, keep data consistent with transactions and locking, and exchange data using X M L and J S O N.

In this topic

  1. 15.1Relational databases: flat files, keys, entity-relationship diagrams and indexingFree below · 29 questions
  2. 15.2Normalisation to third normal formOpen in Full Marks · 21 questions
  3. 15.3SQL queries: SELECT, WHERE, ORDER BY and JOINOpen in Full Marks · 24 questions
  4. 15.4SQL data definition and manipulation: CREATE, INSERT, UPDATE and DELETEOpen in Full Marks · 22 questions
  5. 15.5Referential integrity, transaction processing, ACID and record lockingOpen in Full Marks · 30 questions
  6. 15.6Capturing, selecting, managing and exchanging data: XML and JSONOpen in Full Marks · 25 questions

15.1 · Free notes

Relational databases: flat files, keys, entity-relationship diagrams and indexing

Diagram: Relational databases: flat files, keys, entity-relationship diagrams and indexing

Key points

In more detail

Practice

Relational databases: flat files, keys, entity-relationship diagrams and indexing: 10 questions

Pick an answer to check it, or open the answer for the explanation.

1. Which is a main disadvantage of storing data in a single flat file?

  1. Only one user can ever read the file
  2. Records cannot be searched
  3. Data is duplicated, risking inconsistency
  4. Every field needs a foreign key
Show answer

C: Data is duplicated, risking inconsistency. Repeated data (redundancy) must be changed in many places, so copies can disagree (inconsistency). Flat files can be searched and have no foreign keys.

2. Which property must a primary key have?

  1. It can repeat if other fields differ
  2. It is always a number
  3. It uniquely identifies each record and is never null
  4. It is made of exactly two fields
Show answer

C: It uniquely identifies each record and is never null. A primary key must identify exactly one record, so it must be unique and not null. It can be text and can be one field or several.

3. In Orders(OrderID, CustomerID, OrderDate), CustomerID is the primary key of the Customer table. What is CustomerID in Orders?

  1. Primary key
  2. Secondary key
  3. Foreign key
  4. Composite key
Show answer

C: Foreign key. An attribute that is the primary key of another table and is used to link the tables is a foreign key.

4. Students take many courses and each course has many students. How should this be implemented?

  1. Add CourseID to Student as a foreign key
  2. Store all courses in one Student field
  3. Use a link table holding StudentID and CourseID
  4. Make StudentID the primary key of Course
Show answer

C: Use a link table holding StudentID and CourseID. A many-to-many relationship is resolved with a link table. Its composite key is the two foreign keys, giving two one-to-many relationships.

5. Referential integrity is enforced. A user tries to delete a customer who still has rows in Orders. What should happen?

  1. It is blocked, or cascaded, so no orphan orders exist
  2. The CustomerID in Orders is reset to 0
  3. Orders keep a blank CustomerID
  4. The delete always succeeds and orders remain
Show answer

A: It is blocked, or cascaded, so no orphan orders exist. Referential integrity means every foreign key value must match an existing primary key, so orphan records are not allowed.

6. Which statement about indexing is correct?

  1. It speeds up both searching and inserting records
  2. It speeds up searches but needs extra storage and slows inserts
  3. It makes duplicate records impossible
  4. It removes the need for a primary key
Show answer

B: It speeds up searches but needs extra storage and slows inserts. An index is an ordered structure on an attribute. Searching is faster, but it uses space and must be updated on every insert, update or delete.

7. Enrolment(StudentID, CourseID, Grade) records one grade per student per course. Which is the best primary key?

  1. Grade
  2. CourseID
  3. StudentID and CourseID together
  4. StudentID
Show answer

C: StudentID and CourseID together. Neither ID alone is unique, as students take many courses and courses have many students. The pair is unique, so a composite key is needed.

8. Which attribute is the best primary key for a Student table?

  1. Date of birth
  2. A system-generated StudentID
  3. Surname
  4. Postcode
Show answer

B: A system-generated StudentID. A primary key must be unique and stable. Surnames, birthdays and postcodes can be shared or change, whereas an assigned ID is unique.

9. In an ER diagram, a line has a single bar at Customer and a crow's foot at Order. What does it show?

  1. A many-to-many relationship
  2. A one-to-one relationship
  3. One order has many customers
  4. One customer has many orders
Show answer

D: One customer has many orders. The crow's foot marks the 'many' end, so each customer can have many orders but each order belongs to one customer.

10. One teacher teaches many classes, but each class has one teacher. Where does the foreign key go?

  1. Both tables hold both IDs
  2. TeacherID in the Class table
  3. No foreign key is needed
  4. ClassID in the Teacher table
Show answer

B: TeacherID in the Class table. In a one-to-many relationship the foreign key goes in the 'many' table, so each Class row stores the TeacherID of its one teacher.

Keep going in Full Marks

Full Marks has 29 questions on Relational databases: flat files, keys, entity-relationship diagrams and indexing (19 more than here), set out in practice levels. You also get notes and 3D models for all 6 subtopics of Databases, plus games, timed exams and past papers.

On your exam board

Not in the AQA specification.

All A-level Computer Science Year 12 topics