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.
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...
SQL 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.
Food 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:
The syntax rules in SQL aren't that bad, but it's worth having a reminder:
Food database tasks
Food database tables – with some standard questions
Food 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.
Here's the database creation code so that you can try it out in SQLite.
Airports database code – copy and paste the code
Other databases
Some other simple relational databases to work with:
Games cafe database code – copy and paste the code