Question: What does SQL stand for?
Answer: Structured Query Language.
Question: What is a row in a database table called?
Answer: A record.
Question: Which SQL command is used to retrieve information from a database?
Answer: SELECT.
Question: Which SQL command is used to add a new record to an existing table?
Answer: INSERT INTO.
Question: Identify and correct the error.
SELCT * FROM Books;
SELECT * FROM Books;
Question: What is the primary purpose of SQL?
Answer: To create, retrieve, and manage data in relational databases.
Question: Which SQL data type would be most appropriate for storing a student's age in whole years?
Answer: INTEGER.
Question: What does the asterisk (*) mean in the following statement?
SELECT * FROM Books;
Question: Which SQL command is used to modify information already stored in a record?
Answer: UPDATE.
Question: Identify and correct the error.
SELECT Title Books;
SELECT Title FROM Books;
Question: What is the purpose of the WHERE clause in SQL?
Answer: To identify records that meet a specific condition.
Question: What is the purpose of a primary key in a database table?
Answer: To uniquely identify each record.
Question: Write a SQL statement to display only the Title and Author columns from the Books table.
SELECT Title, Author FROM Books;
Question: Write a SQL statement to delete the record with BookID 8 from the Books table.
DELETE FROM Books
WHERE BookID = 8;
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;
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.
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)
);
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;
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;
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;
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.
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)
);
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.
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);
Question: Identify and correct the errors.
INSERT Books (BookID, Title)
VALUE (9, 'Voyage');
INSERT INTO Books
(BookID, Title)
VALUES (9, 'Voyage');