Sql Interview Questions

Top 50 SQL Interview Questions and Answers for Experienced & Freshers (2022 Update)

SQL, which stands for Structured Query Language, is a domain-specific programming language that is used to manage data in database management systems (DBMS). Because Database Management Systems (DBMS) are used extensively in almost every software application, SQL programming skills are highly sought after and required in the market. Candidates must pass the interview, during which they will be asked a variety of SQL interview questions, in order to be considered for the position.
A curated list of SQL interview questions and answers is provided below. These questions and answers are likely to be asked during the SQL interview. Depending on their level of experience and a variety of other factors, candidates can expect to be asked SQL basic interview questions all the way up to advanced level SQL interview questions for professionals with three years of experience. It includes all of the SQL technical interview questions for freshers as well as SQL server interview questions for experienced candidates, as well as a few SQL query interview questions, which are all included in the following list.

SQL Interview Questions are available as a free PDF download.

Most Common SQL Interview Questions and Answers for Both Freshers and Experienced Professionals

1. What exactly is a database management system (DBMS)?

DBMS stands for Database Management System, and it is a software programme that manages the creation, maintenance, and use of a database. A database management system (DBMS) can be thought of as a file manager because it manages data in a database rather than saving it in file systems.

2. What exactly is a relational database management system (RDBMS)?

Relational Database Management System (RDBMS) is an abbreviation for Relational Database Management System. RDBMS store the data in a collection of tables that are linked together by common fields between the columns of the table in which the data is stored. It also includes relational operators, which allow you to manipulate the information stored in the tables.

As an illustration, consider SQL Server.

3. What exactly is SQL?

SQL is an abbreviation for Structured Query Language, and it is the language that is used to communicate with the database. This is a standard language that is used to perform tasks such as data retrieval, data updating, data insertion, and data deletion from a database, among other things.

Select is one of the most common SQL commands.

4. What is a database and how does it work?

A database is nothing more than a logically organised collection of information that allows for easy access, storage, retrieval, and management of information. This is also referred to as structured data, and it can be accessed in a variety of different ways.

For instance, school management databases and bank management databases are both examples of databases.

5. What is the difference between tables and fields?

A table is a collection of data that has been organised in a model with Columns and Rows to make sense of it. Columns are classified as vertical, whereas rows are classified as horizontal. A table has a specified number of columns, which are referred to as fields, but it can have any number of rows, which are referred to as records.


Employee is listed on the table.

Fields include: employee ID, employee name, and date of birth.

Data: 201456, David, on the 15th of November, 1960.

6. What is a primary key, and how does it work?

A primary key is a combination of fields that is used to identify a row in a database. Specifically, this is a special type of unique key that includes an implicit NOT NULL constraint. This means that the primary key values cannot be NULL in any way.

7. What exactly is a one-of-a-kind key?

A unique key constraint ensured that each record in the database could be uniquely identified. This ensures that the column or set of columns is distinct from the others.

It is possible to define an automatic unique constraint on a primary key constraint. However, this is not the case in the case of Unique Key.

It is possible to define multiple unique constraints for a single table, but only one Primary key constraint for a single table.

8. What is a foreign key, and how does it work?

A foreign key is a table that can be linked to the primary key of another table through a secondary key. It is necessary to establish a relationship between two tables by referencing the foreign key of one table with the primary key of the other table.

9. What exactly is a join?

In this case, the keyword “relationship” is used to query data from multiple tables based on the relationship between their fields. When JOINs are used, the keys play an important role.

10. What are the different types of joins and how do you explain each one?

Depending on the relationship between the tables, there are several different types of joins that can be utilised to retrieve information.

Inner Join is a term that refers to the joining of two or more parts of a circle within a circle.

When there is at least one match of rows between the two tables, the inner join returns the rows.

Right, let’s get started.

Right joins return rows that are shared by both tables as well as all rows from the right-hand side of the table. It simply returns all of the rows from the right-hand side table even when there are no matches in the left-hand side table, to put it another way.

Join on the left.The left join returns the rows that are shared between the tables as well as all of the rows in the left hand side table. It simply returns all of the rows from the Left hand side table even if there are no matches in the Right hand side table, to put it another way.

Full Participation.

When there are matching rows in any one of the tables, a full join returns the rows from that table. Thus, all of the rows from each side table, as well as all of the rows from each side table, are returned in turn.

11. What is the definition of normalisation?

In a database, normalisation refers to the process of reducing redundancy and dependency by organising fields and tables in a logical manner. Normalization is primarily concerned with the addition, deletion, or modification of fields that can be contained within a single table.

12. What is Denormalization and how does it work?

DeNormalization is a technique that is used to access data from databases that have higher normal forms to databases that have lower normal forms. Also known as redundancy introduction, it is the process of including data from related tables into a table to increase its redundancy.

13. What are the various normalizations that are available?

The normal forms can be divided into five categories, each of which is described below -.

first normal form (1NF) is as follows:

This should get rid of all of the duplicate columns in the table for you. The creation of tables for related data and the identification of unique columns are both required.

The Second Normal Form (2NF) is as follows:

Meeting all of the specifications of the first normal form. Organizing the data into subsets and putting them in separate tables Relationships between tables are established by referencing primary keys in each table.

The Third Normal Form (3NF) is as follows:

This should satisfy all of the requirements of the 2NF. Columns that are not dependent on primary key constraints are being removed from the table.

The Fourth Normal Form (4NF) is as follows:

This form should satisfy all of the requirements of the third normal form, and it should not contain any multi-valued dependencies.

14. What exactly is a point of view?

A view is a virtual table that contains only a subset of the data contained in a table that has been created. There are no virtual representations of the views, and it takes up less storage space. The data in a view can be derived from one or more tables and combined, depending on the relationship between them.

15. What is the definition of an index?

Creating an index is a performance tuning technique that allows for quicker retrieval of records from a table. An index creates a unique entry for each value, making it easier to retrieve data in the future.

16. What are the various types of indexes that are available?

Indexes are classified into three categories:

Index that is one of a kind.

Using this indexing method, if the column is unique indexed, it is impossible for the field to contain duplicate values. It is possible to apply a unique index automatically when a primary key is defined.

Clustered Index is a type of index that is arranged in groups of related items.

This type of index reorders the physical order of the table and search results based on the key values that are stored in the table. A clustered index can only be used by one table at a time.

Index that is not clustered.

Because it does not affect physical order of the table, a NonClustered Index can be used to maintain logical order of data. Nonclustered indexes are allowed for a total of 999 indexes per table.

17. What is the definition of a cursor?

A database is used to store information. A cursor is a control that allows you to navigate through the rows or records of a table. This can be thought of as a pointer to a specific row within a larger set of rows. The cursor is extremely useful for traversing through a database, such as for retrieval, addition, and removal of records.

18. What is a relationship, and what types of relationships are there?

The term “database relationship” refers to the connection that exists between the tables in a database. A variety of relationships between data bases exist, and they are as follows:

Relationship between two people.

There is a one-to-many relationship.

There is a one-to-many relationship.

Relationship with Self-Referencing.

19. What exactly is a query?

A database query is a piece of code that is written in order to retrieve information from a database. A query can be constructed in such a way that it corresponds to our expectations regarding the result set. Just a question to the Database, nothing more.

20. What exactly is a subquery?

A subquery is a query that is contained within another query, such as a query within another query. The outer query is referred to as the main query, and the inner query is referred to as the subquery. In all cases, the subquery is executed first and the results of the subquery are passed on to the main query.

21. What are the different kinds of subqueries?
There are two categories of subquery: those that are related to the main query and those that are not.

It is not possible to consider a correlated subquery to be an independent query, but it can refer to the field of a table that is listed in a FROM the list of the main query.

A non-correlated sub query can be treated as a separate query, with the results of the subquery being substituted into the main query in some cases.
22. What is a stored procedure, and how does it work?
A stored procedure is a function that is composed of numerous SQL statements that are used to access the database system. One or more SQL statements are condensed together into a stored procedure that can be called whenever and from wherever is necessary.

23. What exactly is a trigger?
It is possible to create database triggers that automatically execute in response to an event on a table or view in a database by using SQL code or scripts. The primary function of a trigger is to keep the database’s integrity intact.

As an illustration, if a new student is added to the student database, new entries should be created in the associated tables, such as the Exam, Score, and Attendance databases.

24. The distinction between the commands DELETE and TRUNCATE can be found here.
If you want to remove rows from a table, you can use the DELETE command, and the WHERE clause can be used to specify a conditional set of parameters. Following the deletion of a statement, the operations of commit and rollback are available.

TRUNCATE is a command that removes all rows from a table. The operation to truncate cannot be undone.

25. What are the distinctions between local and global variables, as well as their similarities and differences?
Local variables are variables that can be used or that already exist within the scope of a function. As a result, they are not known to the other functions, and those variables cannot be referred to or used by the other functions. When that function is invoked, variables can be created in its place.

Global variables are variables that can be used or that exist throughout the course of a program’s execution. No more than one instance of a declared variable can be utilised in a function. It is not possible to create global variables whenever that function is called.

26. What is a constraint?
A constraint can be used to establish a restriction on the data types that can be stored in the table. When constructing or updating the table statement, it is possible to provide a restriction. Here are some examples of constraints.

This is NOT NULL.
27. What is the definition of data integrity?
Data The correctness and consistency of data recorded in a database are defined by the term “integrity.” The application or database can also set integrity constraints, which can be used to impose business rules on data when it is entered into the application or database.

28. What is the meaning of Auto Increment?
A unique number can be generated when a new record is entered into a database using the auto increment keyword, which can be specified by the user. It is possible to use the AUTO INCREMENT keyword in Oracle, as well as the IDENTITY keyword in SQL SERVER.

In most cases, this keyword can be used in conjunction with a primary key.

29. The distinction between a Cluster Index and a Non-Cluster Index is explained in detail in question 29.
Using a clustered index, which alters the way that records are stored, it is possible to retrieve data from a database more quickly and easily. The database arranges rows according to the column that has been designated as a clustered index.

It is important to note that a nonclustered index does not change the way data is stored, but rather generates a completely new object within the table. Following the search, it returns the user to the original table rows.

30. What is a Datawarehouse and how does it work?
A datawarehouse is a centralised repository for data gathered from a variety of different sources of information. Those data are consolidated, converted, and made available for mining and online processing so that they can be used more effectively. Data Marts are a subset of warehouse data that contains a subset of warehouse data.

31. What is the definition of Self-Join?
The query self-join is configured to be used to compare to itself. This is used to compare values in a column with values in other columns in the same table that have the same values. It is possible to utilise ALIAS ES for the same table comparison.
32. What is the meaning of Cross-Join?
It is defined as the Cartesian product of the number of rows in the first table multiplied by the number of rows in the second table, in which case it is called a cross join. If, for example, the WHERE clause is used in a cross join, the query will behave similarly to an INNER JOIN.

33. How do you define user defined functions (UDFs)?
User defined functions are functions that have been written to make use of that logic whenever it is needed. It is not required to rewrite the same logic numerous times in different places. A function, on the other hand, can be called or run whenever the need arises.

34. What are the various sorts of user-defined functions available?
There are three different sorts of user defined functions.

Scalar functions are functions that have a single value.
Table-valued functions that are inlined.
Functions with multiple statement values.
Unit is returned by scaler, and the return clause has been defined by variation. The other two classes return a table as a result of their actions.

35. What is the definition of collation?
Collation is defined as a set of rules that determines how character data can be sorted and compared, and it is defined as follows: A comparison between A and other language characters can be made using this method, which is also dependent on the width of the characters.

When comparing these character data, the ASCII value might be used.

36. What are the various forms of collation sensitivity available?
Collation sensitivity can be classified into several categories, as follows:

Aspect Sensitivity – A and a, B and b, and C and c. Case Sensitivity.
Kana Sensitivity is the ability to recognise Japanese Kana characters.
Sensitivity to character width – single byte character versus double byte character
37. What are the benefits and drawbacks of using a stored procedure?
A stored procedure can be used as a component of modular programming, which means that it can be created once, stored, and called multiple times as needed. Instead of doing numerous searches, this allows for faster execution of the code. This helps to reduce network traffic while also improving the security of the data.

The disadvantage is that it can only be processed in the database and consumes more memory on the database server, which is not ideal.

38. What is Online Transaction Processing (OLTP) and why is it important?
When it comes to online transaction processing (OLTP), it is the management of transaction-based applications that can be used for data entry, retrieval, and processing. OLTP simplifies and streamlines the process of data administration. The purpose of OLTP systems, in contrast to OLAP systems, is to serve real-time transactions.

As an illustration, everyday bank transactions are an example.

39. What exactly is a CLAUSE?
The SQL clause is defined to limit the number of results returned by the query by supplying a condition to the query. Most of the time, this removes some rows from the entire collection of records.

As an illustration, consider the following query with the WHERE condition:

A query that contains the condition HAVING.

40. What is a recursive stored procedure, and how does it work?
The name of a stored process that keeps calling itself until it hits a certain boundary condition. Recursive functions and procedures allow programmers to reuse the same piece of code several times without having to write new code each time.