That Blue Square Thing

AQA Computer Science GCSE

SQL Basics

Databases are only useful if we can search them and extract information from them. That's where a query language comes in.

Query languages are used to search databases – as well as to do other useful things to them.

The main query language is Structured Query Language, or SQL (sequel).

Using SQL online

There are various places that you can use SQL online.

> SQLite online – this is my usual option.

To use an online tool you first need to create a database. I'll provide text files of SQL commands that will do this for you – all you need to do is copy and paste the text in and run the commands.

SQLite browser comes with a table already in place – it's called demo. You'll want to get rid of this. The way to do this is to run the followng SQL command after you've created your database:

DROP TABLE demo;

That should work to remove the demo table.

On the grounds that websites change and school networks block things, two alternaives are:

> SQLite browser – from Extend Class

> Online SQLite Compiler – from Coding Ground

Basic SQL Commands

Once you've got the idea of simple databases, we can get more complex...

PDF iconSQL basics – slides from class

When you're working through the commands, you'd be best off trying them out using SQLite Browser. To do that, you'll need code to create a simple relational database.

Text file iconFood database code – copy and paste the code

New for 2024, SQLite now insists you use single quotes around strings, rather than double quotes. So it wants 'aString' rather than "aString". In all of the slides below I use double quotes ("aString"), because that's almost always what I do. Anything in SQLite will need single quotes now I'm afraid. Other online tools may vary of course and in an exam you'd be find with either.

There are four basic commands you need to be able to use:

PDF iconSELECT command

PDF iconINSERT INTO command

PDF iconUPDATE command

PDF iconDELETE command

The syntax rules in SQL aren't that bad, but it's worth having a reminder:

PDF iconSQL syntax rules

Food database tasks

PDF iconFood database tables – with some standard questions

PDF iconFood database tasks – a whole pile of SQL tasks to try out

Use the database creation code that's further up the page to create this database in SQLite.

Airport database

Some exam style tasks for a simple relational database.

PDF iconAirports database tasks

Here's the database creation code so that you can try it out in SQLite.

Text file iconAirports database code – copy and paste the code

Other databases

Some other simple relational databases to work with:

Text file iconGames cafe database code – copy and paste the code