SQL Notes
SQL Notes
For Interview
Q 2. What is a database?
Ans: A database is an organized collection of data stored
and accessed electronically. It provides a way to
store, organize, and retrieve large amounts of data
efficiently.
01
Q 4. What is a foreign key?
Ans: A foreign key is a column or combination of columns
that establishes a link between data in two tables. It
ensures referential integrity by enforcing
relationships between tables.
02
Q 6. What is normalization?
Ans: Normalization is the process of organizing data in a
database to minimize redundancy and dependency.
It involves breaking down a table into smaller tables
and establishing relationships between them.
03
Q 9. What is the difference between DELETE and
TRUNCATE in SQL?
Ans: The DELETE statement is used to remove specific
rows from a table based on a condition. It can be
rolled back and generates individual delete
operations for each row.
04
Q 11. What is the difference between the HAVING
clause and the WHERE clause?
Ans: The WHERE clause is used to filter rows based on a
condition before the data is grouped or aggregated.
It operates on individual rows.
05
Q 13. What is the difference between a clustered
and a non-clustered index?
Ans: A clustered index determines the physical order of
data in a table. It changes the way the data is stored
on disk and can be created on only one column. A
table can have only one clustered index.
06
Q 14. What is ACID in the context of database
transactions?
Ans: ACID stands for Atomicity, Consistency, Isolation,
and Durability. It is a set of properties that guarantee
reliable processing of database transactions.
07
Q 15. What is a deadlock?
Ans: A deadlock occurs when two or more transactions
are waiting for each other to release resources,
resulting in a circular dependency. As a result, none
of the transactions can proceed, and the system may
become unresponsive.
07
Q 17. What is the difference between a temporary
table and a table variable?
Ans: A temporary table is a table that is created and exists
only for the duration of a session or a transaction. It
can be explicitly dropped or is automatically
dropped when the session or transaction ends.
07
Q 19. What is the difference between CHAR and
VARCHAR data types?
Ans: CHAR is a fixed-length string data type, while
VARCHAR is a variable-length string data type.
07
Q 22. What is a view?
Ans: A view is a virtual table based on the result of an SQL
statement. It allows users to retrieve and manipulate
data as if
07
Q 23. What is the difference between a cross join
and an inner join?
Ans: A cross join (Cartesian product) returns the
combination of all rows from two or more tables.
07
Q 26. What is the purpose of the NULL value in
SQL?
Ans: NULL represents the absence of a value or unknown
value. It is different from zero or an empty string and
requires special handling in SQL queries.
07
Q 28. What is a correlated subquery?
Ans: A correlated subquery is a subquery that refers to a
column from the outer query. It executes once for
each row processed by the outer query.
Q 29. What is the purpose of the DISTINCT
keyword?
Ans: The DISTINCT keyword is used to retrieve unique
values from a column or combination of columns in a
SELECT statement.
07
Q 31. What is the difference between the IN and
EXISTS operators?
Ans: The IN operator checks for a value within a set of
values or the result of a subquery. The EXISTS
operator checks for the existence of rows returned
by a subquery.
07
Q 34. What is the purpose of the TOP or LIMIT
clause?
Ans: The TOP (in SQL Server) or LIMIT (in MySQL) clause is
used to limit the number of rows returned by a
query. It is often used with an ORDER BY clause.
07
Q 36. What is a data warehouse?
Ans: A data warehouse is a large, centralized repository
that stores and manages data from various sources.
It is designed for efficient reporting, analysis, and
business intelligence purposes.
07
Q 38. What is the purpose of the GRANT statement?
Ans: The GRANT statement is used to grant specific
permissions or privileges to users or roles in a
database.
07
Q 40. What is the purpose of the CASE statement?
Ans: The CASE statement is used to perform conditional
logic in SQL queries. It allows you to return different
values based on specified conditions.
07
Q 43. What is the difference between a natural
join and an inner join?
Ans: A natural join is an inner join that matches rows
based on columns with the same name in the joined
tables. It is automatically determined by the
database.
07
Q 45. What is the purpose of the ALL keyword in
SQL?
Ans: The CASCADE DELETE constraint is used to
automatically delete related rows in child tables
when a row in the parent table is deleted.
07
Q 46. What is the difference between the EXISTS
and NOT EXISTS operators?
Ans: The EXISTS operator returns true if a subquery
returns any rows, while the NOT EXISTS operator
returns true if a subquery returns no rows.
07
Q 47. What is the purpose of the CROSS APPLY
operator?
Ans: The CROSS APPLY operator is used to invoke a table-
valued function for each row of a table expression. It
returns the combined result set.
07
Q 49. What is an ALIAS command?
Ans: ALIAS command in SQL is the name that can be given
to any table or a column. This alias name can be
referred in WHERE clause to identify a particular
table or a column.
07
07
+91-7260058093 www.algotutor.io info@algotutor.io