What a database query is

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

What a database query is

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a database query?
A A saved question asked of a table
B A new table that replaces the old one
2. A query is run on a Students table. What happens to the original table?
A The rows that did not match are deleted
B It stays unchanged
3. Which part of a query picks which columns to show?
A The fields
B The sort order
4. Which part of a query decides which records (rows) are included?
A The field names
B The criteria
5. What does the sort order in a query control?
A The order the results are listed in
B Which records are deleted

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1SELECT Name, Year FROM Students AORDER BY Score DESC
2WHERE Year = 8 BThis changes the table. A query should only show the Year 8 records in a new view and leave all the original records in place.
3A query asks a question of a table and shows the answer as a new view, without changing the table CA query that shows only the Name and Year fields from the Students table
4A query can set a sort order so the results are shown in a chosen order DA criteria that keeps only the records where Year is 8
5A student deletes the Year 7 records from the Students table to 'show only Year 8' ESELECT * FROM Pets WHERE Type = 'Dog'
6SELECT Name FROM Students WHERE Year = 8, to show each student's name and their score FThe query only selects the Name field, so Score is not shown. Add Score to the fields list: SELECT Name, Score.

Definitions

query

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ Name, Year FROM Students
2.
SELECT Name, Year ____ Students
3.
SELECT Name FROM Students _____ Year = 8
4.
SELECT Name FROM Students WHERE Year _ 8
5.
SELECT Name, Score FROM Students ORDER BY Score ____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A QUERY OldPets
B FROM OldPets
C SHOW Name, Age
D WHERE Age > 8
Question 2
A DELETE Teams
B FROM Teams
C SHOW Team, Players
D WHERE Players > 20
Question 3
A QUERY Class8B
B FROM Students
C SHOW Name, Class
D WHERE Class = 8B
Question 4
A QUERY LongMovies
B FROM Movies
C SHOW Tittle, Length
D WHERE Length > 120
Question 5
A FROM Games
B SHOW Player Score
C SORT BY Score DESC

Answer Key

What a database query is
Section A: Quick Questions
Q1
A — A saved question asked of a table
Q2
B — It stays unchanged
Q3
A — The fields
Q4
B — The criteria
Q5
A — The order the results are listed in
Section B: Match the Pairs
Q1
SELECT Name, Year FROM Students → A query that shows only the Name and Year fields from the Students table
Q2
WHERE Year = 8 → A criteria that keeps only the records where Year is 8
Q3
A query asks a question of a table and shows the answer as a new view, without changing the table → SELECT * FROM Pets WHERE Type = 'Dog'
Q4
A query can set a sort order so the results are shown in a chosen order → ORDER BY Score DESC
Q5
A student deletes the Year 7 records from the Students table to 'show only Year 8' → This changes the table. A query should only show the Year 8 records in a new view and leave all the original records in place.
Q6
SELECT Name FROM Students WHERE Year = 8, to show each student's name and their score → The query only selects the Name field, so Score is not shown. Add Score to the fields list: SELECT Name, Score.
Section C: Definitions
Q1
query — A saved question asked of a table. It shows only the fields and records that answer it, as a new view, and leaves the original table unchanged.
Section D: Fill in the Blanks
Q1
SELECT Name, Year FROM Students
Q2
SELECT Name, Year FROM Students
Q3
SELECT Name FROM Students WHERE Year = 8
Q4
SELECT Name FROM Students WHERE Year = 8
Q5
SELECT Name, Score FROM Students ORDER BY Score DESC
Section E: Spot the Error
Q1
B — FROM must name the table the question is asked of, which is Pets. OldPets is the name of the query, not a table. It should be FROM Pets.
Q2
A — A query only asks a question and leaves the table unchanged. It must not delete anything. The first line should name the query: QUERY BigTeams.
Q3
D — A text criterion must go inside quotes. It should be WHERE Class = "8B".
Q4
C — A field name must match the table exactly. Tittle is a misspelling, so the query cannot find that field. It should be SHOW Title, Length.
Q5
B — The fields in a SHOW line must be separated by commas. It should be SHOW Player, Score.