SQL Interview Questions: One-Stop Resource
SQL Interview Questions: One-Stop Resource
Questions article, I will introduce you to the most frequently asked questions
on SQL (Structured Query Language). This blog is the perfect guide for you to
learn all the concepts related to SQL, Oracle, MS SQL Server, and MySQL
database.
Our SQL Interview Questions blog is the one-stop resource from where you can
boost your interview preparation. It has a set of top 65 questions which an
interviewer plans to ask during an interview process. It starts with the basic
SQL interview questions and later continues to advanced questions based on
your discussions and answers. These SQL Interview questions will help you
with different expertise levels to reap the maximum benefit from this article.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 2/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Q3. What do you mean by DBMS? What are its different types?
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 3/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
A DBMS allows a user to interact with the database. The data stored in the
database can be modified, retrieved and deleted and can be of any type like
strings, numbers, images, etc.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 4/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Table: StudentInformation
Field: Stu Id, Stu Name, Stu Marks
Inner Join
Right Join
Left Join
Full Join
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 5/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 6/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
NOT NULL
CHECK
DEFAULT
UNIQUE
PRIMARY KEY
FOREIGN KEY
The foreign key in the child table references the primary key in the
parent table.
The foreign key constraint prevents actions that would destroy links
between the child and parent tables.
Q13. What is the difference between clustered and non clustered index in
SQL?
The differences between the clustered and non clustered index in SQL are :
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 8/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
1. The clustered index is used for easy retrieval of data from the database
and its faster whereas reading from a non clustered index is relatively
slower.
2. Clustered index alters the way records are stored in a database as it sorts
out rows by the column which is set to be clustered index whereas in a
non clustered index, it does not alter the way it was stored but it creates a
separate object within a table which points back to the original table rows
after searching.
3. One table can only have one clustered index whereas it can have many
non clustered index.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 9/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Inner join: Inner Join in MySQL is the most common type of join. It is
used to return all the rows from multiple tables where the join condition
is satisfied.
Left Join: Left Join in MySQL is used to return all the rows from the left
table but only the matching rows from the right table where the join
condition is fulfilled.
Right Join: Right Join in MySQL is used to return all the rows from the
right table but only the matching rows from the left table where the join
condition is fulfilled.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 10/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Full Join: Full join returns all the records when there is a match in any of
the tables. Therefore, it returns all the rows from the left-hand side table
and all the rows from the right-hand side table.
same table. There can also be relationships between separate tables (for
example, customer to accounts).
Unique Index:
This index does not allow the field to have duplicate values if the column is
unique indexed. If a primary key is defined, a unique index can be applied
automatically.
Clustered Index:
This index reorders the physical order of the table and searches based on the
basis of key values. Each table can only have one clustered index.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 12/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Non-Clustered Index:
Non-Clustered Index does not alter the physical order of the table and
maintains a logical order of the data. Each table can have many nonclustered
indexes.
Third Normal Form (3NF) — Dependent solely on the primary key and no
other non-key (supporting) column value.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 14/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Consistency: Consistency ensures that the data must meet all the
validation rules. In simple words, you can say that your transaction never
leaves the database without completing its state.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 15/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
1. Arithmetic Operators
2. Logical Operators
3. Comparison Operators
Q26. Are NULL values the same as that of zero or a blank space?
A NULL value is not at all same as that of zero or a blank space. The NULL
value represents a value which is unavailable, unknown, assigned or not
applicable whereas zero is a number and blank space is a character.
Q27. What is the difference between cross join and natural join?
The cross join produces the cross product or Cartesian product of two tables
whereas the natural join is based on all the columns having the same name
and data types in both the tables.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 16/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
UPDATE or any other query. A subquery can also use any comparison
operators such as >,< or =.
Correlated subquery: These are queries which select the data from a
table referenced in the outer query. It is not considered as an
independent query as it refers to another table and refers the column in a
table.
Q31. Write a SQL query to find the names of employees that begin with ‘A’?
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 17/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
To display the name of the employees that begin with ‘A’, type in the below
command:
Q32. Write a SQL query to get the third-highest salary of an employee from
employee_table?
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 18/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Relation or links are between entities that have something to do with each
other. Relationships are defined as the connection between the tables in a
database. There are various relationships, namely:
Self-Referencing Relationship.
Q35. How can you insert NULL values in a column while inserting the data?
NULL values can be inserted in the following ways:
Q36. What is the main difference between ‘BETWEEN’ and ‘IN’ condition
operators?
BETWEEN operator is used to display rows based on a range of values in a
row whereas the IN condition operator is used to check for values contained
in a specific set of values.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 19/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Example of BETWEEN:
Example of IN:
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 21/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Using EXEC.
Using sp_executesql.
column-level constraint
table-level constraint
Q44. How can you fetch common records from two tables?
You can fetch common records from two tables using INTERSECT. For
example:
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 22/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
LOWER('string')
UPPER('string'
INITCAP: This function returns the string with the first letter in
uppercase and the rest of the letters in lowercase. Syntax:
INITCAP(‘string’)
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 23/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
For example-
In the above example, emp refers to alias name for employee table and dept
refers to alias name for department table.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 24/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Scalar functions return a single value based on the input value. For example
— UCASE(), NOW() are calculated with respect to the string.
Q50. Name the operator which is used in the query for pattern matching?
LIKE operator is used for pattern matching, and it can be used as -.
Using this command, it will print unique student id from the table Student.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 26/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 27/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
stored procedure and execute them whenever and wherever required which
saves time and avoid writing code again and again.
Disadvantages:
Scalar Functions
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 28/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
Scalar returns the unit, variant defined the return clause. Other two types of
defined functions return table.
Case Sensitivity
Kana Sensitivity
Width Sensitivity
Accent Sensitivity
These variables can be used or exist only inside the function. These variables
are not used or referred by any other function.
Global variables:
These variables are the variables which can be accessed throughout the
program. Global variables cannot be created whenever that function is
called.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 30/39
11/07/2024, 06:22 Top 65 SQL Interview Questions You Must Prepare For 2021 | by Kislay Keshari | Edureka | Medium
online processing. Warehouse data also have a subset of data called Data
Marts.
Q64. What are the different authentication modes in SQL Server? How can
it be changed?
Windows mode and Mixed Mode — SQL and Windows. You can go to the
below steps to change authentication mode in SQL Server:
Click Start> Programs> Microsoft SQL Server and click SQL Enterprise
Manager to run SQL Enterprise Manager from the Microsoft SQL Server
program group.
https://medium.com/edureka/sql-interview-questions-162f97f37ac2 31/39