A library has a books table with (book_id, title, author). W…

A library has a books table with (book_id, title, author). Which SQL correctly inserts two books at once? INSERT INTO books VALUES (1, ‘1984’, ‘Orwell’), (2, ‘Dune’, ‘Herbert’); INSERT INTO books (1, ‘1984’, ‘Orwell’) AND (2, ‘Dune’, ‘Herbert’); ADD INTO books VALUES (1, ‘1984’, ‘Orwell’), (2, ‘Dune’, ‘Herbert’); INSERT books (book_id, title, author) = (1, ‘1984’, ‘Orwell’), (2, ‘Dune’, ‘Herbert’); Answer: INSERT INTO books VALUES (1, ‘1984’, ‘Orwell’), (2, ‘Dune’, ‘Herbert’); Explanation: Multiple rows can be inserted in one INSERT by separating tuples with commas. The other options use invalid SQL syntax.

A hospital wants to create a patients table with columns:…

A hospital wants to create a patients table with columns: patient_id (unique number, required) full_name (up to 255 characters, required) age (whole number) Which SQL is correct? CREATE TABLE patients (patient_id INT NOT NULL, full_name VARCHAR(255) NOT NULL, age DECIMAL(10,2)); CREATE TABLE patients (patient_id INT NOT NULL, full_name VARCHAR(255) NOT NULL, age INT); CREATE patients TABLE (patient_id INT NOT NULL, full_name TEXT, age INT); CREATE TABLE patients (patient_id VARCHAR(255), full_name INT, age INT); Answer: CREATE TABLE patients (patient_id INT NOT NULL, full_name VARCHAR(255) NOT NULL, age INT); Explanation: INT works for identifiers and ages, VARCHAR(255) is appropriate for names, and NOT NULL ensures mandatory fields. The other options either misuse data types or have invalid syntax.

A retail company has a customers table with columns (custome…

A retail company has a customers table with columns (customer_id, name, country). They want to add a new customer named Sofia from Spain with customer_id = 101. Which SQL is correct? INSERT INTO customers VALUES (101, ‘Sofia’, ‘Spain’); INSERT customers (101, ‘Sofia’, ‘Spain’); ADD INTO customers VALUES (101, ‘Sofia’, ‘Spain’); UPDATE customers SET (101, ‘Sofia’, ‘Spain’); Answer: INSERT INTO customers VALUES (101, ‘Sofia’, ‘Spain’); Explanation: INSERT INTO … VALUES is the correct syntax. The other options misuse SQL keywords (INSERT, ADD, or UPDATE).

A sales manager wants to know the total revenue from the ord…

A sales manager wants to know the total revenue from the orders table, which has a column called order_amount. Which SQL function should they use? SELECT COUNT(order_amount) FROM orders SELECT SUM(order_amount) FROM orders SELECT AVG(order_amount) FROM orders SELECT MAX(order_amount) FROM orders Answer: SELECT SUM(order_amount) FROM orders Explanation: SUM adds up all the values in a column, which is what’s needed for total revenue. COUNT would only return how many orders exist, AVG would give the average order size, and MAX would only show the largest single order.

A movie rental company has a movies table with title and rel…

A movie rental company has a movies table with title and release_year. The manager wants to see the movies listed from the newest to the oldest release year. Which SQL query should they run? SELECT * FROM movies ORDER BY release_year ASC SELECT * FROM movies ORDER BY release_year DESC SELECT release_year FROM movies SELECT * FROM movies GROUP BY release_year Answer: SELECT * FROM movies ORDER BY release_year DESC Explanation: DESC sorts in descending order, so the most recent release years appear first. ASC would list from oldest to newest. Selecting only release_year shows one column without sorting all movies, and GROUP BY is not a sorting tool.

A car rental company has a rentals table with columns car_ty…

A car rental company has a rentals table with columns car_type and days_rented. The operations team wants to know the longest rental period for each car type. Which SQL query should they use? SELECT car_type, MAX(days_rented) FROM rentals GROUP BY car_type SELECT car_type, days_rented FROM rentals ORDER BY days_rented DESC SELECT MAX(days_rented) FROM rentals SELECT car_type, SUM(days_rented) FROM rentals GROUP BY car_type Answer: SELECT car_type, MAX(days_rented) FROM rentals GROUP BY car_type Explanation: MAX(days_rented) finds the longest rental per car type when grouped accordingly. Simply ordering by days_rented shows all rentals but not summaries. A plain MAX(days_rented) gives the longest rental overall, not per type. SUM(days_rented) would calculate totals, not maximums.

Why might an organization use a view instead of giving direc…

Why might an organization use a view instead of giving direct access to a full table? To permanently delete unnecessary data To automatically increase query performance To restrict access to only part of the table To replace the need for indexes Answer: To restrict access to only part of the table Explanation: Views can hide sensitive columns or rows, allowing controlled access. They don’t automatically boost performance, delete data, or replace indexes.

A bank has an accounts table with (account_id, holder_name,…

A bank has an accounts table with (account_id, holder_name, balance). They want to add a new account with ID 5001, holder name Emma, and starting balance 1000.00. Which SQL is correct? INSERT accounts VALUES (5001, ‘Emma’, 1000.00); INSERT INTO accounts VALUES (5001, ‘Emma’, 1000.00); ADD INTO accounts (5001, ‘Emma’, 1000.00); UPDATE accounts (5001, ‘Emma’, 1000.00); Answer: INSERT INTO accounts VALUES (5001, ‘Emma’, 1000.00); Explanation: The correct syntax is INSERT INTO … VALUES. The others misuse SQL commands (INSERT, ADD, UPDATE).