🗄️

SQL MCQ

Test your SQL knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

100 Questions 40 Beginner 40 Intermediate 20 Advanced
1

What does SQL stand for?

2

Which SQL statement is used to retrieve data from a database?

3

Which clause is used to filter rows based on a condition?

4

Which keyword is used to sort the result set of a query?

5

Which SQL statement is used to add new rows to a table?

6

Which statement modifies existing data in a table?

7

Which statement removes rows from a table?

8

What is the purpose of a PRIMARY KEY constraint?

9

What does the wildcard "%" represent in a LIKE pattern?

10

Which keyword removes duplicate rows from a SELECT result?

11

What does NULL represent in SQL?

12

How do you check if a column value is NULL in a WHERE clause?

13

Which SQL command creates a new table?

14

What is the purpose of the LIMIT clause (or TOP in SQL Server)?

15

Which aggregate function returns the total number of rows matching a query?

16

What does the BETWEEN operator do?

17

Which clause groups rows that have the same values into summary rows?

18

What is the purpose of the FOREIGN KEY constraint?

19

Which logical operator returns true if both conditions are true?

20

What does the "AS" keyword do in a SELECT statement?

21

Which data type is typically used to store whole numbers?

22

Which data type is best for storing variable-length text with a maximum size, e.g. names?

23

What does the IN operator do in a WHERE clause?

24

What is a "view" in SQL?

25

Which command grants or removes a column's default value, structure, or constraints on an existing table?

26

What is the result of "5 = NULL" in SQL?

27

Which clause is used to filter groups after a GROUP BY, based on an aggregate condition?

28

What does "ORDER BY column DESC" do?

29

Which function returns the current date and/or time in most SQL databases?

30

What does "SELECT * FROM table" do?

31

Which constraint ensures a column cannot contain NULL values?

32

What does "DROP TABLE table_name" do?

33

What does the AVG() function do?

34

What is the purpose of the UNIQUE constraint?

35

How do you add a new column to an existing table?

36

Which operator negates a condition, e.g. "WHERE NOT (age > 18)"?

37

What does "COUNT(DISTINCT column)" return?

38

What is the difference between CHAR and VARCHAR data types?

39

Which keyword combines the result sets of two SELECT statements, removing duplicate rows?

40

What is the result of "NULL OR TRUE" in SQL's three-valued logic?

1

What is the difference between an INNER JOIN and a LEFT JOIN?

2

What is a subquery (nested query)?

3

What does a self-join allow you to do?

4

What is the purpose of an INDEX on a column?

5

What is the difference between UNION and UNION ALL?

6

What does a transaction with "COMMIT" and "ROLLBACK" provide?

7

What does the ACID acronym stand for in the context of database transactions?

8

What is the purpose of "GROUP BY" combined with "HAVING COUNT(*) > 1"?

9

What is a "composite key"?

10

What does "CASE WHEN condition THEN result ELSE other_result END" provide in a SELECT statement?

11

What is database normalization?

12

What is the difference between "DELETE", "TRUNCATE", and "DROP" for removing data from a table?

13

What does a window function with "OVER (PARTITION BY column)" do, e.g. "SUM(amount) OVER (PARTITION BY dept)"?

14

What is the purpose of the "EXISTS" operator in a subquery?

15

What is a "CTE" (Common Table Expression), defined with WITH?

16

What does the "ON DELETE CASCADE" option on a foreign key do?

17

What is the difference between a clustered index and a non-clustered index?

18

What does "GROUP BY" require regarding columns in the SELECT list (in standard SQL)?

19

What does "RIGHT JOIN" return that differs from "LEFT JOIN"?

20

What is the effect of "SELECT ... FOR UPDATE" in a transaction?

21

What does the "COALESCE(a, b, c)" function return?

22

What is the difference between "WHERE" and "ON" clauses when used with JOINs?

23

What does "DENSE_RANK()" return differently from "RANK()" in a window function?

24

What is the purpose of "EXPLAIN" (or "EXPLAIN PLAN") before a query?

25

What does a "self-referencing foreign key" typically model, e.g. an "employees" table with a "manager_id" column referencing "employees.id"?

26

What does "INSERT INTO table (cols) SELECT cols FROM other_table" accomplish?

27

What does "ANY" / "SOME" do when used with a comparison operator and a subquery, e.g. "WHERE salary > ANY (subquery)"?

28

What is the purpose of "GENERATED ALWAYS AS IDENTITY" (or AUTO_INCREMENT in MySQL)?

29

What does the "CROSS JOIN" produce?

30

What does "SELECT TOP 10 PERCENT * FROM table ORDER BY score DESC" (SQL Server syntax) accomplish?

31

What is a "materialized view" and how does it differ from a regular view?

32

What does the "LEAD()" / "LAG()" window functions do?

33

What is the purpose of "CHECK" constraints?

34

What does "FULL OUTER JOIN" return?

35

What does "ROUND(123.456, 2)" return?

36

What is the purpose of the "STRING_AGG" / "GROUP_CONCAT" function?

37

What does adding "WITH CHECK OPTION" to a view definition enforce?

38

What is the effect of using a transaction with "SAVEPOINT"?

39

What does "CAST(column AS DECIMAL(10,2))" do?

40

What does the "OFFSET" clause do when combined with LIMIT, e.g. "LIMIT 10 OFFSET 20"?

1

What is the difference between the four standard transaction isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE)?

2

What is a "deadlock" in a database, and how do most database systems handle it?

3

What is the purpose of "query plan caching" and how can parameterized queries affect it?

4

How does a recursive CTE (Common Table Expression) work, e.g. for traversing a hierarchy?

5

What is the difference between "covering index" and a regular index?

6

What problem does "MVCC" (Multi-Version Concurrency Control), used by databases like PostgreSQL and MySQL InnoDB, solve?

7

What does "SARGable" mean in the context of a WHERE clause predicate, and why does it matter for performance?

8

What is the purpose of "PARTITIONING" a large table (e.g. by date range)?

9

What is the "N+1 query problem" often encountered in application code using an ORM, and how does SQL help avoid it?

10

What is the difference between a "hash join", "merge join" (sort-merge join), and "nested loop join" as physical join strategies?

11

What is "write-ahead logging" (WAL) and why is it important for durability?

12

What is the difference between "optimistic locking" and "pessimistic locking" concurrency control strategies?

13

What is a "lateral join" (or CROSS APPLY in SQL Server) used for?

14

What does "denormalization" trade off, and when might it be appropriate?

15

What is a "phantom read" anomaly, and which isolation level is required to fully prevent it according to the SQL standard?

16

What is the purpose of "UPSERT" (e.g. "INSERT ... ON CONFLICT DO UPDATE" in PostgreSQL or "ON DUPLICATE KEY UPDATE" in MySQL)?

17

What does "query plan parameter sniffing" mean in the context of stored procedures, and what issue can it cause?

18

What is the difference between a "scalar subquery" and a "correlated subquery"?

19

What does "GROUPING SETS", "CUBE", and "ROLLUP" extend GROUP BY to do?

20

What is the practical significance of the difference between "NOT IN (subquery)" and "NOT EXISTS (correlated subquery)" when the subquery can return NULL values?