Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

DA 2.3: SQL, NoSQL and macros as query tools

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

One question, three tools

A teacher asks: "Which Year 9B pupils are in chess club?" The pupil list could be a table, a pile of documents or a spreadsheet.

Each store has its own search tool. Choosing the right one saves time.

Key words

WordWhat it means
SQLthe language used to search tables in a relational database
NoSQLtools that search non-relational stores
Macroa saved set of steps that runs on its own
Documentone record with its own fields
Query toolsoftware you use to search data
Relational databasetables linked by values they share

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can match SQL, NoSQL and macros to the data they query.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

SQL searches relational tables

SQL searches the tables of a relational database. You say which columns, from which table, where the condition is true.

It is the right tool when data sits in tables with fixed columns.

Try it: the question in SQL

Code: duckdb
select name
from pupils
where form = '9B' and club = 'chess';

-- Try it: change chess to choir. What comes back?

NoSQL searches other kinds of store

NoSQL tools search non-relational stores, such as a collection of documents. The query describes the fields a document must have.

The tool depends on the store. One document store may take a query like {form: "9B", club: "chess"}.

Try it: the same question on documents

Code: python
docs = [
    {"name": "Sam", "form": "9B", "club": "chess"},
    {"name": "Ada", "form": "9C"},
    {"name": "Raj", "form": "9B"},
]

for doc in docs:
    if "club" in doc and doc["form"] == "9B" and doc["club"] == "chess":
        print(doc["name"])

# Try it: print the form of every pupil with a club.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

6 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.