Study resource
Structured Query Language (SQL) revision notes
Study Structured Query Language (SQL) with curriculum-aligned Revision Notes resources, practice links, and exam-focused support.
At a glance
revision notes
Resource type
Topic
Structured Query Language (SQL)
Revision notes
SQL Operations on Relational Database Tables
Purpose of SQL
Structured Query Language (SQL) is used to work with data in relational databases. For this topic, the key skills are defining a database table and using SQL to retrieve, insert, update and delete data. These operations can involve one table or multiple tables.
Defining a table
A table can be defined with
CREATE TABLE. The definition gives the table a name and specifies its columns and suitable data types.sql CREATE TABLE Student ( StudentID INTEGER, StudentName VARCHAR(50), YearGroup INTEGER );This statement defines a table called
Studentwith three columns. The semicolon marks the end of the SQL statement.Retrieving data
SELECTretrieves data.FROMidentifies the table, andWHERErestricts the rows considered by the condition.sql SELECT StudentName, YearGroup FROM Student WHERE YearGroup = 12;To retrieve data using multiple tables, include the tables in the query and specify how related rows should be matched. For example:
sql SELECT Student.StudentName, Course.CourseName FROM Student JOIN Course ON Student.CourseID = Course.CourseID;The selected columns identify the required data, while the
ONcondition gives the relationship used to match rows from the two tables.Inserting data
INSERT INTOadds a row to a table. The listed columns correspond to the values in theVALUESlist.sql INSERT INTO Student (StudentID, StudentName, YearGroup) VALUES (101, 'Aisha Khan', 12);The order and meaning of the values must match the listed columns.
Updating data
UPDATEchanges existing data.SETgives the new value, andWHEREidentifies which rows are changed.sql UPDATE Student SET YearGroup = 13 WHERE StudentID = 101;The
WHEREcondition is important because it limits the update to the intended row or rows.Deleting data
DELETE FROMremoves rows from a table.sql DELETE FROM Student WHERE StudentID = 101;Again,
WHEREidentifies the rows to remove. Omitting or incorrectly writing the condition can cause more rows than intended to be deleted.Common errors
- Confusing
UPDATE, which changes existing rows, withINSERT, which adds a new row. - Using
DELETEwhen the task requires changing a value. - Forgetting the
WHEREcondition when only particular rows should be changed or removed. - Selecting columns from multiple tables without specifying how the tables are matched.
- Giving values in an
INSERTstatement in an order that does not match the listed columns.
- Confusing
Related topics
