SQL has two categories. Before writing any query, it helps to know which one you're in.
Commands that define or create the structure of the database itself.
Commands that work with the data inside the tables.
Every field in a CREATE TABLE statement needs a data type. AQA accepts a range of sensible types — these are the most useful ones to know.
| Data Type | Used For | Example Value | Notes |
|---|---|---|---|
| INT | Whole numbers | 42 | Also accepted: SMALLINT, TINYINT, INTEGER |
| VARCHAR(n) | Text up to n characters | 'Smith' | n is optional but good practice. Also: CHAR(n) |
| DATE | Date values | '29/09/2024' | Always use quote marks around dates in queries |
| DECIMAL / FLOAT | Numbers with decimal points | 19.99 | Also accepted: REAL, NUMERIC, MONEY |
| BOOLEAN | True or False | TRUE | Rarely tested directly in SQL questions |
Facility(FacilityID, Description, MaxPeople, PricePerHour)
SELECT retrieves data from a table. There are four clauses — always written in this order, one per line:
When data comes from two tables, list both in FROM — and you must include a linking condition in WHERE to join them via their shared key.
Book (BookID, Title, Author, Price, Category, Publisher)
Property(PropertyID, HouseNum, Street, Area, Postcode, Bedrooms, Bathrooms, AskingPrice, SellerID)
Buyer(BuyerID, Title, Forename, Surname, Telephone, DesiredArea, MinBedrooms, MaxPrice)
INSERT adds a new record to a table. You specify the table, the fields, and the values to insert.
Product(ProductID, Description, QuantityInStock, SupplierID)
Sale(SaleID, CustomerID, SaleDate)
SaleLine(SaleID, ProductID, QuantitySold)
UPDATE modifies the value of a field in existing records. It has three clauses — always in this order:
Product(ProductID, Description, QuantityInStock, SupplierID)
DELETE removes records from a table. It's the simplest DML command — just two clauses.
Film(FilmID, FilmName, Duration, Certificate)
Showing(ShowingID, ScreenNumber, FilmID, ShowTime, ShowDate)
CREATE TABLE Name (
Field1 Type PRIMARY KEY,
Field2 Type,
Field3 Type
)
SELECT Field1, Field2 FROM Table1, Table2 WHERE Table1.Key = Table2.Key AND Field = 'value' ORDER BY Field DESC
INSERT INTO Table (F1, F2, F3) VALUES (123, 'text', 'date')
UPDATE TableName SET Field = Field - 3 WHERE IDField = value
DELETE FROM TableName WHERE Field = 'value'