Senior Secondary (HKDSE) · Information and Communication Technology

SQL: Practice Questions

5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on SQL.

10 questions27 marksFree, no account
Question 1
1 mark

You need to add a new student record into the Students table, which has columns StudentID, FirstName, LastName, and Major. The new student's details are: ID 'S001', FirstName 'Alice', LastName 'Smith', Major 'Computer Science'. Which SQL statement correctly inserts this data?

Question 2
1 mark

Consider a table named Customers with a column CustomerName. Which SQL query will retrieve all customers whose names start with the letter 'M'?

Question 3
1 mark

You are managing a database for an e-commerce platform. The Customers table currently has columns CustomerID, CustomerName, and Email. You need to add a new column named LastLoginDate to this table. This column should store dates and have a default value of '2023-01-01' for any existing or new records if no specific date is provided. Which SQL statement correctly performs this operation?

Question 4
1 mark

An existing table named Suppliers has columns SupplierID, SupplierName, ContactPerson, and FaxNumber. Due to a policy change, the FaxNumber column is no longer needed. Which SQL statement correctly removes the FaxNumber column from the Suppliers table?

Question 5
1 mark

Given a table named Products with columns ProductID, ProductName, Category, Price, and StockQuantity. Which SQL query will retrieve the ProductName and Price of all products whose price is between $$50$$ and $$100$$ (inclusive)?

Question 6
2 marks

Which specific SQL Data Manipulation Language (DML) command is used to add new rows (records) of data into an existing database table?

Write your answer out first, then check it against the worked solution.

Question 7
5 marks

Given a table Employees (EmployeeID, Name, Salary, DepartmentID) and Departments (DepartmentID, DepartmentName). Write an SQL query to list the Name of employees and their corresponding DepartmentName for all employees, and if a department name is not available, display 'No Department'.

Write your answer out first, then check it against the worked solution.

Question 8
5 marks

Given the tables: Orders (OrderID, CustomerID, OrderDate) and Customers (CustomerID, CustomerName, City). Write an SQL query to retrieve the CustomerName of all customers who have placed at least one order in the year $$2023$$.

Write your answer out first, then check it against the worked solution.

Question 9
5 marks

A company needs to set up a simple relational database to manage its IT assets and maintenance history.

You are tasked with defining the structure of the maintenance record table.

Table: Assets

  • AssetID (Primary Key, INTEGER)
  • AssetName (VARCHAR)
  • Location (VARCHAR)

(a) Write the SQL statement to create a new table named MaintenanceLog with the following specifications:

  • LogID (Primary Key, auto-incrementing INTEGER)
  • AssetID (INTEGER, linked to Assets table)
  • MaintenanceDate (DATE)
  • TechnicianName (VARCHAR, cannot be NULL)

(b) Write an SQL statement to insert a record into the MaintenanceLog table, assuming the AssetID is 101, the maintenance was done on '2024-05-15', and the technician was 'Sarah Lee'. (Assume LogID is handled automatically.)

(c) Later, the company decides that all maintenance records must include a unique service report number (up to 20 characters) which should be recorded in a new column called ReportCode. Write the SQL statement to add this new column to the MaintenanceLog table and ensure that every entry must have a unique code.

Write your answer out first, then check it against the worked solution.

Question 10
5 marks

An online retailer tracks product information in the Products table and sales transactions in the Transactions table:

Table: Transactions

  • TransactionID (INTEGER)
  • ProductID (INTEGER)
  • SaleDate (DATE)
  • UnitsSold (INTEGER)

(a) Write an SQL query to determine the total UnitsSold and the number of distinct transactions (COUNT(TransactionID)) for each month in the year \(2024\). Assume a built-in function MONTH() or similar is available to extract the month from SaleDate.

(b) Write an SQL query to list the ProductID and the total UnitsSold for products where the total units sold is less than \(500\) units. The results must be grouped by ProductID.

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, marked as you go.

Practise More