Thanks to visit codestin.com
Credit goes to www.scribd.com

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

30 SQL Interview Questions and Answers

The document contains 30 SQL interview questions and their corresponding answers, covering fundamental concepts such as SQL, databases, primary and foreign keys, SQL commands, and data types. It also explains advanced topics like normalization, joins, indexes, stored procedures, and transaction properties. This resource serves as a comprehensive guide for individuals preparing for SQL-related interviews.

Uploaded by

Mohd Haider
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)
27 views5 pages

30 SQL Interview Questions and Answers

The document contains 30 SQL interview questions and their corresponding answers, covering fundamental concepts such as SQL, databases, primary and foreign keys, SQL commands, and data types. It also explains advanced topics like normalization, joins, indexes, stored procedures, and transaction properties. This resource serves as a comprehensive guide for individuals preparing for SQL-related interviews.

Uploaded by

Mohd Haider
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

30 SQL interview questions and answers

1. What is SQL?

Answer: SOL 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 rolationship between the tablos 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 Ito quickly locate and access the raw 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 SOL 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 (or “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.

26. What is the purpose of the SQL GROUP BY and COUNT() functions?

Answer: The GROUP BY clause is used to group rows based on specified columns, and
COUNT() is an aggregate function that counts the number of rows in each group.
27. Explain the difference between a DELETE and TRUNCATE statement.

Answer: DELETE is used to remove rows from a table based on a condition, while
TRUNCATE removes all rows from a table and is faster but cannot be rolled back.

28. What is a cross join?

Answer: A cross join, or Cartesian join, returns the Cartesian product of the sets of rows
from the joined tables. It results in every combination of rows from both tables.

29. What is the purpose of the SQL BETWEEN operator?

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

30. Explain the purpose of the SQL UPDATE statement.

Answer: The UPDATE statement is used to modify the existing records in a table. It allows
you to update specific columns with now values.

You might also like