0% found this document useful (0 votes)
14 views8 pages

60 SQL Interview Questions and Answers

The document provides a comprehensive list of 60 short interview questions and answers on SQL, covering basic, intermediate, and advanced topics. Key concepts include SQL commands, data integrity, joins, normalization, and various SQL functions. It serves as a useful resource for individuals preparing for SQL-related interviews.

Uploaded by

Sarafat Ali Adir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

60 SQL Interview Questions and Answers

The document provides a comprehensive list of 60 short interview questions and answers on SQL, covering basic, intermediate, and advanced topics. Key concepts include SQL commands, data integrity, joins, normalization, and various SQL functions. It serves as a useful resource for individuals preparing for SQL-related interviews.

Uploaded by

Sarafat Ali Adir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

60 Short Interview Questions and Answers on SQL

Basic SQL Questions:


1. What is SQL?
Answer: SQL stands for Structured Query Language, used for managing and
manipulating relational databases.
2. What are the different types of SQL commands?
Answer: The types are DDL (Data Definition Language), DML (Data Manipulation
Language), DCL (Data Control Language), and TCL (Transaction Control
Language).
3. What is the primary key?
Answer: A primary key is a unique identifier for each record in a database table.
4. What is a foreign key?
Answer: A foreign key is a field in one table that uniquely identifies a row in
another table, thereby establishing a relationship between the two tables.
5. Explain the difference between DELETE and TRUNCATE commands.
Answer: DELETE removes specific rows from a table and can use a WHERE
clause, while TRUNCATE removes all rows from a table and resets its identity
value.
6. What is a JOIN in SQL?
Answer: A JOIN clause is used to combine rows from two or more tables, based on
a related column between them.
7. What are the different types of JOINs?
Answer: The types are INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER
JOIN, and CROSS JOIN.

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


8. What is normalization?
Answer: Normalization is the process of organizing data in a database to reduce
redundancy and improve data integrity.
9. What are the different normal forms?
Answer: The normal forms are 1NF (First Normal Form), 2NF (Second Normal
Form), 3NF (Third Normal Form), BCNF (Boyce-Codd Normal Form), and 4NF
(Fourth Normal Form).
10. What is a view in SQL?
Answer: A view is a virtual table based on the result set of an SQL statement.

Intermediate SQL Questions:


11. What is an index in SQL?
Answer: An index in SQL is used to speed up the retrieval of data from a database
table.
12. Explain the GROUP BY statement.
Answer: GROUP BY is used in collaboration with the aggregate functions to group
the result set by one or more columns.
13. What is a subquery?
Answer: A subquery is an SQL query nested inside a larger query.
14. What is a stored procedure?
Answer: A stored procedure is a set of SQL statements that can be stored in the
database.
15. Explain ACID properties in a database.
Answer: ACID stands for Atomicity, Consistency, Isolation, and Durability -
essential for ensuring database transactions are processed reliably.
16. What is a transaction in SQL?

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


Answer: A transaction is a sequence of operations performed as a single logical
unit of work.

17. What is the difference between UNION and UNION ALL?


Answer: UNION combines the results of two or more SELECT statements and
removes duplicate rows, while UNION ALL combines the results and does not
remove duplicates.
18. What are the constraints in SQL?
Answer: Constraints are rules enforced on data columns in a table. They are used
to prevent invalid data from entering the table.
19. What is SQL injection?
Answer: SQL injection is a code injection technique used to attack data-driven
applications by inserting malicious SQL statements into the execution field.
20. What is a cursor in SQL?
Answer: A cursor is a database object used to retrieve data from a result set one
row at a time.

Intermediate to Advanced SQL Questions:


21. Explain the concept of self-join.
Answer: A self-join is a regular join, but the table joins with itself.
22. What is a composite key?
Answer: A composite key is a primary key composed of two or more columns used
together to identify a unique record.
23. What is a clustered index?
Answer: A clustered index sorts and stores the data rows of the table or view based
on their key values.

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


24. What is a non-clustered index?
Answer: A non-clustered index stores the data somewhere else in the table and
maintains a logical order of the key values.
25. What are aggregate functions in SQL?
Answer: Aggregate functions perform a calculation on a set of values and return a
single value, e.g., COUNT, SUM, AVG, MAX, MIN.
26. What is a "HAVING" clause in SQL?
Answer: HAVING is used to filter records that work on summarized GROUP BY
results.
27. What is a "UNIQUE" constraint?
Answer: A UNIQUE constraint ensures that all values in a column are different.
28. Can the primary key be NULL?
Answer: No, a primary key cannot be NULL. It must contain a unique value for
each row of data.
29. What is data integrity?
Answer: Data integrity refers to the accuracy and consistency of data in a database.
30. Explain the difference between CHAR and VARCHAR data types.
Answer: CHAR is a fixed-length character type, whereas VARCHAR is a variable-
length character type.
31. What is a "WITH" clause or Common Table Expression (CTE)?
Answer: A CTE provides a way to write auxiliary statements for use in a larger
query.
32. What is a pivot table in SQL?
Answer: A pivot table is used to transform or reshape data, which turns unique
values from one column into multiple columns in the output.
33. What is SQL Profiler?

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


Answer: SQL Profiler is a tool that allows system administrators to monitor events
in the SQL Server.

34. What is a deadlock in SQL?


Answer: A deadlock is a situation where two or more transactions are waiting for
each other to give up locks.
35. What are triggers in SQL?
Answer: Triggers are stored procedures in a database that automatically execute
when certain conditions are met.
36. What is a correlated subquery?
Answer: A correlated subquery is a subquery that uses values from the outer query.
37. Explain the use of the SET NOCOUNT ON statement.
Answer: SET NOCOUNT ON prevents the message that shows the count of
affected rows from being returned as part of the results.
38. What is table partitioning?
Answer: Table partitioning is the process of dividing a large table into smaller,
more manageable pieces while maintaining the overall structure.
39. What are SQL Server Reporting Services (SSRS)?
Answer: SSRS is a reporting generation tool that allows creating reports from SQL
Server and other data sources.
40. What is an alias in SQL?
Answer: An alias is a temporary name given to a table or column for a particular
SQL query.

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


Advanced SQL Questions:

41. Explain the difference between INNER JOIN and OUTER JOIN.
Answer: INNER JOIN returns rows when there is at least one match in both tables.
OUTER JOIN returns all rows from one table and matched rows from the other.
42. What is a full-text search in SQL?
Answer: Full-text search in SQL is a feature for performing complex queries
against character-based data.
43. Explain the use of the EXCEPT clause.
Answer: EXCEPT returns all rows from the first dataset that do not exist in the
second dataset.
44. What is a window function in SQL?
Answer: Window functions perform a calculation across a set of table rows that are
somehow related to the current row.
45. What does a cross-apply in SQL?
Answer: CROSS APPLY is used to join a table to a table-valued function.
46. What is SQL injection and how can it be prevented?
Answer: SQL injection is a code injection technique where attackers can execute
malicious SQL. It can be prevented by using parameterized queries.
47. What is the difference between a function and a stored procedure?
Answer: A function must return a value and cannot modify the data received as
parameters, while a stored procedure doesn't have to return a value and can modify
data.
48. What is a temporary table in SQL?
Answer: Temporary tables are used to store temporary data. They are created in the
database for the duration of a session.
49. What is the use of the COALESCE function?
Answer: COALESCE returns the first non-null value in a list.

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


50. What is a recursive query in SQL?
Answer: A recursive query refers to itself in its definition.
51. What are indexed views?
Answer: Indexed views are views that have been materialized. This means they
have been computed and stored in the database.
52. What is a covering index?
Answer: A covering index is an index that contains all, and possibly more, columns
needed for a query to be processed.
53. What is the difference between a lock, a block, and a deadlock in SQL?
Answer: A lock is a mechanism to control concurrent access, a block is a situation
where one process is waiting for another to release a lock, and a deadlock is a
situation where two or more processes are unable to proceed because each is
waiting for the other to release a lock.
54. What is database replication?
Answer: Database replication is the process of copying data from one database to
another to ensure consistency.
55. What is the difference between RANK(), DENSE_RANK(), and
ROW_NUMBER()?
Answer: RANK() assigns a unique rank to each distinct row, with gaps in the
ranking for tied values. DENSE_RANK() also assigns a unique rank, but without
gaps. ROW_NUMBER() assigns a unique number to each row starting from 1.
56. What are the uses of the CASE statement in SQL?
Answer: CASE statements are used to provide if-then-else logic to SQL queries.
57. What is a materialized view?
Answer: A materialized view is a database object that contains the results of a
query and can be updated as needed.
58. What is a lateral join?

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart


Answer: A lateral join allows a subquery in the FROM clause to refer to columns
of preceding tables.
59. What are the best practices for SQL query optimization?
Answer: Best practices include using proper indexing, avoiding unnecessary
columns in SELECT statements, and avoiding complex joins when possible.
60. What is a sequence in SQL?
Answer: A sequence is a database object that generates a sequence of numbers
according to a specified specification.

Thank you!

www.aiquest.org | Prepared by KM Rashedul Alam | Study Mart

You might also like