SQL Interview Questions and Answers
SQL Interview Questions and Answers
1. What is SQL?
SQL (Structured Query Language) is used to manage and manipulate relational databases.
A Primary Key uniquely identifies each record in a table. It cannot have NULL values.
Primary Key: Uniquely identifies records, does not allow NULL values.
Unique Key: Ensures uniqueness but allows NULL values.
A Foreign Key is a field that establishes a relationship between two tables by referencing a
Primary Key in another table.
An Index improves the speed of data retrieval but may slow down INSERT, UPDATE, and
DELETE operations.
Stored Procedures are precompiled SQL statements that improve performance and security.
Triggers are automatic actions executed before or after an INSERT, UPDATE, or DELETE
operation.
Window functions perform calculations across a set of table rows related to the current row.
A Deadlock occurs when two transactions block each other while waiting for a resource.
An optimized query improves performance by using indexes, avoiding unnecessary joins, and
using efficient functions.
These questions cover fundamental and advanced SQL concepts commonly asked in
interviews.