SQL Basics
Tables & Data
SELECT Squad
Change It!
Debug the Code
100

Question: What does SQL stand for?


Answer: Structured Query Language.


100

Question: What is a row in a database table called?


Answer: A record.


100

Question: Which SQL command is used to retrieve information from a database?


Answer: SELECT.


100

Question: Which SQL command is used to add a new record to an existing table?


Answer: INSERT INTO.


100

Question: Identify and correct the error.

SELCT * FROM Books;

SELECT * FROM Books;


200

Question: What is the primary purpose of SQL?


Answer: To create, retrieve, and manage data in relational databases.


200

Question: Which SQL data type would be most appropriate for storing a student's age in whole years?


Answer: INTEGER.


200

Question: What does the asterisk (*) mean in the following statement?


SELECT * FROM Books;

200

Question: Which SQL command is used to modify information already stored in a record?


Answer: UPDATE.


200

Question: Identify and correct the error.

SELECT Title Books;


SELECT Title FROM Books;


300

Question: What is the purpose of the WHERE clause in SQL?


Answer: To identify records that meet a specific condition.


300

Question: What is the purpose of a primary key in a database table?


Answer: To uniquely identify each record.


300

Question: Write a SQL statement to display only the Title and Author columns from the Books table.


SELECT Title, Author FROM Books;


300

Question: Write a SQL statement to delete the record with BookID 8 from the Books table.


DELETE FROM Books
WHERE BookID = 8;

300

Question: The goal is to retrieve all books published in 2020. Identify and correct the error.

SELECT * FROM Books
SET YearPublished = 2020;


SELECT * FROM Books
WHERE YearPublished = 2020;

400

Question: Explain the difference between DELETE FROM and DROP TABLE.


Answer: DELETE FROM removes records while keeping the table structure. DROP TABLE removes the entire table, including its structure.


400

Question: Write a SQL statement to create a table named Books containing two columns: BookID (INTEGER) and Title (VARCHAR(100)).


CREATE TABLE Books (
  BookID INTEGER,
  Title VARCHAR(100)
);

400

Question: A Books table contains four records with publication years 2019, 2021, 2021, and 2023. How many records would this statement return?


SELECT * FROM Books
WHERE YearPublished = 2021;

400

Question: Write a SQL statement to change the Title to 'New Edition' for the book with BookID 6.


UPDATE Books
SET Title = 'New Edition'
WHERE BookID = 6;

400

Question: The goal is to change the publication year to 2024 for only the book with BookID 3. Identify and fix the problem.

UPDATE Books
SET YearPublished = 2024;

UPDATE Books
SET YearPublished = 2024
WHERE BookID = 3;

500

Question: What does the following SQL statement do, and why is IF EXISTS useful?

DROP TABLE IF EXISTS Books;

Answer: It removes the Books table if it exists. IF EXISTS helps prevent an error if the table does not exist.


500

Question: Write SQL to create a table named Clubs with ClubID as an INTEGER primary key and ClubName as VARCHAR(60).


CREATE TABLE Clubs (
  ClubID INTEGER PRIMARY KEY,
  ClubName VARCHAR(60)
);

500

Question: A Books table contains the following records:

(open file)

What titles would the following statement return?

SELECT Title FROM Books
WHERE YearPublished = 2022;

Answer: Orbit and Comet.


500

Question: Write a SQL statement to add the following record to the Books table:

  • BookID: 12

  • Title: Skyward

  • YearPublished: 2023

INSERT INTO Books
(BookID, Title, YearPublished)
VALUES
(12, 'Skyward', 2023);

500

Question: Identify and correct the errors.

INSERT Books (BookID, Title)
VALUE (9, 'Voyage');

INSERT INTO Books
(BookID, Title)
VALUES (9, 'Voyage');

M
e
n
u