Structured Query Language

Section A (compulsory), B1 and B2. Covers SQL and MySQL basics; DDL commands; DML and queries; Math and text functions; Date functions; Aggregate functions and grouping; Operations on relations.

Computer Science/Informatics Practices35 questions7 topics

About this unit

This unit teaches SQL (Structured Query Language), the standard language for working with relational databases, using MySQL as the example RDBMS. You will create and modify tables, insert and change data, and write queries that filter, sort, group and combine data. Built-in functions for numbers, text and dates, and aggregate functions such as SUM and COUNT, are a large part of the unit.

Key ideas

  • SQL commands fall into groups: DDL (structure), DML (data changes) and DQL (queries).
  • Data types such as INT, FLOAT, CHAR, VARCHAR and DATE, and constraints such as PRIMARY KEY, NOT NULL, UNIQUE and DEFAULT.
  • SELECT … FROM … WHERE with operators such as BETWEEN, IN, LIKE and IS NULL.
  • Single-row functions (math, text, date) return one value per row.
  • Aggregate functions work on groups of rows, with GROUP BY and HAVING.
  • Union, intersection, minus, Cartesian product and joins combine tables.

How to prepare

Practise writing queries on a small sample table and predicting their output by hand. Memorise the exact behaviour of functions such as ROUND, MOD, SUBSTRING, INSTR and COUNT(*) versus COUNT(column). Many questions show a query and ask for its output or the number of rows returned.

Topics in this chapter

Practice questions

Practise all 35 questions as a set

Practice this topic