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

Most Asked SQL Interview Q&a

It

Uploaded by

wayfareraromal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Most Asked SQL Interview Q&a

It

Uploaded by

wayfareraromal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MOST ASKED SQL INTERVIEW Q&A

1. What is SQL?

Answer: SQL stands for Structured Query Language, and it is a domain-specific language used
for managing and manipulating relational databases.

2. What is a database?

Answer: A database is a structured collection of data that is organized and stored for efficient
retrieval and manipulation.

3. Explain the difference between SQL and MySQL.

Answer: SQL is a language used to manage and manipulate relational databases, while MySQL
is an open-source relational database management system (RDBMS) that uses SQL as its
query language.

4. What is a primary key?

Answer: A primary key is a unique identifier for a record in a database table. It ensures that
each record can be uniquely identified and helps maintain data integrity.

5. What is a foreign key?

Answer: A foreign key is a field in a database table that is used to establish a link between the
data in two tables. It creates a relationship between the tables by referencing the primary key
of another table.

6. Explain the types of SQL commands.

Answer: SQL commands can be broadly categorized into Data Definition Language (DDL),
Data Manipulation Language (DML), Data Query Language (DQL), and Data Control Language
(DCL).

7. What is the difference between CHAR and VARCHAR data types?

Answer: CHAR is a fixed-length character data type, while VARCHAR is a variable-length


character data type. VARCHAR is more flexible as it only stores the characters entered,
whereas CHAR pads the remaining spaces with blanks.
8. What is normalization?

Answer: Normalization is the process of organizing data in a database to reduce redundancy


and improve data integrity. It involves dividing large tables into smaller tables and defining
relationships between them.

9. Explain the difference between INNER JOIN and LEFT JOIN.

Answer: INNER JOIN returns only the rows where there is a match in both tables, while LEFT
JOIN returns all rows from the left table and the matched rows from the right table. If there is
no match, NULL values are returned for columns from the right table.

10. What is the purpose of the GROUP BY clause?

Answer: The GROUP BY clause is used to group rows that have the same values in specified
columns into summary rows, like finding the total or average for each group.

11. Explain the difference between UNION and UNION ALL.

Answer: UNION combines the result sets of two queries, eliminating duplicate rows, while
UNION ALL combines the result sets including duplicates.

12. What is an index, and why is it used?

Answer: An index is a data structure that improves the speed of data retrieval operations on a
database table. It is used to quickly locate and access the ro in a table based on the values in
one or more columns.

13. What is a stored procedure?

Answer: A stored procedure is a precompiled collection of one or more SQL statements that
can be executed as a single unit. It is stored in the database and can be called by name.

14. Explain the ACID properties of a transaction.

Answer: ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of
properties that guarantee that database transactions are processed reliably.

15. What is the purpose of the HAVING clause?

Answer: The HAVING clause is used in combination with the GROUP BY clause to filter the
results of a group based on a specified condition.

16. What is a view in SQL?

Answer: A view is a virtual table derived from one or more tables. It does not store the data
itself but provides a way to represent the result of a stored query.
17. Explain the difference between a clustered and a non- clustered index.

Answer: A clustered index determines the physical order of data in a table, whereas a non-
clustered index does not affect the physical order and creates a separate structure for faster
data retrieval.

18. What is the purpose of the SQL ORDER BY clause?

Answer: The ORDER BY clause is used to sort the result set of a query in ascending or
descending order based on one or more columns.

19. What is a trigger?

Answer: A trigger is a set of instructions that are automatically executed (o "triggered") in


response to certain events on a particular table or view in a database.

20. Explain the difference between a candidate key, primary key, and a super key.

Answer: A super key is any set of columns that uniquely identifies a row, a candidate key is a
minimal super key, and the primary key is the chosen candidate key for a table.

21. What is the purpose of the SQL LIKE statement?

Answer: The LIKE statement is used in a WHERE clause to search for a specified pattern in a
column.

22. What is the difference between a view and a table?

Answer: A table is a physical storage structure that stores data, while a view is a virtual table
derived from one or more tables, presenting a way to represent the result of a stored query.

23. What is a self-join?

Answer: A self-join is a regular join, but the table is joined with itself. It is often used when a
table has a foreign key that references its own primary key.

24. Explain the purpose of the SQL IN operator.

Answer: The IN operator is used in a WHERE clause to filter the result set based on a specified
list of values.

25. What is a subquery?

Answer: A subquery is a query nested inside another query. It can be used to retrieve data
that will be used in the main query as a condition to further restrict the data to be retrieved.

You might also like