SQL DROP TABLE

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

SQL DROP TABLE

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement removes the whole table named orders, including its structure?
A DROP TABLE orders;
B DELETE FROM orders;
2. After DROP TABLE students; runs, can you get the records back with an undo command?
A No, the data cannot be recovered
B Yes, run UNDO DROP to restore it
3. Which version avoids an error if the table results does not exist?
A DROP TABLE results IF EXISTS;
B DROP TABLE IF EXISTS results;
4. What happens when you run DROP TABLE tempData; and tempData does not exist (no IF EXISTS)?
A The database reports an error
B It quietly creates an empty tempData table
5. Which statement is correct SQL for dropping a table?
A DROP products TABLE;
B DROP TABLE products;

Match the Pairs

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

Left columnRight column
1DROP TABLE orders; AThe TABLE keyword is missing. It must be DROP TABLE students; to say that a table is being removed.
2DROP TABLE IF EXISTS results; BDROP TABLE IF EXISTS products;
3A dropped table cannot be recovered, so the whole table and its records are gone for good CDrops the results table only if it exists, so there is no error when the table is missing
4Remove a table safely in a setup script so it runs without an error even if the table was never created DDROP TABLE deletes the whole table, not just old rows. Use DELETE FROM with a WHERE condition to remove only some records.
5DROP students; EDROP TABLE students;
6DROP TABLE students; -- only to remove old rows FPermanently removes the whole orders table, including its structure and every record in it

Definitions

DROP TABLE

Fill in the Blanks

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

1.
____ TABLE students;
2.
DROP _____ results;
3.
DROP TABLE __ EXISTS orders;
4.
DROP TABLE ______; DROP TABLE products;
5.
DROP TABLE IF ______ subjects;

Spot the Error

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

Question 1
A -- remove the old log table
B DROP TABLE IF EXIST old_log;
C SELECT * FROM students;
Question 2
A DELETE TABLE IF EXISTS temp;
B CREATE TABLE temp (id INT);
C INSERT INTO temp VALUES (1);
Question 3
A -- remove the unused table
B DROP old_notes;
C SELECT * FROM students;
Question 4
A DROP TABLE archive IF EXISTS;
B CREATE TABLE archive (id INT);
C SELECT * FROM students;
Question 5
A CREATE TABLE temp (id INT);
B INSERT INTO temp VALUES (1);
C SELECT * FROM temp;
D DROP TABLE temp WHERE id = 1;

Answer Key

SQL DROP TABLE
Section A: Quick Questions
Q1
A — DROP TABLE orders;
Q2
A — No, the data cannot be recovered
Q3
B — DROP TABLE IF EXISTS results;
Q4
A — The database reports an error
Q5
B — DROP TABLE products;
Section B: Match the Pairs
Q1
DROP TABLE orders; → Permanently removes the whole orders table, including its structure and every record in it
Q2
DROP TABLE IF EXISTS results; → Drops the results table only if it exists, so there is no error when the table is missing
Q3
A dropped table cannot be recovered, so the whole table and its records are gone for good → DROP TABLE students;
Q4
Remove a table safely in a setup script so it runs without an error even if the table was never created → DROP TABLE IF EXISTS products;
Q5
DROP students; → The TABLE keyword is missing. It must be DROP TABLE students; to say that a table is being removed.
Q6
DROP TABLE students; -- only to remove old rows → DROP TABLE deletes the whole table, not just old rows. Use DELETE FROM with a WHERE condition to remove only some records.
Section C: Definitions
Q1
DROP TABLE — DROP TABLE name; permanently deletes a whole table and all its records. It cannot be undone. Add IF EXISTS to avoid an error when the table is missing.
Section D: Fill in the Blanks
Q1
DROP TABLE students;
Q2
DROP TABLE results;
Q3
DROP TABLE IF EXISTS orders;
Q4
DROP TABLE orders; DROP TABLE products;
Q5
DROP TABLE IF EXISTS subjects;
Section E: Spot the Error
Q1
B — The keyword is spelled EXISTS, with an S. It should be DROP TABLE IF EXISTS old_log; so the statement does not error if the table is missing.
Q2
A — SQL has no DELETE TABLE command. A table is removed with DROP TABLE, so the line should be DROP TABLE IF EXISTS temp;
Q3
B — DROP must be followed by the word TABLE and then the table name. The line should be DROP TABLE old_notes;
Q4
A — IF EXISTS comes before the table name, not after it. The correct line is DROP TABLE IF EXISTS archive;
Q5
D — DROP TABLE removes the whole table, so it cannot take a WHERE condition. Use DELETE FROM temp WHERE id = 1; to remove single rows, or DROP TABLE temp; to remove the table.