1. What is a database? What is a DBMS?
o A database is a collection of related data stored in an organized way. A DBMS
(Database Management System) is software that lets you create, manage, and
query databases. SQL Shack+1
2. What is an RDBMS? How is it different from DBMS?
o An RDBMS (Relational DBMS) stores data in structured tables with relations
(rows and columns), supports relationships between tables, enforces
constraints, and uses structured query language (SQL). In contrast, a plain
DBMS may not support relations or structured tables in the same way. SQL
Shack+1
3. What is a table in SQL? What are fields (columns) and records (rows)?
o A table is a structured set of data organized into columns (fields) and rows
(records). Columns define what type of data is stored (e.g. name, age), while
each row holds a single record’s values for those columns. Indeed+1
4. What are NULL values in SQL?
o NULL represents a missing or unknown value. It is different from zero or an
empty string. It means “no value” or “value not provided.” GeeksforGeeks+1
5. What is an SQL statement? Give examples.
o An SQL statement (or command) is a command interpreted by the database
engine to perform an action. Examples: SELECT, INSERT, UPDATE, DELETE,
CREATE TABLE, DROP TABLE, etc. [Link]+1
6. What are the different categories of SQL commands (subsets)?
o Common subsets include:
DDL (Data Definition Language): CREATE, ALTER, DROP, etc. — deals
with database structure. [Link]+1
DML (Data Manipulation Language): INSERT, UPDATE, DELETE, SELECT
— for manipulating data. [Link]+1
DCL (Data Control Language): commands controlling
access/permissions (depending on DBMS). [Link]+1
TCL (Transaction Control Language): commands for transactions
(commit, rollback, etc.) in many SQL flavours.
[Link]+1
7. What is a query in SQL?
o A query is a request to the database — usually to retrieve data or perform
some action like insert, update or delete. For example, a SELECT statement is
a query. Indeed+1
8. What is a subquery?
o A subquery is a query nested inside another query. It can be used in SELECT,
WHERE, FROM etc. For example, you might use a subquery to get a set of
values that the outer query will use. Indeed+1
9. What is a constraint in SQL? Give examples.
o Constraints are rules enforced on table columns to ensure data integrity.
Examples: PRIMARY KEY, UNIQUE, NOT NULL, DEFAULT, FOREIGN KEY.
[Link]+[Link]+2
10. What is a Primary Key? What is a Unique Key? How are they different?
o A Primary Key uniquely identifies each row in a table; it cannot have NULL
and there can be only one per table (though it can consist of multiple
columns). GeeksforGeeks+[Link]+2
o A Unique Key also enforces uniqueness, but can accept NULL values
(depending on DBMS), and you can have multiple unique keys per table.
GeeksforGeeks+1
11. What is a Foreign Key? What is referential integrity?
o A Foreign Key is a column (or set of columns) in one table that references a
Primary (or Unique) Key in another table. This ensures referential integrity —
i.e. relationships between tables remain consistent and valid.
GeeksforGeeks+[Link]+2
12. What is normalization in databases? Why is it important?
o Normalization is the process of organizing data in tables to minimize
redundancy and avoid update/insertion/deletion anomalies. It often involves
dividing larger tables into smaller, linked tables. This ensures data consistency
and efficient storage. GeeksforGeeks+[Link]+2
🔹 SQL Querying, Clauses & Operations
13. What is a SELECT statement?
o SELECT is used to retrieve data from one or more tables. It’s the most
frequently used command in SQL. GeeksforGeeks+1
14. What is the purpose of the WHERE clause?
o WHERE is used to filter rows returned by a query according to specified
conditions. For example: SELECT * FROM Employees WHERE salary > 50000.
Talentuner+1
15. What is ORDER BY clause?
o ORDER BY sorts the result set based on one or more columns, either in
ascending (ASC) or descending (DESC) order. GeeksforGeeks+1
16. What is GROUP BY clause? When would you use it?
o GROUP BY groups rows that have the same values in specified columns, often
used with aggregate functions (e.g. to compute sum, average per group). It
helps produce summarized results.
[Link]+[Link]+2
17. What is HAVING clause? How is it different from WHERE?
o HAVING is used to filter groups created by GROUP BY, whereas WHERE filters
individual rows before grouping. Use HAVING when you want to filter based
on aggregate conditions. (e.g. groups with SUM(sales) > 10000)
[Link]+2Indeed+2
18. What are SQL operators? Name some common types.
o Operators are symbols or keywords used to perform operations in queries.
Common types: arithmetic (+, -, *, /), comparison (=, >, <, >=, <=, <>), logical
(AND, OR, NOT), set operators (UNION, INTERSECT, EXCEPT), string operators
(depending on DBMS), etc. DataCamp+[Link]+2
19. What are aggregate functions? Give some examples.
o Aggregate functions perform calculations on a group of values and return a
single result. Examples: COUNT(), SUM(), AVG(), MIN(), MAX().
[Link]+2SQL Shack+2
20. What are scalar (single-row) functions? Give examples.
o Scalar functions operate on single values and return a single value. Examples:
string manipulation (e.g. UPPER(), LOWER(), SUBSTRING()), numeric functions
(ROUND()), date/time functions (NOW() in some DBs), etc.
[Link]+1
21. What is the difference between UNION and UNION ALL?
o UNION combines results of two queries and removes duplicates. UNION ALL
combines results and keeps all duplicates. (Note: UNION ALL is faster since it
doesn’t perform duplicate elimination). GeeksforGeeks+[Link]+2
22. What is a JOIN in SQL? Why do we use joins?
o A JOIN combines rows from two or more tables based on related columns
(like matching keys), enabling retrieval of related data stored across different
tables. Useful when data is normalized across tables.
[Link]+[Link]+2
23. What is an INNER JOIN?
o INNER JOIN returns only the rows where there is a match in both tables based
on the join condition. If there's no match, rows are excluded.
GeeksforGeeks+1
24. What is a LEFT JOIN (LEFT OUTER JOIN)?
o LEFT JOIN returns all rows from the left (first) table, and the matching rows
from the right table. If there’s no match, NULLs are returned for columns from
the right table. [Link]+[Link]+2
25. What is a RIGHT JOIN (RIGHT OUTER JOIN)?
o RIGHT JOIN returns all rows from the right table, and matched rows from the
left table. If there's no match, NULLs appear for left table columns. (Some
DBMS don’t support RIGHT JOIN explicitly — depends.)
[Link]+[Link]+2
26. What is a FULL OUTER JOIN?
o FULL OUTER JOIN returns rows when there is a match in one of the tables. It
returns all rows from both tables, with NULLs in places where no match
exists. (Note: Some DBMS implement this differently or via UNION of LEFT +
RIGHT JOIN). [Link]+1
27. What is a CROSS JOIN?
o CROSS JOIN produces the Cartesian product of two tables — every row from
the first table combined with every row of the second (i.e. all possible
combinations), irrespective of matching. Use when you intentionally need all
combinations. GeeksforGeeks+1
28. What is the difference between DELETE, TRUNCATE, and DROP?
o DELETE: removes specified rows; can include a WHERE clause, and the action
can usually be rolled back (in transaction).
o TRUNCATE: removes all rows from a table at once, but keeps the table
structure; faster than DELETE for large data.
o DROP: deletes the entire table (structure + data + indexes) from the database.
Talentuner+[Link]+2
29. What is a view in SQL? What are its advantages?
o A view is a virtual table derived from one or more tables (or other views). It
doesn’t store data itself (in many implementations), but provides a saved
query result. Advantages: simplifies complex queries, provides security
(restricting direct access to underlying tables), hides complexity, and offers
abstraction. [Link]+2SQL Shack+2
30. What is a stored procedure?
o A stored procedure is a precompiled group of SQL statements stored in the
database which can accept input parameters, run logic or multiple queries,
and return results. It enables reuse, improves maintainability, and may
improve performance. GeeksforGeeks+1
🔹 Data Integrity, Keys & Constraints
31. What is referential integrity?
o Referential integrity ensures that relationships between tables remain
consistent: a foreign key in a child table must always reference a valid
primary/unique key in the parent table — preventing “orphaned” records.
[Link]+2SQL Shack+2
32. What’s the difference between DDL and DML commands?
o DDL: Commands that define/modifies schema — CREATE, ALTER, DROP,
TRUNCATE, etc.
DML: Commands that manipulate data — SELECT, INSERT, UPDATE, DELETE.
GeeksforGeeks+[Link]+2
33. What is a default constraint?
o A default constraint assigns a default value to a column when no value is
provided during insertion. Ensures that a column has some valid data even if
a value is omitted. [Link]+1
34. What is the difference between UNIQUE constraint and NOT NULL constraint (in
context of keys)?
o UNIQUE ensures all values in the column (or set of columns) are distinct. NOT
NULL ensures no NULL values are allowed in that column. For a primary key,
both uniqueness and NOT NULL are implicit.
GeeksforGeeks+[Link]+2
🔹 Advanced Basics & Query Optimization (Still Beginner-Friendly)
35. What is an index in SQL? Why is it used?
o An index is a data structure built on one or more columns of a table; it speeds
up data retrieval (searches, queries) without scanning the entire table. It’s like
an index in a book — helps locate data quickly. However, indexes take extra
storage and can slow down data insertion/updating.
GeeksforGeeks+[Link]+2
36. What is a composite (multi-column) index?
o A composite index is an index built on multiple columns together. It’s useful
when queries filter or join tables on multiple columns — it can speed up such
queries more than separate indexes on individual columns. [Link]+1
37. What is a transaction? What are ACID properties?
o A transaction is a group of one or more SQL operations executed as a single
logical unit. Ideally, it either completes fully or doesn’t at all. ACID stands for
Atomicity, Consistency, Isolation, and Durability — properties that ensure
reliability and correctness of transactions. [Link]+1
38. What is a CTE (Common Table Expression)?
o A CTE is a temporary, named result set defined using WITH clause, which
exists only during the execution of a single SQL statement. It helps make
complex queries simpler and more readable, and can be used for recursion
(hierarchical data) or to avoid repeating subqueries. GeeksforGeeks+1
39. What is a correlated subquery vs a regular (nested) subquery?
o A nested subquery is independent — it doesn’t refer to columns of the outer
query.
o A correlated subquery refers to columns of the outer query and is evaluated
once per outer row, making it dependent on the outer query. Useful when
you need row-by-row comparisons.
[Link]+[Link]+2
40. What is query optimization? Why is it important?
o Query optimization is the process of improving SQL queries to make them run
faster and use fewer resources. This may involve using indexes, avoiding
unnecessary columns, using efficient joins, avoiding redundant subqueries,
etc. It’s important for performance, especially with large data.
[Link]+2SQL Shack+2
🔹 Functions, Joins, Set Ops — Mixed Concepts
41. What is the difference between scalar functions and aggregate functions?
o Scalar functions operate on a single row and return a single value (e.g.
UPPER(), SUBSTRING(), ROUND()). Aggregate functions work on a set of rows
(usually grouped) and return a single summarised value (e.g. SUM(), AVG(),
COUNT(), MAX()). [Link]+[Link]+2
42. What are set operations in SQL? Name some.
o Set operations combine results from two or more SELECT queries. Common
set operations: UNION, UNION ALL, INTERSECT, EXCEPT (or MINUS in some
SQL dialects). They require queries to have same number of columns and
compatible types. GeeksforGeeks+1
43. What is the difference between UNION and INTERSECT?
o UNION returns all distinct rows from both queries combined. INTERSECT
returns only rows that are common to both query results (intersection).
GeeksforGeeks+1
44. What is the difference between UNION and EXCEPT (or MINUS)?
o UNION merges results from two queries (distinct). EXCEPT (or MINUS) returns
rows from the first query that are not present in the second — effectively a
difference operation between sets. GeeksforGeeks+1
45. When would you use a subquery vs a JOIN?
o Use a subquery when you need to filter based on aggregated or derived
results, or when logic is easier to encapsulate as a subquery. Use a JOIN when
you want to retrieve related fields from multiple tables in a combined result
set — especially when there’s relational data. Subqueries may be easier for
nested logic; JOINs are efficient for relational data retrieval. (Note: tradeoffs
may depend on DBMS and query plan.)
46. What is a self-join? Provide a use case.
o A self-join is when a table is joined with itself. It’s useful when records in a
table are related to other records in the same table — for example,
employees having managers, where manager and employee both exist in the
same Employee table.
47. What is the difference between WHERE and HAVING clauses?
o WHERE filters rows before grouping/aggregation. HAVING filters groups after
aggregation. Use HAVING when you need conditions on aggregate results,
and WHERE for individual rows before grouping.
48. What is the difference between DROP TABLE and TRUNCATE TABLE?
o DROP TABLE removes the table entirely (data + structure). After drop, the
table no longer exists.
o TRUNCATE TABLE removes all the data from the table but retains the table
structure (columns, constraints) — you can still insert new data afterward.
Talentuner+[Link]+2
49. What is a view, and how does it differ from a table?
o A view is a virtual table defined by a query; it doesn’t necessarily store data
itself (depends on DBMS), but represents a saved view of data from one or
more real tables. Tables store actual data. Views help simplify complex
queries, enforce access control, and present data in a custom way without
duplication. [Link]+2SQL Shack+2
50. What is a trigger in SQL? What is its use?
o A trigger is a set of SQL statements that automatically executes (fires) in
response to certain events on a table (like INSERT, UPDATE, DELETE). It’s used
for enforcing business rules, maintaining audit logs, ensuring data integrity, or
synchronizing tables.