BHARATLINKR
TOP 100
IMPORTANT
SQL INTERVIEW
QUESTIONS
YOUR ONE STOP FOR LAST MINUTE PREPARATIONS
Most Asked SQL Questions
1. What is SQL?
➔ SQL (Structured Query Language) is a programming language used for
managing relational databases. It allows users to store, manipulate, and retrieve
data from databases.
2. What are the different types of SQL statements?
➔ SQL statements can be categorized into three types:
• Data Definition Language (DDL): Used for creating, altering, and
dropping database objects.
• Data Manipulation Language (DML): Used for querying, inserting,
updating, and deleting data.
• Data Control Language (DCL): Used for controlling access to the
database, granting or revoking privileges.
3. What is a primary key?
➔A primary key is a column or a set of columns that uniquely identifies each
record in a table. It ensures data integrity and allows efficient retrieval of data.
4. What is a foreign key?
➔ A foreign key is a column or a set of columns in a table that refers to the
primary key of another table. It establishes a relationship between the two
tables.
5. What is a composite key?
➔ A composite key is a primary key composed of two or more columns.
Together, these columns uniquely identify each record in a table.
6. What is the difference between DELETE and TRUNCATE?
➔ DELETE is a DML statement used to remove specific rows from a table,
whereas TRUNCATE is a DDL statement used to remove all rows from a table,
effectively resetting the table.
7. What is a subquery?
➔ A subquery is a query nested within another query. It can be used to retrieve
data from one table based on values from another table or perform complex
calculations.
8. What is the difference between a subquery and a join?
➔ A subquery is a query nested within another query, whereas a join is used to
combine rows from two or more tables based on related columns.
9. What is a self-join?
➔ A self-join is a join operation where a table is joinedwith itself. It is useful
when you want to compare rows within the same table.
10. What are the different types of JOIN operations?
➔ The different types of JOIN operations are:
• INNER JOIN: Returns onlythe matching rows from both tables.
• LEFT JOIN: Returns all rowsfrom the left table and matching rows
fromtheright table.
• RIGHT JOIN: Returns allrowsfrom the right table and matching rows
fromtheleft table.
• FULL JOIN: Returnsall rowsfrom both tables.
11. What is normalization in SQL?
➔ Normalization is the process oforganizing data in a database to eliminate
redundancy and dependency [Link] splitting tables into smaller,
more manageable entities.
12. What are the different normal forms in database normalization?
➔ The different normal forms are:
• First Normal Form (1NF): Eliminates duplicate rows and ensures
atomicity of values.
• Second Normal Form (2NF): Ensures that each non-key column
dependsontheentireprimary key.
• Third Normal Form (3NF): Ensures that each non-key column depends
onlyontheprimarykeyand not on other non-key columns.
• Fourth Normal Form (4NF): Eliminates multi-valued dependencies.
• Fifth Normal Form (5NF): Eliminates join dependencies.
13. What is an index?
➔ An index is a database structure that improves the speed of data retrieval
operations on database tables. It allows faster searching, sorting, and filtering of
data.
14. What is a clustered index?
➔ A clustered index determines the physical order of data in a table. Each table
can have only one clustered index, and it is generally created on the primary key
column(s).
15. What is a non-clustered index?
➔ A non-clustered index is a separatestructure from the table that contains a
sorted list of selected columns. It enhances the performance of searching and
filtering operations.
16. What is the difference between a primary key and a unique key?
➔
A primary key is a column or a set of columns that uniquely identifieseach
record in a table and cannot contain NULL values. A unique key, on theother
hand, allows NULL values and enforces uniqueness but does not automatically
define the primary identifier of a table.
17. What is ACID in database transactions?
➔
ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set
of properties that ensure reliability and integrity in database transactions.
18. What is the difference between UNION and UNION ALL?
➔ UNION combinesthe result sets of two or more SELECT statements and
removes duplicates,whereas UNION ALL combines the result sets without
removing duplicates.
19. What is a view?
➔
A view is a virtualtable derivedfrom one or more tables. It does not store
data but provides a way to presentdata in a customized or simplified manner.
20. What is a stored procedure?
➔
A stored procedure is a precompiled set of SQL statements that performs a
specific task. It can be called and executed multiple times with different
parameters.
21. What is a trigger?
➔
A trigger is a set ofSQL statements that are automatically executed in
response to a specificevent, such as INSERT, UPDATE, or DELETE operations
on a table.
22. What is a transaction?
➔ A transaction is a logicalunit of work that consists of one or more database
operations. It ensures that alloperations within the transaction are treated as a
single unit, either all succeeding or all failing.
23. What is a deadlock?
➔ A deadlock is a situation where two or more transactions are unable to
proceed because each is waiting for a resource held by another transaction. This
can result in a perpetual wait state.
24. What is the difference between CHAR and VARCHAR data types?
➔ CHAR is a fixed-length character data type that stores a specific number of
characters, while VARCHAR is a variable-length character data type that stores
a varying number of characters.
25. What is the difference between a function and a stored procedure?
➔ A function returns a value and can be used in SQL statements, whereasa
stored procedure does not return a value directly but can perform various
actions.
26. What is the difference between GROUP BY and HAVING clauses?
➔ GROUP BY is used to group rows based on one or more columns, while
HAVING is used to filter grouped rows based on specific conditions.
27. What is the difference between a database and a schema?
➔ A database is a collectionofrelated data that is stored and organized. A
schema, on the other hand, isalogical container within a database that holds
objects like tables, views, andprocedures.
28. What is a data warehouse?
➔ A data warehouse is a large repository of data collected from various
sources, structured and organized to support business intelligence and reporting.
29. What is the difference between OLTP and OLAP?
➔ OLTP (Online Transaction Processing) is used for day-to-day transactional
operations and focuses on real-time processing. OLAP (Online Analytical
Processing) is used for complex analytical queries and focuses on historical data
analysis.
30. What is a correlated subquery?
➔ A correlated subquery is a subquerythat references columns from the outer
query. It is executed for each row of theouter query, making it dependent on the
outer query's results.
31. What is the difference between a temporary table and a table variable?
➔ A temporary table is a physical table that is created and used temporarily
within a session or a specific scope, whereas a table variable is a variable with a
structure similar to a table and exists only within the scope of a user-defined
function or a stored procedure.
32. What is the difference between UNION and JOIN?
➔ UNION combines rows from two or more tables vertically, while JOIN
combines columns from two or more tables horizontally based on related
columns.
33. What is the difference between WHERE and HAVING clauses?
➔ WHERE is used to filter rows before grouping in a query, while HAVING is
used to filter grouped rows after grouping.
34. What is the difference between a database and a data warehouse?
➔ A database is a collection of related data organized for transactional
purposes, while a data warehouse is a large repository of data organized for
analytical purposes.
35. What is the difference between a primary key and a candidate key?
➔A candidate key is a column or a set of columns that can uniquely identify
each record in a table. A primary key is a chosen candidate key that becomesthe
main identifier for the table.
36. What is the difference between a schema and a database?
➔ A database is a collection of related data, while a schema isalogical
container within a database that holds objects like tables, views,and procedures.
37. What is a self-join?
➔ A self-join is a join operation where a table is joined with itself. It is used
when you want to compare rows within the same table.
38. What is a recursive SQL query?
➔ A recursive SQL query is a querythat refers to its own output in order to
perform additional operations. It is commonly used for hierarchical or tree-like
data structures.
39. What is the difference between a correlated subquery and a nested
subquery?
➔ A correlated subquery is a subquery that references columns from the outer
query, while a nested subquery is a subquery that is independent of the outer
query.
40. What is the difference between a natural join and an equijoin?
➔ A natural join is a join operation that automatically matches columnswith
the same name from both tables, whereas an equijoin is a join operationthat
explicitly specifies the join condition using equality operators.
41. What is the difference between an outer join and an inner join?
➔ An inner join returns only the matching rows from both tables, whereas an
outer join returns all rows from one table and matching rows from the other
table(s).
42. What is the difference between a left join and a right join?
➔ A left join returns all rows from the left table and matching rowsfrom the
right table, whereas a right join returns all rows from the right tableand
matching rows from the left table.
43. What is a full outer join?
➔ A full outer join returns allrows from both tables, including unmatched
rows, and combines them basedon the join condition.
44. What is a self-referencing foreign key?
➔ A self-referencing foreign key is a foreignkey that references the primary
key of the same table. It is used to establish hierarchical relationships within a
single table.
45. What is the purpose of the GROUP BY clause?
➔ The GROUP BY clause is used to group rows basedon one or more
columns. It is typically used with aggregate functionstoperform calculations on
each group.
46. What is the purpose of the HAVING clause?
➔ The HAVING clause is used to filter grouped rowsbased on specific
conditions. It operates on the results of the GROUP BYclause.
47. What is the purpose of the ORDER BY clause?
➔ The ORDER BY clause is used to sort the result setbased on one or more
columns in ascending or descending order.
48. What is the purpose of the DISTINCT keyword?
➔ The DISTINCT keyword is used to retrieve uniquevalues from a column in
a result set, eliminating duplicate rows.
49. What is the purpose of the LIKE operator?
➔ The LIKE operator is used in a WHERE clausetosearch for a specified
pattern in a column. It allows wildcard characterslike% (matches any sequence
of characters) and _ (matches any single character).
50. What is the purpose of the IN operator?
➔ The IN operator is used in a WHERE clauseto check if a value matches any
value in a list or a subquery.
51. What is the purpose of the BETWEEN operator?
➔ The BETWEEN operator is used in a WHERE clauseto check if a value lies
within a specified range of values, inclusive of the endpoints.
52. What is the purpose of the EXISTS operator?
➔ The EXISTS operator is used in a WHERE clausetocheck if a subquery
returns any rows. It returns true if the subquery resultsetisnot empty.
53. What is the purpose of the COUNT() function?
➔ The COUNT() function is used to count the numberofrows or non-null
values in a column.
54. What is the purpose of the SUM() function?
➔ The SUM() function is used to calculate the sumof values in a column.
55. What is the purpose of the AVG() function?
➔ The AVG() function is used to calculate the average value of a column.
56. What is the purpose of the MAX() function?
➔ The MAX() function is used to retrieve the maximum value from a column.
57. What is the purpose of the MIN() function?
➔ The MIN() function is used to retrieve the minimum value fromacolumn.
58. What is the purpose of the GROUP_CONCAT() function?
➔ The GROUP_CONCAT() function is usedtoconcatenate valuesfrom
multiple rows into a single string, grouped byaspecific column.
59. What is the purpose of the JOIN keyword?
➔ The JOIN keyword is used to combine rows from two or more tables based
on related columns.
60. What is a self-referencing table?
➔ A self-referencing table is a table that has a foreign key column referencing
its own primary key. It is used to represent hierarchical relationships within a
single table.
61. What is the difference between UNION and UNION ALL?
➔ UNION combines the result sets of two or more SELECT statements and
removes duplicate rows, whereas UNION ALL combines the result sets without
removing duplicates.
62. What is the purpose of the ROW_NUMBER() function?
➔ The ROW_NUMBER() function assigns a uniquesequentialnumber to each
row within a result set. It is often used for paginationor rankingpurposes.
63. What is the purpose of the RANK() function?
➔ The RANK() function assigns a rank to each rowwithin a result set based on
a specified criteria, such as ordering by a column. Itallows you to identify the
ranking of each row.
64. What is the purpose of the DENSE_RANK() function?
➔ The DENSE_RANK() function is similar to the RANK()function but
assigns consecutive ranks to rows without gaps. If two rowshave the same rank,
the next rank is skipped.
65. What is the purpose of the LAG() function?
➔ The LAG() function is used to access the valueofa previous row within a
result set based on a specified column. It allows youto compare values across
adjacent rows.
66. What is the purpose of the LEAD() function?
➔The LEAD() function is used to access the valueofa subsequent row within
a result set based on a specified column. It allows youto compare values across
adjacent rows.
67. What is the purpose of the COALESCE() function?
➔ The COALESCE() function is used to return the first non-null value from a
list of expressions. It is often used to provide a default value when a column
value is null.
68. What is the purpose of the CASE statement?
➔ The CASE statement is used to perform conditional logic within a SQL
statement. It allows you to evaluate multiple conditions and return different
values based on the result.
69. What is the purpose of the TRUNCATE TABLE statement?
➔ The TRUNCATE TABLE statement is used to remove all rowsfrom a table,
while keeping the table structure intact. It is faster than deleting allrows using
the DELETE statement.
70. What is the purpose of the CONSTRAINT keyword?
➔The CONSTRAINT keyword is used to define rules andrelationships on
columns within a table. It ensures data integrity and enforcesbusiness rules.
71. What is the purpose of the PRIMARY KEY constraint?
➔ The PRIMARY KEY constraint is used to uniquely identifyeach record in a
table. It ensures that the primary key column(s) have unique values and cannot
contain null values.
72. What is the purpose of the FOREIGN KEY constraint?
➔ The FOREIGN KEY constraint is used to establish a relationship between
two tables based on a common column. It ensures referential integrity by
enforcing that values in the foreign key column exist in the referenced table's
primary key.
73. What is the purpose of the INDEX keyword?
➔ The INDEX keyword is used to create an indexonone or more columns of a
table. It improves query performance by allowingfaster data retrieval based on
the indexed columns.
74. What is the purpose of the CASCADE keyword in a FOREIGN KEY
constraint?
➔ The CASCADE keyword is used to specify that changes made to the
primary key values in the referenced table should be propagated to the foreign
key values in the referring table. This ensures that the relationship remains
valid.
75. What is the purpose of the UPDATE statement?
➔ The UPDATE statement is used to modify existingrecords in a table. It
allows you to change the values of one or more columnsbased on specified
conditions.
76. What is the purpose of the DELETE statement?
➔ The DELETE statement is used to remove one or morerecords from a table.
It allows you to delete rows based on specified conditions.
77. What is the purpose of the COMMIT statement?
➔ The COMMIT statement is used to permanently saveallchanges made
within a transaction to the database. Once committed, thechanges are visible to
other users.
78. What is the purpose of the ROLLBACK statement?
➔ The ROLLBACK statement is used to undo all changesmade within a
transaction and restore the database to its previous [Link] used
when an error occurs or when the transaction needs to becanceled.
79. What is the purpose of the SAVEPOINT statement?
➔ The SAVEPOINT statement is used to define a specificpoint within a
transaction to which you can roll back. It allows you to undochanges up to a
specific savepoint without rolling back the entire transaction.
80. What is the purpose of the CONSTRAINT keyword in the ALTER
TABLE statement?
➔ The CONSTRAINT keyword in the ALTER TABLE statement is used to
add, modify, or drop constraints on columns within an existing table.
81. What is the purpose of the DISTINCT keyword in the SELECT
statement?
➔ The DISTINCT keyword in the SELECT statement is used to retrieve unique
values from a column in the result set, eliminating duplicate rows.
82. What is the purpose of the AS keyword in the SELECT statement?
➔The AS keyword in the SELECT statement is used to assign an alias toa
column or a table. It allows you to refer to the column or table by the assigned
alias in subsequent parts of the query.
83. What is the purpose of the ORDER BY clause in the SELECT
statement?
➔ The ORDER BY clause in the SELECT statement is used to sort the result
set based on one or more columns in ascending or descending order.
84. What is the purpose of the GROUP BY clause in the SELECT
statement?
➔The GROUP BY clause in the SELECT statement is used to group rows
based on one or more columns. It is typically used with aggregate functions to
perform calculations on each group.
85. What is the purpose of the HAVING clause in the SELECT statement?
➔ The HAVING clause in the SELECT statement is used to filter grouped rows
based on specific conditions. It operates on the results of the GROUP BY
clause.
86. What is the purpose of the LIMIT clause in the SELECT statement?
➔ The LIMIT clause in the SELECT statement is used to restrict the numberof
rows returned by a query. It allows you to specify the maximum number of rows
to be retrieved.
87. What is the purpose of the OFFSET clause in the SELECT statement?
➔ The OFFSET clause in the SELECT statement is used in conjunction with
the LIMIT clause to skip a specified number of rows before starting to return
the result set.
88. What is the purpose of the JOIN keyword in the SELECT statement?
➔ The JOIN keyword in the SELECT statement is used to combine rows from
two or more tables based on related columns. It allows you to retrieve data from
multiple tables in a single query.
89. What is the purpose of the INNER JOIN?
➔ The INNER JOIN is a join operation that returns only the matching rows
from both tables based on the specified join condition. It combines rows that
have matching values in the joined columns.
90. What is the purpose of the LEFT JOIN?
➔ The LEFT JOIN is a join operation that returns all rows from the left table
and the matching rows from the right table based on the specified join
condition. If no match is found, null values are returned for the right table
columns.
91. What is the purpose of the RIGHT JOIN?
➔ The RIGHT JOIN is a join operation that returns all rows from the right
table and the matching rows from the left table based on the specified join
condition. If no match is found, null values are returned for the left table
columns.
92. What is the purpose of the FULL OUTER JOIN?
➔ The FULL OUTER JOIN is a join operation that returns all rows from both
tables, including unmatched rows, and combines them based on the join
condition. If no match is found, null values are returned for the respective
columns.
93. What is the purpose of the UNION operator?
➔ The UNION operator is used to combine the resultsets of two or more
SELECT statements into a single result set. It removesduplicate rows from the
final result set.
94. What is the purpose of the UNION ALL operator?
➔ The UNION ALL operator is used to combine the resultsets of two or more
SELECT statements into a single result set, including duplicate rows.
95. What is the purpose of the LIKE operator in the WHERE clause?
➔The LIKE operator is used in the WHERE clause to search for a specified
pattern in a column. It allows wildcard characters like % (matches any sequence
of characters) and _ (matches any single character).
96. What is the purpose of the IN operator in the WHERE clause?
➔ The IN operator is used in the WHERE clause to check if a value matches
any value in a list or a subquery.
97. What is the purpose of the EXISTS operator in the WHERE clause?
➔ The EXISTS operator is used in the WHERE clause to check if a subquery
returns any rows. It returns true if the subquery result set is not empty.
98. What is the purpose of the GROUP BY clause in the SELECT
statement?
➔The GROUP BY clause in the SELECT statement is used to group rows
based on one or more columns. It is typically used with aggregate functions to
perform calculations on each group.
99. What is the purpose of the ORDER BY clause in the SELECT
statement?
➔ The ORDER BY clause in the SELECT statement is used to sort the result
set based on one or more columns in ascending or descending order.
100. What is the purpose of the DISTINCT keyword in the SELECT
statement?
➔ The DISTINCT keyword in the SELECT statement is used to retrieve unique
values from a column in the result set, eliminating duplicate rows.
BHARATLINKR
FROM PREPARATION
TO PLACEMENT,
WE’VE GOT YOU.
JOIN US NOW
FOR MORE SUCH CONTENT
FOLLOW US ON :
VISIT US AT :