SQL Fundamentals Beginner Quiz
30 questions on SQL Fundamentals.
Question 1: What does SQL stand for?
- A. System Query Language
- B. Structured Query Language β (correct answer)
- C. Standard Question Language
- D. Server Query Logic
Explanation: SQL is the standard language used to communicate with and manipulate relational databases.
Question 2: Which SQL statement is used to extract data from a database?
- A. GET
- B. FETCH
- C. SELECT β (correct answer)
- D. EXTRACT
Explanation: The SELECT statement is the most commonly used command in SQL, designed to query and retrieve data from tables.
Question 3: Which clause is used to filter records and extract only those that fulfill a specified condition?
- A. FILTER
- B. SORT
- C. HAVING
- D. WHERE β (correct answer)
Explanation: The WHERE clause filters data before it is returned. For example, WHERE age > 18.
Question 4: Which statement is used to add new rows of data to a database table?
- A. ADD RECORD
- B. INSERT INTO β (correct answer)
- C. UPDATE
- D. CREATE ROW
Explanation: INSERT INTO table_name (col1, col2) VALUES (val1, val2) is the standard syntax to add new data.
Question 5: Which statement is used to modify existing data within a table?
- A. MODIFY
- B. CHANGE
- C. UPDATE β (correct answer)
- D. ALTER
Explanation: The UPDATE statement is used alongside a SET clause (and usually a WHERE clause) to change existing records.
Question 6: Which statement is used to remove rows from a table?
- A. DROP
- B. REMOVE
- C. TRUNCATE
- D. DELETE β (correct answer)
Explanation: DELETE FROM table_name WHERE condition safely removes specific rows from a table.
Question 7: What happens if you omit the WHERE clause in a DELETE statement?
- A. It deletes the first row only
- B. It returns a syntax error
- C. It deletes all records in the table β (correct answer)
- D. It deletes the table structure
Explanation: Without a WHERE clause to limit the scope, DELETE FROM table_name will empty the entire table (though the table itself remains).
Question 8: Which SQL keyword is used to sort the result-set?
- A. ORDER BY β (correct answer)
- B. SORT BY
- C. GROUP BY
- D. ALIGN
Explanation: ORDER BY column_name ASC|DESC sorts the returned records.
Question 9: Which operator is used to search for a specified pattern in a column?
- A. MATCHES
- B. LIKE β (correct answer)
- C. CONTAINS
- D. HAS
Explanation: The LIKE operator is used with wildcards (% for multiple characters, _ for a single character) to perform pattern matching.
Question 10: How do you select all columns from a table named "Customers"?
- A.
SELECT Customers;
- B.
SELECT ALL FROM Customers;
- C.
SELECT * FROM Customers; β (correct answer)
- D.
SELECT columns FROM Customers;
Explanation: The asterisk * acts as a wildcard meaning "all columns".
Question 11: Which keyword is used to return only distinct (different) values?
- A. UNIQUE
- B. DISTINCT β (correct answer)
- C. DIFFERENT
- D. SEPARATE
Explanation: SELECT DISTINCT country FROM users; will return a list of countries without any duplicates.
Question 12: Which SQL clause is used to combine rows from two or more tables, based on a related column between them?
- A. MERGE
- B. COMBINE
- C. APPEND
- D. JOIN β (correct answer)
Explanation: JOIN is the fundamental operation for relational databases, connecting tables using Primary and Foreign keys.
Question 13: What does an INNER JOIN do?
- A. Returns all records from both tables
- B. Returns all records from the left table
- C. Returns only records that have matching values in BOTH tables β (correct answer)
- D. Returns records that do not match
Explanation: An INNER JOIN strictly requires a match on both sides of the relationship.
Question 14: What is a "Primary Key"?
- A. A column that automatically encrypts data
- B. A column (or set of columns) that uniquely identifies each row in a table β (correct answer)
- C. The first column created in a table
- D. A column used for joining without indexes
Explanation: A primary key must contain unique values and cannot contain NULL values.
Question 15: What is a "Foreign Key"?
- A. A key used to connect to a foreign database
- B. A column in one table that refers to the Primary Key of another table β (correct answer)
- C. An encrypted password
- D. A temporary key
Explanation: Foreign keys enforce referential integrity, ensuring that relationships between tables remain valid.
Question 16: Which aggregate function calculates the total sum of a numeric column?
- A. COUNT()
- B. TOTAL()
- C. SUM() β (correct answer)
- D. ADD()
Explanation: SUM(column_name) adds up all the values in that specific column.
Question 17: Which clause groups rows that have the same values into summary rows?
- A. GROUP BY β (correct answer)
- B. ORDER BY
- C. SORT BY
- D. MATCH BY
Explanation: GROUP BY is used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.
Question 18: Why do we use the HAVING clause instead of WHERE sometimes?
- A.
HAVING is faster
- B.
WHERE cannot be used with aggregate functions, while HAVING can β (correct answer)
- C.
HAVING is used for text, WHERE is used for numbers
- D.
HAVING is used in NoSQL
Explanation: Because WHERE filters rows before grouping occurs, you must use HAVING to filter the results *after* GROUP BY has applied an aggregate function (e.g., HAVING COUNT(id) > 5).
Question 19: What does the IN operator do?
- A. Checks if an element is inside an array
- B. Allows you to specify multiple values in a
WHERE clause β (correct answer)
- C. Inserts new data into a table
- D. Joins an inner table
Explanation: WHERE country IN ('USA', 'UK', 'Canada') is much cleaner than writing multiple OR statements.
Question 20: What does the BETWEEN operator do?
- A. Selects values within a given range (inclusive) β (correct answer)
- B. Selects values strictly between a range (exclusive)
- C. Joins two tables
- D. Finds the average of two numbers
Explanation: WHERE price BETWEEN 10 AND 20 selects all prices from 10 to 20, including 10 and 20.
Question 21: Which SQL statement is used to create a new database table?
- A. BUILD TABLE
- B. GENERATE TABLE
- C. CREATE TABLE β (correct answer)
- D. NEW TABLE
Explanation: The CREATE TABLE command defines the table name, columns, and data types.
Question 22: How do you change the structure of an existing table (like adding a column)?
- A. UPDATE TABLE
- B. MODIFY TABLE
- C. CHANGE TABLE
- D. ALTER TABLE β (correct answer)
Explanation: ALTER TABLE table_name ADD column_name datatype; modifies the table's schema.
Question 23: Which command completely destroys a table and its structure?
- A. DELETE TABLE
- B. DROP TABLE β (correct answer)
- C. TRUNCATE TABLE
- D. REMOVE TABLE
Explanation: DROP TABLE deletes the data, the structure, and the indexes. TRUNCATE TABLE only deletes the data.
Question 24: What is a NULL value in SQL?
- A. The number zero (0)
- B. A blank space (' ')
- C. A field with no value (missing or unknown data) β (correct answer)
- D. An error code
Explanation: NULL represents the deliberate absence of any value. It is not the same as zero or an empty string.
Question 25: How do you test for NULL values in a WHERE clause?
- A.
WHERE column = NULL
- B.
WHERE column == NULL
- C.
WHERE column IS NULL β (correct answer)
- D.
WHERE column HAS NULL
Explanation: Because NULL represents an unknown, it cannot be compared using = or !=. You must use IS NULL or IS NOT NULL.
Question 26: What does the UNION operator do?
- A. Combines the result-set of two or more SELECT statements β (correct answer)
- B. Joins two tables horizontally
- C. Multiplies two columns together
- D. Groups rows together
Explanation: UNION stacks query results vertically. By default, it removes duplicate rows (unlike UNION ALL).
Question 27: What is an "Index" in SQL?
- A. A primary key
- B. A special data structure that improves the speed of data retrieval operations β (correct answer)
- C. A table of contents at the beginning of a database file
- D. An auto-incrementing number
Explanation: Indexes prevent the database engine from having to scan every single row in a table to find a specific value, at the cost of slightly slower INSERT and UPDATE operations.
Question 28: What does a LEFT JOIN do?
- A. Returns all records from the left table, and the matched records from the right table β (correct answer)
- B. Returns only records that match on the left side
- C. Returns all records from the right table
- D. Returns only unmatched records
Explanation: Even if there is no match in the right table, the row from the left table will still be included in the results (with NULLs for the right table's columns).
Question 29: What does the AS keyword do in SQL?
- A. Assigns an alias to a column or table for the duration of a query β (correct answer)
- B. Casts a data type
- C. Sorts ascending
- D. Asserts a constraint
Explanation: SELECT first_name AS "First Name" FROM users; changes how the column name is displayed in the result set.
Question 30: What is a "Subquery"?
- A. A query that executes faster than normal
- B. A query nested inside another SQL query β (correct answer)
- C. A backup query
- D. A query that returns no data
Explanation: Subqueries (or inner queries) are evaluated first, and their results are used by the main (outer) query to filter or calculate data.