Databases & SQL

Information often needs to be organized, searchable, and structured. To do this, we use Databases and search them using Structured Query Language (SQL).

Core Terminology

Before writing queries, you must understand the anatomical structure of a database. Click the cards below to reveal their definitions and visual diagrams.

Database Tap to explore

A digital filing system that stores lots of information so it's easy to search and manage.

See visual
A digital filing cabinet
Click to close
Table Tap to explore

A grid of rows and columns that stores data about one specific topic (like a register).

See visual
ID
Name
Age
1
John
15
2
Sue
16
Click to close
Record Tap to explore

One complete horizontal ROW. It holds all the information about a single person or item.

See visual
ID
Name
Age
1
John
15
2
Sue
16
Click to close
Field Tap to explore

A single vertical COLUMN or category of data (e.g., a column just for 'Surnames').

See visual
ID
Name
Age
1
John
15
2
Sue
16
Click to close
Syntax Tap to explore

The strict spelling and grammar rules required so the computer understands your query.

See visual
Age == 16
Age = 16
Click to close
Query Tap to explore

A question we ask the database to find data. We write these queries using SQL.

See visual

SELECT Name

FROM tblStudents

Click to close

Building the Query: SELECT & FROM

To pull specific data from a database, we use SQL string sentences. We will look at a table called tblStudents as our example.

StudentID FirstName Surname Age Subject
1 John Smith 15 Computing
2 Sue Jones 16 History

SELECT chooses the specific Columns/Fields. FROM chooses the Table. The asterisk * is our wildcard for "all fields".

SELECT FirstName, Subject
FROM tblStudents

Filters & Syntax Traps

The WHERE clause adds a filter/condition to our query to pull specific records rather than all of them. But there are major EXAM TRAPS you must avoid!

The Equals Trap

In Python, we used == to check if something matched. In SQL syntax, we only ever use a single = sign.

WHERE Age == 16
WHERE Age = 16

The Quotes Trap

Text strings MUST have quotes around them (e.g., 'History' or "History"). Numbers DO NOT need quotes.

WHERE Subject = History
WHERE Subject = "History"