0% found this document useful (0 votes)
2 views5 pages

50 SQL Interview Question

Uploaded by

Dasugari Vishnu
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)
2 views5 pages

50 SQL Interview Question

Uploaded by

Dasugari Vishnu
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/ 5

Top 50 SQL Interview Questions and Answers

1. What is SQL?

SQL stands for Structured Query Language. It is used for managing and manipulating relational

databases.

2. What are the different types of SQL statements?

1. DDL (Data Definition Language): CREATE, ALTER, DROP

2. DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE

3. DCL (Data Control Language): GRANT, REVOKE

4. TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

5. DQL (Data Query Language): SELECT

3. What is a Primary Key?

A Primary Key is a column or a set of columns that uniquely identifies each row in a table.

4. What is the difference between WHERE and HAVING clause?

WHERE is used to filter rows before grouping. HAVING is used to filter groups after grouping.

5. What is a JOIN?

JOIN is used to retrieve data from multiple tables based on a logical relationship between the tables.

6. What are the types of JOINS?

INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, SELF JOIN, CROSS JOIN.

7. What is the difference between CHAR and VARCHAR?

CHAR is a fixed-length data type, while VARCHAR is a variable-length data type.

8. What is normalization?

Normalization is the process of organizing data to minimize redundancy and improve data integrity.

9. What is denormalization?

Denormalization is the process of combining normalized tables to improve read performance.

10. What is a subquery?

A subquery is a query nested inside another query, often used in SELECT, INSERT, UPDATE, or
DELETE statements.

11. What is a foreign key?

A foreign key is a column or group of columns in one table that refers to the primary key in another

table.

12. What is the difference between DELETE and TRUNCATE?

DELETE removes specific rows and can be rolled back. TRUNCATE removes all rows and cannot

be rolled back.

13. What is an index?

An index is used to speed up the retrieval of data from a database table.

14. What is a view?

A view is a virtual table based on the result of a SQL query.

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

UNION removes duplicate records, while UNION ALL includes all duplicates.

16. What is a constraint?

Constraints are rules enforced on data columns, like NOT NULL, UNIQUE, PRIMARY KEY,

FOREIGN KEY, CHECK.

17. What is a unique key?

A unique key ensures that all values in a column are different.

18. What is a composite key?

A composite key is a combination of two or more columns that uniquely identify a row.

19. What is the use of GROUP BY?

GROUP BY is used to arrange identical data into groups.

20. What is the use of ORDER BY?

ORDER BY is used to sort the result set in ascending or descending order.

21. What is a transaction?

A transaction is a unit of work performed against a database.

22. What are ACID properties?


ACID stands for Atomicity, Consistency, Isolation, Durability.

23. What is the difference between clustered and non-clustered index?

Clustered index sorts the table data, non-clustered index is stored separately from the table.

24. What is a stored procedure?

A stored procedure is a prepared SQL code that can be saved and reused.

25. What is a trigger?

A trigger is a SQL procedure that initiates an action in response to an event (INSERT, UPDATE,

DELETE).

26. What is a cursor?

A cursor is used to iterate through a result set row by row.

27. What is the difference between RANK() and DENSE_RANK()?

RANK() skips ranks if there are ties, DENSE_RANK() does not.

28. What is COALESCE function?

COALESCE returns the first non-null value in a list.

29. What is NULL value in SQL?

NULL represents a missing or undefined value.

30. What are scalar functions?

Functions that return a single value, e.g., UPPER(), LOWER(), NOW(), LEN().

31. What are aggregate functions?

Functions that operate on a set of values and return a single value: COUNT(), SUM(), AVG(), MIN(),

MAX().

32. What is the difference between IN and EXISTS?

IN checks if a value is in a list. EXISTS checks if a subquery returns any result.

33. What is the BETWEEN operator?

BETWEEN is used to filter values within a range.

34. What is a case statement in SQL?

CASE allows conditional logic in SQL queries.


35. What is a schema?

A schema is a collection of database objects such as tables, views, and procedures.

36. What is a data warehouse?

A data warehouse is a system used for reporting and data analysis, storing large volumes of data.

37. What is the difference between OLTP and OLAP?

OLTP is for transactional systems; OLAP is for analytical processing.

38. What is the use of aliases in SQL?

Aliases give a table or a column a temporary name.

39. What is a correlated subquery?

A subquery that uses values from the outer query.

40. What is a temporary table?

A table that exists temporarily and is deleted when the session ends.

41. What is SET vs SELECT when assigning values to variables?

SET assigns one variable at a time. SELECT can assign multiple variables at once.

42. What are common table expressions (CTEs)?

CTEs are temporary result sets used within a SELECT, INSERT, UPDATE, or DELETE statement.

43. What is the difference between ISNULL() and NULLIF()?

ISNULL() replaces NULL with a specified value. NULLIF() returns NULL if two expressions are

equal.

44. What is a surrogate key?

A surrogate key is an artificial key used to uniquely identify an entity when a natural key is not

available.

45. What are the different types of relationships in SQL?

One-to-One, One-to-Many, Many-to-Many.

46. What is referential integrity?

Ensures that a foreign key value always refers to an existing row in another table.

47. What is the use of DISTINCT keyword?


DISTINCT is used to return only distinct (different) values.

48. What is a materialized view?

A materialized view stores the result of a query physically and updates it periodically.

49. What is SQL injection?

A code injection technique that might destroy your database. Use prepared statements to prevent it.

50. How to optimize SQL queries?

Use proper indexes, avoid SELECT *, limit joins, and use WHERE clauses efficiently.

You might also like