SQL MCQ
Test your SQL knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
What does SQL stand for?
2Which SQL statement is used to retrieve data from a database?
3Which clause is used to filter rows based on a condition?
4Which keyword is used to sort the result set of a query?
5Which SQL statement is used to add new rows to a table?
6Which statement modifies existing data in a table?
7Which statement removes rows from a table?
8What is the purpose of a PRIMARY KEY constraint?
9What does the wildcard "%" represent in a LIKE pattern?
10Which keyword removes duplicate rows from a SELECT result?
11What does NULL represent in SQL?
12How do you check if a column value is NULL in a WHERE clause?
13Which SQL command creates a new table?
14What is the purpose of the LIMIT clause (or TOP in SQL Server)?
15Which aggregate function returns the total number of rows matching a query?
16What does the BETWEEN operator do?
17Which clause groups rows that have the same values into summary rows?
18What is the purpose of the FOREIGN KEY constraint?
19Which logical operator returns true if both conditions are true?
20What does the "AS" keyword do in a SELECT statement?
21Which data type is typically used to store whole numbers?
22Which data type is best for storing variable-length text with a maximum size, e.g. names?
23What does the IN operator do in a WHERE clause?
24What is a "view" in SQL?
25Which command grants or removes a column's default value, structure, or constraints on an existing table?
26What is the result of "5 = NULL" in SQL?
27Which clause is used to filter groups after a GROUP BY, based on an aggregate condition?
28What does "ORDER BY column DESC" do?
29Which function returns the current date and/or time in most SQL databases?
30What does "SELECT * FROM table" do?
31Which constraint ensures a column cannot contain NULL values?
32What does "DROP TABLE table_name" do?
33What does the AVG() function do?
34What is the purpose of the UNIQUE constraint?
35How do you add a new column to an existing table?
36Which operator negates a condition, e.g. "WHERE NOT (age > 18)"?
37What does "COUNT(DISTINCT column)" return?
38What is the difference between CHAR and VARCHAR data types?
39Which keyword combines the result sets of two SELECT statements, removing duplicate rows?
40What is the result of "NULL OR TRUE" in SQL's three-valued logic?
What is the difference between an INNER JOIN and a LEFT JOIN?
2What is a subquery (nested query)?
3What does a self-join allow you to do?
4What is the purpose of an INDEX on a column?
5What is the difference between UNION and UNION ALL?
6What does a transaction with "COMMIT" and "ROLLBACK" provide?
7What does the ACID acronym stand for in the context of database transactions?
8What is the purpose of "GROUP BY" combined with "HAVING COUNT(*) > 1"?
9What is a "composite key"?
10What does "CASE WHEN condition THEN result ELSE other_result END" provide in a SELECT statement?
11What is database normalization?
12What is the difference between "DELETE", "TRUNCATE", and "DROP" for removing data from a table?
13What does a window function with "OVER (PARTITION BY column)" do, e.g. "SUM(amount) OVER (PARTITION BY dept)"?
14What is the purpose of the "EXISTS" operator in a subquery?
15What is a "CTE" (Common Table Expression), defined with WITH?
16What does the "ON DELETE CASCADE" option on a foreign key do?
17What is the difference between a clustered index and a non-clustered index?
18What does "GROUP BY" require regarding columns in the SELECT list (in standard SQL)?
19What does "RIGHT JOIN" return that differs from "LEFT JOIN"?
20What is the effect of "SELECT ... FOR UPDATE" in a transaction?
21What does the "COALESCE(a, b, c)" function return?
22What is the difference between "WHERE" and "ON" clauses when used with JOINs?
23What does "DENSE_RANK()" return differently from "RANK()" in a window function?
24What is the purpose of "EXPLAIN" (or "EXPLAIN PLAN") before a query?
25What does a "self-referencing foreign key" typically model, e.g. an "employees" table with a "manager_id" column referencing "employees.id"?
26What does "INSERT INTO table (cols) SELECT cols FROM other_table" accomplish?
27What does "ANY" / "SOME" do when used with a comparison operator and a subquery, e.g. "WHERE salary > ANY (subquery)"?
28What is the purpose of "GENERATED ALWAYS AS IDENTITY" (or AUTO_INCREMENT in MySQL)?
29What does the "CROSS JOIN" produce?
30What does "SELECT TOP 10 PERCENT * FROM table ORDER BY score DESC" (SQL Server syntax) accomplish?
31What is a "materialized view" and how does it differ from a regular view?
32What does the "LEAD()" / "LAG()" window functions do?
33What is the purpose of "CHECK" constraints?
34What does "FULL OUTER JOIN" return?
35What does "ROUND(123.456, 2)" return?
36What is the purpose of the "STRING_AGG" / "GROUP_CONCAT" function?
37What does adding "WITH CHECK OPTION" to a view definition enforce?
38What is the effect of using a transaction with "SAVEPOINT"?
39What does "CAST(column AS DECIMAL(10,2))" do?
40What does the "OFFSET" clause do when combined with LIMIT, e.g. "LIMIT 10 OFFSET 20"?
What is the difference between the four standard transaction isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE)?
2What is a "deadlock" in a database, and how do most database systems handle it?
3What is the purpose of "query plan caching" and how can parameterized queries affect it?
4How does a recursive CTE (Common Table Expression) work, e.g. for traversing a hierarchy?
5What is the difference between "covering index" and a regular index?
6What problem does "MVCC" (Multi-Version Concurrency Control), used by databases like PostgreSQL and MySQL InnoDB, solve?
7What does "SARGable" mean in the context of a WHERE clause predicate, and why does it matter for performance?
8What is the purpose of "PARTITIONING" a large table (e.g. by date range)?
9What is the "N+1 query problem" often encountered in application code using an ORM, and how does SQL help avoid it?
10What is the difference between a "hash join", "merge join" (sort-merge join), and "nested loop join" as physical join strategies?
11What is "write-ahead logging" (WAL) and why is it important for durability?
12What is the difference between "optimistic locking" and "pessimistic locking" concurrency control strategies?
13What is a "lateral join" (or CROSS APPLY in SQL Server) used for?
14What does "denormalization" trade off, and when might it be appropriate?
15What is a "phantom read" anomaly, and which isolation level is required to fully prevent it according to the SQL standard?
16What is the purpose of "UPSERT" (e.g. "INSERT ... ON CONFLICT DO UPDATE" in PostgreSQL or "ON DUPLICATE KEY UPDATE" in MySQL)?
17What does "query plan parameter sniffing" mean in the context of stored procedures, and what issue can it cause?
18What is the difference between a "scalar subquery" and a "correlated subquery"?
19What does "GROUPING SETS", "CUBE", and "ROLLUP" extend GROUP BY to do?
20What is the practical significance of the difference between "NOT IN (subquery)" and "NOT EXISTS (correlated subquery)" when the subquery can return NULL values?