AI-assisted, automatically checked• Updated August 2026

SQL MCQs

SQL multiple choice questions covering SELECT queries, joins, aggregations, subqueries, and indexing.

53 MCQs2 subtopicsProgrammingAll Levels
Key Concept Overview & Exam Context

Review core principles of SQL before answering questions. These questions simulate placement technical assessments (TCS, Infosys, Amazon), university exams (CS/IT), and technical certifications.

Target Readiness
Placements & Job Interviews
Question Format
Multiple-Choice with Explanations
Explained Solutions
Written explanations

Core SQL Fundamentals Quiz

10 questions · Interactive timed test · Instant score & review

Browse by Subtopic

SQL MCQ Questions

Page 1 of 2 (53 total)
Q1

What is the difference between DELETE and TRUNCATE in SQL?

medium
View Answer & Explanation
Correct Answer: DELETE removes rows one at a time and can be rolled back, while TRUNCATE removes all rows at once and is generally faster
Explanation:
DELETE is a logged, row by row operation that supports a WHERE clause and can be undone within a transaction, while TRUNCATE deallocates the data pages directly and typically cannot target specific rows.
Q2

What does the UNION operator do in SQL?

medium
View Answer & Explanation
Correct Answer: Combines the results of two or more SELECT queries and removes duplicate rows
Explanation:
UNION requires each SELECT statement to return the same number of columns with compatible data types, and it automatically removes duplicate rows from the combined result unless UNION ALL is used instead.
Q3

What is the difference between UNION and UNION ALL?

medium
View Answer & Explanation
Correct Answer: UNION removes duplicate rows from the combined result, while UNION ALL keeps every row including duplicates
Explanation:
Because UNION has to check for and remove duplicates, it is generally slower than UNION ALL, which simply appends all rows together without any comparison step.
Q4

What does the SQL EXISTS operator check for?

medium
View Answer & Explanation
Correct Answer: Whether a subquery returns at least one row
Explanation:
EXISTS returns true as soon as the subquery produces a single matching row, and it stops evaluating further rows, which often makes it more efficient than IN for large datasets.
Q5

What is the purpose of a composite primary key in a table?

medium
View Answer & Explanation
Correct Answer: To uniquely identify a row using a combination of two or more columns together
Explanation:
A composite primary key is used when no single column can guarantee uniqueness on its own, but the combination of two or more columns together can, such as a table tracking student enrollment in courses.
Q6

What does the SQL constraint UNIQUE ensure?

easy
View Answer & Explanation
Correct Answer: That all values in a column, or set of columns, are different from one another across rows
Explanation:
Unlike a primary key, a UNIQUE constraint can allow NULL values in most database systems, but any actual value that is entered must not already exist elsewhere in that column.
Q7

What is a subquery in SQL?

easy
View Answer & Explanation
Correct Answer: A query nested inside another SQL query, often used within a WHERE or FROM clause
Explanation:
A subquery is evaluated first, and its result is then used by the outer query, which makes it useful for filtering based on values that themselves need to be computed with a separate SELECT statement.
Q8

What is the purpose of the SQL ALTER TABLE statement?

easy
View Answer & Explanation
Correct Answer: To modify the structure of an existing table, such as adding or removing a column
Explanation:
ALTER TABLE is used for structural changes like adding a new column, changing a column's data type, or adding a constraint, as opposed to UPDATE, which changes the actual data within existing rows.
Q9

What does a RIGHT JOIN return?

medium
View Answer & Explanation
Correct Answer: All rows from the right table, along with matching rows from the left table, filling with NULL where there is no match
Explanation:
A RIGHT JOIN is essentially the mirror image of a LEFT JOIN, guaranteeing every row from the right table appears in the result even if there is no corresponding match on the left side.
Q10

What is the purpose of the SQL DISTINCT keyword?

easy
View Answer & Explanation
Correct Answer: To remove duplicate rows from the result set of a query
Explanation:
When placed right after SELECT, DISTINCT ensures that only unique combinations of the selected columns appear in the output, collapsing any rows that would otherwise be exact duplicates.
Q11

What is a trigger in SQL?

hard
View Answer & Explanation
Correct Answer: A stored procedure that automatically executes in response to a specific event on a table, such as an insert or update
Explanation:
Triggers run automatically when the defined event occurs, without needing to be explicitly called, which makes them useful for enforcing business rules or maintaining audit logs whenever data changes.
Q12

What is the difference between the WHERE clause and the HAVING clause in SQL?

medium
View Answer & Explanation
Correct Answer: WHERE filters individual rows before grouping, while HAVING filters groups after GROUP BY has been applied
Explanation:
Because aggregate functions like SUM or COUNT do not exist until after grouping happens, any condition involving them must go in the HAVING clause rather than WHERE.
Q13

What does the SQL LIKE operator allow you to do?

easy
View Answer & Explanation
Correct Answer: Search for a specified pattern within a column using wildcard characters
Explanation:
LIKE is typically used with wildcards such as the percent sign to match any sequence of characters or an underscore to match a single character, making it useful for partial text searches.
Q14

What is the purpose of the SQL COALESCE function?

medium
View Answer & Explanation
Correct Answer: To return the first non-NULL value from a list of expressions
Explanation:
COALESCE is commonly used to provide a default or fallback value when a column might contain NULL, evaluating each argument in order and returning the first one that is not NULL.
Q15

What is the effect of adding a NOT NULL constraint to a column?

easy
View Answer & Explanation
Correct Answer: It prevents that column from storing NULL values in any row
Explanation:
Attempting to insert or update a row without providing a value for a NOT NULL column will cause the database to reject the operation with a constraint violation error.
Q16

What does the SQL BETWEEN operator do?

easy
View Answer & Explanation
Correct Answer: Selects values within a given inclusive range
Explanation:
BETWEEN checks whether a value falls within a specified minimum and maximum, and both boundary values are included in the match, unlike some range comparisons that exclude the endpoints.
Q17

What is a natural join in SQL?

hard
View Answer & Explanation
Correct Answer: A join that automatically matches columns with the same name and compatible data type across both tables
Explanation:
Because a natural join relies on column names matching automatically, it can behave unpredictably if the schema changes, which is why many developers prefer explicitly specifying the join condition instead.
Q18

What is the purpose of the SQL CASE expression?

medium
View Answer & Explanation
Correct Answer: To perform conditional logic within a query, returning different values based on specified conditions
Explanation:
CASE works similarly to an if-else structure, evaluating each condition in order and returning the result associated with the first one that is true, which is useful for creating computed columns in a SELECT statement.
Q19

What does an outer join guarantee that an inner join does not?

medium
View Answer & Explanation
Correct Answer: It includes rows from one or both tables even when there is no matching row in the other table
Explanation:
While an inner join discards any row that lacks a match on the other side, an outer join, whether LEFT, RIGHT, or FULL, preserves those unmatched rows and fills the missing columns with NULL.
Q20

What is the purpose of the SQL AS keyword?

easy
View Answer & Explanation
Correct Answer: To assign a temporary alias to a column or table for the duration of a query
Explanation:
Aliases created with AS make query output more readable or shorten long table names when writing joins, but they only exist for that specific query and do not change the underlying schema.
Q21

What does it mean for a SQL query to use a window function?

hard
View Answer & Explanation
Correct Answer: It performs a calculation across a set of rows related to the current row without collapsing them into a single result, unlike GROUP BY
Explanation:
Window functions such as ROW_NUMBER or RANK let you compute running totals or rankings while still returning one row per original row, which is different from GROUP BY, which reduces multiple rows into one summary row per group.
Q22

What is the purpose of the SQL INDEX statement when creating an index manually?

medium
View Answer & Explanation
Correct Answer: It speeds up data retrieval on a column by creating a separate lookup structure
Explanation:
Manually created indexes are especially useful on columns that are frequently searched or joined on, though every index adds some overhead to insert and update operations.
Q23

What does the SQL 'IN' operator allow you to do?

easy
View Answer & Explanation
Correct Answer: It checks whether a value matches any value in a specified list or subquery
Explanation:
Using IN with a list, such as WHERE country IN ('India','USA'), is often a cleaner alternative to chaining several OR conditions together.
Q24

What is a correlated subquery in SQL?

hard
View Answer & Explanation
Correct Answer: A subquery that references a column from the outer query and is re-evaluated for each row of the outer query
Explanation:
Because a correlated subquery runs once per outer row, it can be slower on large tables compared to an equivalent join, though it is sometimes the clearest way to express a condition.
Q25

What is the purpose of the SQL 'IS NULL' condition?

medium
View Answer & Explanation
Correct Answer: It checks whether a column value is missing or unknown, since NULL cannot be compared using the equals operator
Explanation:
Writing WHERE column = NULL never returns any rows because NULL represents an unknown value, which is why SQL provides the dedicated IS NULL comparison instead.
Q26

What does the SQL 'LIMIT' clause do, and what is its equivalent called in some other databases?

easy
View Answer & Explanation
Correct Answer: It restricts the number of rows returned by a query, and it is sometimes called TOP or FETCH FIRST in other systems
Explanation:
LIMIT is commonly used together with ORDER BY to fetch, for example, only the top 5 highest paid employees from a larger result set.
Q27

What is the purpose of the SQL 'GRANT' statement?

medium
View Answer & Explanation
Correct Answer: It gives specific users or roles permission to perform certain actions on database objects
Explanation:
GRANT is a core part of SQL's access control system, letting a database administrator allow specific privileges like SELECT or INSERT on particular tables to particular users.
Q28

What is the difference between a full outer join and an inner join?

medium
View Answer & Explanation
Correct Answer: A full outer join returns all rows from both tables, filling in NULLs where there is no match, while an inner join returns only rows with matches in both tables
Explanation:
Because a full outer join keeps unmatched rows from both sides, it is useful when you want to see everything, including records that have no corresponding match in the other table.
Q29

What is the purpose of a common table expression (CTE) introduced with the WITH keyword?

hard
View Answer & Explanation
Correct Answer: It defines a temporary named result set that can be referenced within a single SQL statement to make complex queries more readable
Explanation:
CTEs are often used to break a complicated query into smaller, named steps, and they can also be used to write recursive queries for things like hierarchical data.
Q30

What is the effect of the SQL 'DEFAULT' constraint on a column?

easy
View Answer & Explanation
Correct Answer: It automatically assigns a specified value to a column if no value is provided during an insert
Explanation:
A DEFAULT constraint is handy for things like a 'created_at' timestamp or a status column that should start as 'pending' unless specified otherwise.
Q31

What is the purpose of the SQL 'ANY' and 'ALL' operators used with a subquery?

hard
View Answer & Explanation
Correct Answer: ANY returns true if the comparison holds for at least one value returned by the subquery, while ALL requires it to hold for every value
Explanation:
For example, WHERE salary > ALL (subquery) checks that a salary is greater than every value returned by the subquery, while ANY only requires it to beat at least one of them.
Q32

What is the purpose of the SQL 'RENAME' or equivalent statement for changing a table's name?

easy
View Answer & Explanation
Correct Answer: It changes the name of an existing table without affecting its data or structure
Explanation:
Renaming a table is often used during refactoring or migrations, and the underlying data and column definitions remain exactly as they were before.
Q33

What is a foreign key constraint used for in SQL?

easy
View Answer & Explanation
Correct Answer: It enforces a link between a column in one table and the primary key of another table, maintaining referential integrity
Explanation:
A foreign key constraint stops you from inserting a value that does not exist in the referenced table, which helps keep related data consistent across tables.
Q34

What does the SQL 'OFFSET' keyword typically do when used with a query?

medium
View Answer & Explanation
Correct Answer: It skips a specified number of rows before starting to return results, often used for pagination
Explanation:
OFFSET is commonly paired with LIMIT or FETCH to implement paging through results, such as skipping the first 20 rows to show the next page of a list.
Q35

What is the purpose of using aliases with the SQL 'AS' keyword in a JOIN query?

easy
View Answer & Explanation
Correct Answer: It gives shorter or more readable names to tables or columns, making complex joins easier to write and read
Explanation:
Aliases are especially useful when a query joins the same table to itself, since each reference to the table needs its own distinct name to avoid ambiguity.
Q36

What is the effect of using DISTINCT together with multiple columns in a SELECT statement?

medium
View Answer & Explanation
Correct Answer: It returns unique combinations of the specified columns, rather than unique values in just one column
Explanation:
So SELECT DISTINCT city, state would treat two rows as duplicates only if both the city and state match exactly, not just one of the two.
Q37

What is the purpose of the SQL 'CASCADE' option on a foreign key constraint?

hard
View Answer & Explanation
Correct Answer: It automatically applies related changes, such as deleting or updating matching rows in a child table when the parent row is deleted or updated
Explanation:
ON DELETE CASCADE, for instance, means that deleting a customer would automatically delete all of that customer's related orders in a linked table.
Q38

What is the purpose of the SQL 'INTERSECT' operator?

hard
View Answer & Explanation
Correct Answer: It returns only the rows that appear in the result sets of both queries being combined
Explanation:
INTERSECT is less commonly used than UNION, but it is handy when you need to find records that satisfy two separate conditions represented as two separate queries.
Q39

What is the purpose of the SQL 'EXCEPT' or 'MINUS' operator, depending on the database system?

hard
View Answer & Explanation
Correct Answer: It returns the rows from the first query that do not appear in the result of the second query
Explanation:
This is useful for finding, for example, customers who placed an order last year but have not placed one this year, by subtracting one result set from another.
Q40

What is the purpose of the SQL 'NOT NULL' constraint combined with 'DEFAULT'?

medium
View Answer & Explanation
Correct Answer: It ensures a column always has a value, using the default when none is explicitly provided during an insert
Explanation:
Combining these two constraints is a common pattern for columns like 'status' that should never be empty but also should not require the application to always specify a value.
Q41

What is the effect of adding an ORDER BY clause after a UNION of two SELECT statements?

hard
View Answer & Explanation
Correct Answer: It sorts the entire combined result set, and it must be placed only once at the end rather than after each individual SELECT
Explanation:
Most database systems require the ORDER BY to reference column names or positions from the final combined result, applied after the UNION has already merged the two queries.
Q42

What is the purpose of the SQL 'EXPLAIN' or 'EXPLAIN PLAN' statement?

medium
View Answer & Explanation
Correct Answer: It shows how the database engine intends to execute a query, including which indexes it plans to use
Explanation:
Developers often use EXPLAIN to diagnose slow queries, since it reveals whether the database is scanning an entire table instead of using an available index.
Q43

What does it mean for a column to have a 'UNIQUE' constraint but still allow NULL values?

hard
View Answer & Explanation
Correct Answer: Every non-null value in that column must be different, but more than one NULL is generally still allowed since NULL is treated as unknown
Explanation:
This behavior can differ slightly between database systems, but in most common systems NULL is not compared to other NULLs for uniqueness purposes, so several NULLs can coexist.
Q44

What is the purpose of a schema-level 'CREATE DATABASE' statement?

easy
View Answer & Explanation
Correct Answer: It creates a brand new, empty database container that can later hold tables and other objects
Explanation:
Once a database is created, tables, views, and other objects can be added inside it, but the CREATE DATABASE statement itself only sets up the container.
Q45

What is the purpose of the SQL 'BEGIN TRANSACTION' statement?

medium
View Answer & Explanation
Correct Answer: It marks the start of a group of SQL statements that should be treated as a single unit of work
Explanation:
Everything between BEGIN TRANSACTION and the following COMMIT or ROLLBACK is treated together, so either all the changes take effect or none of them do.
Q46

What is the purpose of the SQL 'IFNULL' or 'ISNULL' function, depending on the database system?

easy
View Answer & Explanation
Correct Answer: It returns a specified replacement value when a given expression evaluates to NULL
Explanation:
This function is handy for displaying something readable, such as showing 0 instead of a blank value when a quantity column happens to be NULL.
Q47

Which JOIN returns all rows from the left table and matching rows from the right table, filling with NULL where there is no match?

easy
View Answer & Explanation
Correct Answer: LEFT JOIN
Explanation:
LEFT OUTER JOIN (or LEFT JOIN) returns all records from the left table and matched records from the right table. If no match exists, NULL is returned for right table columns.
Q48

Which SQL clause is used to filter rows AFTER aggregating with GROUP BY?

easy
View Answer & Explanation
Correct Answer: HAVING
Explanation:
The HAVING clause is used to filter groups based on aggregate function results, whereas WHERE filters individual rows before grouping.
Q49

Which SQL clause is used to filter group results created by the GROUP BY clause?

easy
View Answer & Explanation
Correct Answer: HAVING
Explanation:
The HAVING clause is used to filter aggregated group records, whereas the WHERE clause filters individual rows before grouping.
Q50

Which join returns all rows from the left table, and matching rows from the right table, filling nulls if no match exists?

easy
View Answer & Explanation
Correct Answer: LEFT JOIN
Explanation:
A LEFT (OUTER) JOIN returns all rows from the left table regardless of whether there is a corresponding match in the right table.
Showing 1 to 50 of 53 questions