0% found this document useful (0 votes)
3 views

sql_interview_questions

The document provides a comprehensive overview of SQL, including definitions, types of SQL statements, and key concepts such as primary keys, foreign keys, normalization, and joins. It also covers differences between SQL functions and commands, such as DELETE vs. TRUNCATE, and explains ACID properties and aggregate functions. Additionally, it includes practical SQL examples for finding duplicates and understanding ranking functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

sql_interview_questions

The document provides a comprehensive overview of SQL, including definitions, types of SQL statements, and key concepts such as primary keys, foreign keys, normalization, and joins. It also covers differences between SQL functions and commands, such as DELETE vs. TRUNCATE, and explains ACID properties and aggregate functions. Additionally, it includes practical SQL examples for finding duplicates and understanding ranking functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Interview Questions and Answers

1. 1. What is SQL?

Answer: SQL (Structured Query Language) is a standard language used to communicate


with relational databases. It is used to perform tasks such as querying data, updating
records, and managing database structures.

2. 2. What are the different types of SQL statements?

Answer: SQL statements are categorized into:


- DDL (Data Definition Language): CREATE, ALTER, DROP
- DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE
- DCL (Data Control Language): GRANT, REVOKE
- TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

3. 3. What is the difference between WHERE and HAVING clauses?

Answer: WHERE is used to filter rows before grouping, while HAVING is used to filter
groups after aggregation.

4. 4. What is a primary key?

Answer: A primary key uniquely identifies each record in a table. It must contain unique
values and cannot contain NULLs.

5. 5. What is a foreign key?

Answer: A foreign key is a column that creates a relationship between two tables. It refers
to the primary key in another table.

6. 6. What is normalization?

Answer: Normalization is the process of organizing data to minimize redundancy and


improve data integrity.

7. 7. Explain the different normal forms.

Answer: - 1NF: Eliminate repeating groups


- 2NF: Remove partial dependencies
- 3NF: Remove transitive dependencies
- BCNF: Every determinant is a candidate key

8. 8. What is a JOIN? Name its types.

Answer: JOIN is used to combine rows from two or more tables based on related columns.
Types include:
- INNER JOIN
- LEFT JOIN (LEFT OUTER JOIN)
- RIGHT JOIN (RIGHT OUTER JOIN)
- FULL JOIN (FULL OUTER JOIN)
- CROSS JOIN
- SELF JOIN

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

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

10. 10. What is a subquery?

Answer: A subquery is a query nested inside another SQL query. It can be used in SELECT,
FROM, or WHERE clauses.

11. 11. What is indexing?

Answer: Indexing is used to speed up the retrieval of rows by using a pointer. It is similar to
an index in a book.

12. 12. What is the difference between DELETE and TRUNCATE?

Answer: DELETE removes specific rows and logs each row deletion; TRUNCATE removes all
rows without logging individual deletions.

13. 13. What is a view?

Answer: A view is a virtual table based on the result set of a SELECT query. It simplifies
complex queries and provides data security.

14. 14. What is a stored procedure?

Answer: A stored procedure is a group of SQL statements that perform a task, stored in the
database and can be executed repeatedly.

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

Answer: A clustered index determines the physical order of data in a table; only one per
table. A non-clustered index creates a separate structure to point to data locations and can
be multiple per table.

16. 16. What is a constraint?

Answer: Constraints are rules enforced on data in tables, such as NOT NULL, UNIQUE,
PRIMARY KEY, FOREIGN KEY, CHECK, and DEFAULT.

17. 17. What is ACID in SQL?


Answer: ACID stands for Atomicity, Consistency, Isolation, Durability. These properties
ensure reliable processing of database transactions.

18. 18. What are aggregate functions?

Answer: Functions that perform a calculation on a set of values and return a single value.
Examples: COUNT(), SUM(), AVG(), MAX(), MIN().

19. 19. How do you find duplicate records in a table?

Answer: ```sql
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
```

20. 20. What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?

Answer: - RANK(): Leaves gaps in ranking when there are ties.


- DENSE_RANK(): No gaps in ranking for ties.
- ROW_NUMBER(): Assigns unique numbers regardless of ties.

You might also like