0% found this document useful (0 votes)
14 views

GCSE Computer Science QP On Relational Databases and SQL

Uploaded by

skilzababy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

GCSE Computer Science QP On Relational Databases and SQL

Uploaded by

skilzababy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

GCSE Computer Science QP on Relational Databases and SQL

Flat File and Relational Databases (8 Marks)

01 | Define a flat file database. (1 Mark)


01.1 | Explain one advantage of using a relational database over a flat
file database. (2 Marks)
0.12 | What is a primary key? (1 Mark)
01.3 | Why is it important to have a primary key in a database table? (2
Marks)
01.4 | Describe what a foreign key is in a relational database. (2 Marks)

Relational Database Tables

Let's create two tables: `Students` and `Courses`.

**Students Table**
- `StudentID` (Primary Key)
- `FirstName`
- `LastName`
- `DateOfBirth`
- `CourseID` (Foreign Key)

**Courses Table**
- `CourseID` (Primary Key)
- `CourseName`
- `CourseDescription`
- `StartDate`
- `EndDate`

**Records for Students Table**


| StudentID | FirstName | LastName | DateOfBirth | CourseID |
|-----------|-----------|----------|-------------|----------|
|1 | Alice | Smith | 2005-09-01 | 101 |
|2 | Bob | Brown | 2006-03-12 | 102 |
|3 | Carol | Johnson | 2005-07-23 | 101 |
|4 | David | Wilson | 2006-05-14 | 103 |
|5 | Eve | Davis | 2005-11-30 | 102 |
|6 | Frank | Miller | 2006-01-25 | 103 |

**Records for Courses Table**


| CourseID | CourseName | CourseDescription | StartDate |
EndDate |
|----------|----------------|------------------------|------------|------------|
| 101 | Mathematics | Algebra and Geometry | 2023-09-01 | 2024-
06-30 |
| 102 | Science | Physics and Chemistry | 2023-09-01 | 2024-06-
30 |
| 103 | English | Literature and Grammar | 2023-09-01 | 2024-06-
30 |

#### Questions Based on the Database (5 Marks)

1. **How many students are enrolled in the Science course?** (1 Mark)


2. **What is the `CourseName` for `CourseID` 101?** (1 Mark)
3. **Which student has `StudentID` 3?** (1 Mark)
4. **List the `FirstName` and `LastName` of all students enrolled in the
English course.** (2 Marks)

#### SQL Questions (12 Marks)

1. **Write an SQL query to retrieve all records from the `Students`


table.** (2 Marks)
2. **Write an SQL query to add a new student to the `Students` table.**
(2 Marks)
3. **Write an SQL query to update the `CourseID` for `StudentID` 2 to
103.** (2 Marks)
4. **Write an SQL query to delete the student with `StudentID` 6 from
the `Students` table.** (2 Marks)
5. **Write an SQL query to retrieve the names of students enrolled in
the Mathematics course.** (4 Marks)

### Mark Scheme

#### Flat File and Relational Databases

1. **Define a flat file database.**


- A database that stores data in a single table or worksheet. (1 Mark)

2. **Explain one advantage of using a relational database over a flat file


database.**
- Relational databases reduce data redundancy by organizing data
into multiple related tables. (1 Mark)
- They also improve data integrity and make it easier to update and
retrieve data. (1 Mark)

3. **What is a primary key?**


- A unique identifier for each record in a database table. (1 Mark)

4. **Why is it important to have a primary key in a database table?**


- It ensures each record can be uniquely identified. (1 Mark)
- It helps establish relationships between tables. (1 Mark)

5. **Describe what a foreign key is in a relational database.**


- A field in one table that uniquely identifies a row of another table or
the same table. (1 Mark)
- It is used to establish and enforce a link between the data in the two
tables. (1 Mark)

#### Questions Based on the Database


1. **How many students are enrolled in the Science course?**
- 2 students (Eve and Bob). (1 Mark)

2. **What is the `CourseName` for `CourseID` 101?**


- Mathematics (1 Mark)

3. **Which student has `StudentID` 3?**


- Carol Johnson (1 Mark)

4. **List the `FirstName` and `LastName` of all students enrolled in the


English course.**
- David Wilson, Frank Miller (2 Marks)

#### SQL Questions

1. **Write an SQL query to retrieve all records from the `Students`


table.**
```sql
SELECT * FROM Students;
```
(2 Marks)

2. **Write an SQL query to add a new student to the `Students` table.**


```sql
INSERT INTO Students (StudentID, FirstName, LastName, DateOfBirth,
CourseID)
VALUES (7, 'Grace', 'Lee', '2006-04-15', 101);
```
(2 Marks)

3. **Write an SQL query to update the `CourseID` for `StudentID` 2 to


103.**
```sql
UPDATE Students
SET CourseID = 103
WHERE StudentID = 2;
```
(2 Marks)

4. **Write an SQL query to delete the student with `StudentID` 6 from


the `Students` table.**
```sql
DELETE FROM Students
WHERE StudentID = 6;
```
(2 Marks)

5. **Write an SQL query to retrieve the names of students enrolled in


the Mathematics course.**
```sql
SELECT FirstName, LastName
FROM Students
WHERE CourseID = 101;
```
(4 Marks)

You might also like