Running an SQL query in a database tool

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

Running an SQL query in a database tool

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. You have written SELECT * FROM students; in the SQL view of Access or Base. What do you do next?
A Close the window and the results appear on their own
B Run the query and read the results table
2. Which is the right place to type an SQL statement in a database tool?
A The query window (SQL view)
B The table's Datasheet view where records are stored
3. You run SELECT * FROM students; on the practice data. What appears?
A A results table showing every field of every student
B A message that says only how many students there are
4. An online SQL practice editor shows the error: no such table: student. Which fix is best?
A Change student to students, the real table name
B Add more rows to the student table
5. Your query shows an error message. What should you do first?
A Delete the database and start again
B Read the message, then fix the statement

Match the Pairs

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

Left columnRight column
1SELECT * FROM students; AThe keyword SELECT is spelt wrong, so the tool shows a syntax error and no results table. Correct it to SELECT and run the statement again.
2SELECT firstName, house FROM students; BThe table name is spelt wrong. The built-in table is called students, so the tool shows an error that the table cannot be found. Fix the name and run again.
3Type a statement in the query window, run it, and the results table shows the matching records. CSELECT * FROM students;
4When an error message says a table name is unknown, check the spelling and fix the statement before running it again. DA statement you type in the query window and run to show every field and record from the students table in the results table.
5SELECT * FROM student; EA statement that, once run, gives a results table with only the firstName and house columns, so you check the columns match what you asked for.
6SELEC firstName FROM students; FSELECT firstName, points FROM students WHERE points > 100;

Definitions

SELECT * FROM students;

Fill in the Blanks

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

1.
______ * FROM students;
2.
SELECT * ____ students;
3.
SELECT firstName, house FROM ________;
4.
-- Error: no such column: nme SELECT ____ FROM subjects;
5.
SELECT * FROM students _____ house = 'Red';

Spot the Error

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

Question 1
A SELECT firstName, points
B FROM students
C WHERE house = Red
D ORDER BY points DESC;
Question 2
A SELECT firstName, lastName
B FROM students
C WHERE yearLevel = 8
D ORDER lastName;
Question 3
A SELECT name, price
B FORM products
C WHERE price > 10;
Question 4
A SELECT *
B FROM student
C WHERE points > 100;
Question 5
A SELECT name teacher
B FROM subjects
C ORDER BY name;

Answer Key

Running an SQL query in a database tool
Section A: Quick Questions
Q1
B — Run the query and read the results table
Q2
A — The query window (SQL view)
Q3
A — A results table showing every field of every student
Q4
A — Change student to students, the real table name
Q5
B — Read the message, then fix the statement
Section B: Match the Pairs
Q1
SELECT * FROM students; → A statement you type in the query window and run to show every field and record from the students table in the results table.
Q2
SELECT firstName, house FROM students; → A statement that, once run, gives a results table with only the firstName and house columns, so you check the columns match what you asked for.
Q3
Type a statement in the query window, run it, and the results table shows the matching records. → SELECT firstName, points FROM students WHERE points > 100;
Q4
When an error message says a table name is unknown, check the spelling and fix the statement before running it again. → SELECT * FROM students;
Q5
SELECT * FROM student; → The table name is spelt wrong. The built-in table is called students, so the tool shows an error that the table cannot be found. Fix the name and run again.
Q6
SELEC firstName FROM students; → The keyword SELECT is spelt wrong, so the tool shows a syntax error and no results table. Correct it to SELECT and run the statement again.
Section C: Definitions
Q1
SELECT * FROM students; — Type an SQL statement in the tool's query window, run it, then read the results table. If an error shows, read the message and fix the statement.
Section D: Fill in the Blanks
Q1
SELECT * FROM students;
Q2
SELECT * FROM students;
Q3
SELECT firstName, house FROM students;
Q4
-- Error: no such column: nme SELECT name FROM subjects;
Q5
SELECT * FROM students WHERE house = 'Red';
Section E: Spot the Error
Q1
C — Text values must be in quotes. Without them the tool reads Red as a field name and shows an error. It should be WHERE house = 'Red'.
Q2
D — Sorting needs the keywords ORDER BY. The word BY is missing, so the tool shows a syntax error. It should be ORDER BY lastName;
Q3
B — FROM is spelled wrong. The error message would point at FORM. It should be FROM products.
Q4
B — The table is called students, not student. The tool would say it cannot find the table. It should be FROM students.
Q5
A — Field names in a SELECT list must be separated by commas. It should be SELECT name, teacher.