SQL İnterview Questions
SQL İnterview Questions
SQL İnterview Questions
SQL vs MySQL
MySQL
SQL
which is used for accessing and managing Database Management System) such as
data. It helps you to insert, update, delete and retrieve data from the database.
Q3. What do you mean by DBMS? What are its different types?
with the user, applications, and the database itself to capture and analyze data. A
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.
features that allow IT professionals and others to develop, edit, administer, and
systems use Structured Query Language (SQL) to access the database, which is
The RDBMS is the most widely used database system in businesses all over the
world. It offers a stable means of storing and retrieving massive amounts of data.
Databases, in general, hold collections of data that may be accessed and used in other
applications. The development, administration, and use of database platforms are all
management system (DBMS) that stores data in a row-based table structure that links
related data components. An RDBMS contains functions that ensure the data’s
security, accuracy, integrity, and consistency. This is not the same as the file storage
The following are some further distinctions between database management systems
A DBMS can only handle one user at a time, whereas an RDBMS can handle
numerous users.
Amount of information
RDBMSes can handle any quantity of data, from tiny to enormous, whereas DBMSes
with headers that serve as column names and rows that hold the associated values.
The atomicity, consistency, isolation, and durability (ACID) concept is not used by
DBMSs for data storage. RDBMSes, on the other hand, use the ACID model to
A DBMS will not provide complete support for distributed databases, whereas an
RDBMS will.
A DBMS focuses on keeping databases that are present within the computer network
and system hard discs, whereas an RDBMS helps manage relationships between its
A self-join is a type of join that can be used to connect two tables. As a result, it is a
unary relationship. Each row of the table is attached to itself and all other rows of the
A SELECT command gets zero or more rows from one or more database tables or
views. The most frequent data manipulation language (DML) command is SELECT
in most applications. SELECT queries define a result set, but not how to calculate it,
Q7. What are some common clauses used with SELECT query in SQL?
The following are some frequent SQL clauses used in conjunction with a SELECT
query:
WHERE clause: In SQL, the WHERE clause is used to filter records that are required
ORDER BY clause: The ORDER BY clause in SQL is used to sort data in ascending
GROUP BY clause: GROUP BY clause in SQL is used to group entries with identical
data and may be used with aggregation methods to obtain summarised database
results.
HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause. It is different from WHERE, since the WHERE clause cannot filter aggregated
records.
The UNION operator is used to combine the results of two tables while also
The MINUS operator is used to return rows from the first query but not from the
second query.
The INTERSECT operator is used to combine the results of both queries into a single
row.
Before running either of the above SQL statements, certain requirements must be
satisfied –
Within the clause, each SELECT query must have the same amount of columns.
To start the result set, move the cursor over it. Before obtaining rows from the result
To retrieve and go to the next row in the result set, use the FETCH command.
Finally, use the DEALLOCATE command to remove the cursor definition and free
One-to-One – This is a connection between two tables in which each record in one
massive amounts of database transactions in real time, usually via the internet. A
queried.
OLTP stands for online transaction processing, whereas OLAP stands for online
Q13. How to create empty tables with the same structure as another table?
Using the INTO operator to fetch the records of one table into a new table while
setting a WHERE clause to false for all entries, it is possible to create empty tables
with the same structure. As a result, SQL creates a new table with a duplicate
structure to accept the fetched entries, but nothing is stored into the new table since
Local variables:
These variables can be used or exist only inside the function. These variables are not
Global variables:
These variables are the variables which can be accessed throughout the program.
PostgreSQL under the name Postgres. It was created to aid developers in the
constantly backed it. PostgreSQL has achieved significant appeal among developers
It’s a very reliable database management system, with more than two decades of
community work to thank for its high levels of resiliency, integrity, and accuracy.
SQL Comments are used to clarify portions of SQL statements and to prevent SQL
You may use the NVL function to replace null values with a default value. The
function returns the value of the second parameter if the first parameter is null. If the
This function is used in Oracle, not in SQL and MySQL. Instead of NVL() function,
SQL.
Change, extract, and edit the character string using character manipulation routines.
The function will do its action on the input strings and return the result when one or
values together. The second string is always appended to the end of the first string.
B) SUBSTR: This function returns a segment of a string from a given start point to a
given endpoint.
C) LENGTH: This function returns the length of the string in numerical form,
word in a string.
E) LPAD: For right-justified values, it returns the padding of the left-side character
value.
F) RPAD: For a left-justified value, it returns the padding of the right-side character
value.
G) TRIM: This function removes all defined characters from the beginning, end, or
Q19. Write the SQL query to get the third maximum salary of an employee from a
Employee table
employee_name salary
A 24000
C 34000
D 55000
E 75000
F 21000
G 40000
H 50000
SELECT * FROM(
WHERE r=&n;
ordered partition. If both rows have the same rank, the next number in the ranking
will be the previous rank plus a number of duplicates. If we have three records at
The DENSE_RANK() function assigns a distinct rank to each row within a partition
based on the provided column value, with no gaps. It always indicates a ranking in
order of precedence. This function will assign the same rank to the two rows if they
have the same rank, with the next rank being the next consecutive number. If we
have three records at rank 4, for example, the next level indicated is 5.
relationships. The most basic form of data storage is the table. An example of an
collection of connected data. The Employee table, for example, has four records.
A table is made up of numerous records (rows), each of which can be split down into
smaller units called Fields(columns). ID, Name, Department, and Salary are the four
two records. The UNIQUE constraint guarantees that every value in a column is
unique.
A self-join is a type of join that can be used to connect two tables. As a result, it is a
unary relationship. Each row of the table is attached to itself and all other rows of the
A SELECT command gets zero or more rows from one or more database tables or
views. The most frequent data manipulation language (DML) command is SELECT
in most applications. SELECT queries define a result set, but not how to calculate it,
Q25. What are some common clauses used with SELECT query in SQL?
The following are some frequent SQL clauses used in conjunction with a SELECT
query:
WHERE clause: In SQL, the WHERE clause is used to filter records that are required
ORDER BY clause: The ORDER BY clause in SQL is used to sort data in ascending
(ASC) or descending (DESC) order depending on specified field(s) (DESC).
GROUP BY clause: GROUP BY clause in SQL is used to group entries with identical
data and may be used with aggregation methods to obtain summarised database
results.
HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause. It is different from WHERE, since the WHERE clause cannot filter aggregated
records.
The UNION operator is used to combine the results of two tables while also
The MINUS operator is used to return rows from the first query but not from the
second query.
The INTERSECT operator is used to combine the results of both queries into a single
row.
Before running either of the above SQL statements, certain requirements must be
satisfied –
Within the clause, each SELECT query must have the same amount of columns.
To start the result set, move the cursor over it. Before obtaining rows from the result
To retrieve and go to the next row in the result set, use the FETCH command.
Finally, use the DEALLOCATE command to remove the cursor definition and free
One-to-One – This is a connection between two tables in which each record in one
SQL is a database query language that allows you to edit, remove, and request data
from databases. The following statements are a few examples of SQL statements:
SELECT
INSERT
UPDATE
DELETE
CREATE DATABASE
ALTER DATABASE
SQL skills aid data analysts in the creation, maintenance, and retrieval of data from
relational databases, which divide data into columns and rows. It also enables users
The most fundamental abilities that a SQL expert should possess are:
1. Database Management
2. Structuring a Database
3. Creating SQL clauses and statements
4. SQL System SKills like MYSQL, PostgreSQL
5. PHP expertise is useful.
6. Analyze SQL data
7. Using WAMP with SQL to create a database
8. OLAP Skills
Q31. What is schema in SQL Server?
specifies the relationships among the database’s numerous entities. It refers to the
several kinds of constraints that may be applied to a database. It also describes the
Schemas come in a variety of shapes and sizes. Star schema and Snowflake schema
are two of the most popular. The entities in a star schema are represented in a star
Temporary tables are created in TempDB and are erased automatically after the last
connection is closed. We may use Temporary Tables to store and process interim
results. When we need to store temporary data, temporary tables come in handy.
Step 1: Click on SSMS, which will take you to the SQL Server Management Studio
page.
Step 2: Moreover, click on the SQL Server Management Studio link and tap on Save
File.
Step 3: Save this file to your local drive and go to the folder.
Step 4: The setup window will appear, and here you can choose the location where
Step 7: Furthermore, go back to your Start Menu and search for SQL server
management studio.
Step 8: Furthermore, double-click on it, and the login page will appear once it shows
up.
Step 9: You should be able to see your server name. However, if that’s not visible,
After that, the SQL server will connect, and Windows 11 will run good.
The CASE statement is used to construct logic in which one column’s value is
At least one set of WHEN and THEN commands makes up the SQL Server CASE
WHEN condition returns TRUE, the THEN sentence explains what to do.
When none of the WHEN conditions return true, the ELSE statement is executed. The
1 CASE
5 ELSE result
6 END;
In summary, the following are the five major distinctions between SQL and NoSQL:
SQL databases have a specified schema and employ structured query language. For
NOW() returns a constant time that indicates the time at which the statement began
to execute. (Within a stored function or trigger, NOW() returns the time at which the
The simple difference between NOW() and CURRENT_DATE() is that NOW() will
fetch the current date and time both in format ‘YYYY-MM_DD HH:MM:SS’ while
BLOB stands for Binary Huge Objects and can be used to store binary data, whereas
TEXT may be used to store a large number of strings. BLOB may be used to store
BLOB values function similarly to byte strings, and they lack a character set. As a
result, bytes’ numeric values are completely dependent on comparison and sorting.
If the SQL table has duplicate rows, the duplicate rows must be removed.
ID Name Age
1 A 21
2 B 23
2 B 23
4 D 22
5 E 25
6 G 26
5 E 25
The following SQL query removes the duplicate ids from the table:
SELECT
ID, COUNT(ID)
FROM table
GROUP BY ID
HAVING
A stored procedure is a piece of prepared SQL code that you can save and reuse
So, if you have a SQL query that you create frequently, save it as a stored procedure
You may also supply parameters to a stored procedure so that it can act based on the
AS
sql_statement
GO;
EXEC procedure_name;
Black Box Testing is a software testing approach that involves testing the functions of
details, or internal routes. Black Box Testing is a type of software testing that focuses
on the input and output of software applications and is totally driven by software
Prior to the introduction of MySQL 5.5 in December 2009, MyISAM was the default
storage engine for MySQL relational database management system versions. It’s
based on the older ISAM code, but it comes with a lot of extra features. Each
MyISAM table is split into three files on disc (if it is not partitioned). The file names
start with the table name and end with an extension that indicates the file type. The
table definition is stored in a.frm file, however this file is not part of the MyISAM
engine; instead, it is part of the server. The data file’s suffix is.MYD (MYData). The
index file’s extension is.MYI (MYIndex). If you lose your index file, you may always
The most typical interview question is to find the Nth highest pay in a table. This
Employee table
employee_name salary
A 24000
C 34000
D 55000
E 75000
F 21000
G 40000
H 50000
SELECT * FROM(
Table: StudentInformation
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them. It is used to merge two tables or retrieve data from there.
Inner join: Inner Join in SQL 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 SQL 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 SQL 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.
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
Q45. What is the difference between CHAR and VARCHAR2 datatype in SQL?
Both Char and Varchar2 are used for characters datatype but varchar2 is used for
character strings of variable length whereas Char is used for strings of fixed length.
For example, char(10) can only store 10 characters and will not be able to store a
string of any other length whereas varchar2(10) can store any length i.e 6,8,2 in this
variable.
of columns) or a set of columns that uniquely identifies each row in the table.
Constraints in SQL are used to specify the limit on the data type of the table. It can be
specified while creating or altering the table statement. The sample of constraints are:
NOT NULL
CHECK
DEFAULT
UNIQUE
PRIMARY KEY
FOREIGN KEY
DELETE vs TRUNCATE
TRUNCATE
DELETE
Delete command is used to delete a row in Truncate is used to delete all the rows
a table. from a table.
Apart from this SQL Interview Questions blog, if you want to get trained from
professionals on this technology, you can opt for structured training from edureka!
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
Data Integrity defines the accuracy as well as the consistency of the data stored in a
database. It also defines integrity constraints to enforce business rules on the data
Q52. What is the difference between clustered and non-clustered index in SQL?
The differences between the clustered and non clustered index in SQL are :
1. Clustered index is used for easy retrieval of data from the database and its
faster whereas reading from 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.
In SQL, there is a built-in function called GetDate() which helps to return the current
timestamp/date.
The phase that identifies a plan for evaluation query which has the least estimated
adds the redundant data into a table by incorporating database queries that combine
Entities: A person, place, or thing in the real world about which data can be stored
in a database. Tables store data that represents one type of entity. For example – A
bank database has a customer table to store customer information. The customer
table stores this information as a set of attributes (columns within the table) for each
customer.
each other. For example – The customer name is related to the customer account
number and contact information, which might be in the same table. There can also be
records from the table. An index creates an entry for each value and hence it will be
Unique Index:
This index does not allow the field to have duplicate values if the column is unique
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.
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.
Apart from this SQL Interview Questions Blog, if you want to get trained from
professionals on this technology, you can opt for structured training from edureka!
Q60. What is the difference between DROP and TRUNCATE commands?
DROP command removes a table and it cannot be rolled back from the database
whereas TRUNCATE command removes all the rows from the table.
There are many successive levels of normalization. These are called normal
forms. Each consecutive normal form depends on the previous one.The first three
Normal Forms are used in database tables to remove or decrease duplication. The
normal form. The first normal form is broken when a relation has a composite or
multi-valued property.
A relation is in second normal form if it meets the first normal form’s requirements
and does not contain any partial dependencies. In 2NF, a relation has no partial
suitable subset of any table candidate key. Often, the problem may be solved by
If a relation meets the requirements for the second normal form and there is no
massive amounts of database transactions in real time, usually via the internet. A
queried.
OLTP stands for online transaction processing, whereas OLAP stands for online
Using the INTO operator to fetch the records of one table into a new table while
setting a WHERE clause to false for all entries, it is possible to create empty tables
with the same structure. As a result, SQL creates a new table with a duplicate
structure to accept the fetched entries, but nothing is stored into the new table since
PostgreSQL under the name Postgres. It was created to aid developers in the
constantly backed it. PostgreSQL has achieved significant appeal among developers
It’s a very reliable database management system, with more than two decades of
community work to thank for its high levels of resiliency, integrity, and accuracy.
SQL Comments are used to clarify portions of SQL statements and to prevent SQL
The RANK() function in the result set defines the rank of each row within your
ordered partition. If both rows have the same rank, the next number in the ranking
will be the previous rank plus a number of duplicates. If we have three records at
rtification Course
The DENSE_RANK() function assigns a distinct rank to each row within a partition
based on the provided column value, with no gaps. It always indicates a ranking in
order of precedence. This function will assign the same rank to the two rows if they
have the same rank, with the next rank being the next consecutive number. If we
have three records at rank 4, for example, the next level indicated is 5.
SQL injection is a sort of flaw in website and web app code that allows attackers to
take control of back-end processes and access, retrieve, and delete sensitive data
stored in databases. In this approach, malicious SQL statements are entered into a
database entry field, and the database becomes exposed to an attacker once they are
executed. By utilising data-driven apps, this strategy is widely utilised to get access
Getting access to secret data in order to change a SQL query to acquire the
desired results.
UNION attacks are designed to steal data from several database tables.
Examine the database to get information about the database’s version and
structure
SQL aggregate functions provide information about a database’s data. AVG, for
SQL provides seven (7) aggregate functions, which are given below:
COUNT(): returns the number of table rows, including rows with null values.
Q69. What is the default ordering of data using the ORDER BY clause? How could
it be changed?
The ORDER BY clause in MySQL can be used without the ASC or DESC modifiers.
The sort order is preset to ASC or ascending order when this attribute is absent from
The SQL DISTINCT keyword is combined with the SELECT query to remove all
duplicate records and return only unique records. There may be times when a table
Q71. What are the syntax and use of the COALESCE function?
From a succession of expressions, the COALESCE function returns the first non-
NULL value. The expressions are evaluated in the order that they are supplied, and
the function’s result is the first non-null value. Only if all of the inputs are null does
if one part of any transaction fails, the entire transaction fails and the
Consistency: Consistency ensures that the data must meet all the validation
rules. In simple words, you can say that your transaction never leaves the
occur whatever may come in between such as power loss, crash or any sort of
error.
Trigger in SQL is are a special type of stored procedures that are defined to execute
code when an insert, update or any other query is executed against a specific table.
1. Arithmetic Operators
2. Logical Operators
3. Comparison Operators
Apart from this SQL Interview Questions blog, if you want to get trained from
professionals on this technology, you can opt for structured training from edureka!
A NULL value is not at all same as that of zero or a blank space. NULL value
Q76. 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
A subquery is a query inside another query where a query is defined to retrieve data
or information back from the database. In a subquery, the outer query is called as the
main query whereas the inner query is called subquery. Subqueries are always
executed first and the result of the subquery is passed on to the main query. It can be
nested inside a SELECT, UPDATE or any other query. A subquery can also use any
Correlated subquery: These are queries which select the data from a table referenced
To count the number of records in a table in SQL, you can use the below commands:
Apart from this SQL Interview Questions Blog, if you want to get trained from
professionals on this technology, you can opt for structured training from edureka!
Q80. Write a SQL query to find the names of employees that begin with ‘A’?
To display name of the employees that begin with ‘A’, type in the below command:
employee_table?
2 FROM(
4 FROM employee_table
Group functions work on the set of rows and return one result per group. Some of
the commonly used group functions are: AVG, COUNT, MAX, MIN, SUM,
VARIANCE.
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
Self-Referencing Relationship.
Q84. How can you insert NULL values in a column while inserting the data?
Q85. What is the main difference between ‘BETWEEN’ and ‘IN’ condition
operators?
whereas the IN condition operator is used to check for values contained in a specific
set of values.
Example of BETWEEN:
SELECT * FROM Students where ROLL_NO BETWEEN 10 AND 50;
Example of IN:
This statement allows conditional update or insertion of data into a table. It performs
Recursive stored procedure refers to a stored procedure which calls by itself until it
reaches some boundary condition. This recursive function or procedure helps the
SQL clause helps to limit the result set by providing a condition to the query. A
clause helps to filter the rows from the entire set of records.
Apart from this SQL Interview Questions Blog, if you want to get trained from
professionals on this technology, you can opt for a structured training from edureka!
CLAUSE?
HAVING clause can be used only with SELECT statement. It is usually used in a
GROUP BY clause and whenever GROUP BY is not used, HAVING behaves like a
WHERE clause.
Having Clause is only used with the GROUP BY function in a query whereas
WHERE Clause is applied to each row before they are a part of the GROUP BY
function in a query.
Using EXEC.
Using sp_executesql.
Constraints are the representation of a column to enforce data entity and consistency.
Q93. How can you fetch common records from two tables?
You can fetch common records from two tables using INTERSECT. For example:
Exam
LOWER(‘string’)
UPPER(‘string’)
INITCAP: This function returns the string with the first letter in uppercase
INITCAP(‘string’)
Apart from this SQL Interview Questions blog, if you want to get trained from
professionals on this technology, you can opt for a structured training from edureka!
Some of the available set operators are – Union, Intersect or Minus operators.
ALIAS command in SQL is the name that can be given to any table or a column. This
column.
For example-
emp.empID=dept.empID
In the above example, emp refers to alias name for employee table and dept refers to
single value. These calculations are done from the columns in a table. For example-
Scalar functions return a single value based on the input value. For example –
You can fetch alternate records i.e both odd and even row numbers. For example- To
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
Q99. Name the operator which is used in the query for pattern matching?
Apart from this SQL Interview Questions Blog, if you want to get trained from
professionals on this technology, you can opt for structured training from edureka!
You can select unique records from a table by using the DISTINCT keyword.
Using this command, it will print unique student id from the table Student.
There are a lot of ways to fetch characters from a string. For example:
SQL is a query language that allows you to issue a single query or execute a single
allows you to write a full program (loops, variables, etc.) to accomplish multiple
A view is a virtual table which consists of a subset of data contained in a table. Since
views are not present, it takes less space to store. View can have data of one or more
A view refers to a logical snapshot based on a table or another view. It is used for the
following reasons:
the database system. Several SQL statements are consolidated into a stored
procedure and execute them whenever and wherever required which saves time and
Advantages:
once, store and call for several times whenever it is required. This supports faster
execution. It also reduces network traffic and provides better security to the data.
Disadvantage:
The only disadvantage of Stored Procedure is that it can be executed only in the
Scalar Functions
Scalar returns the unit, variant defined the return clause. Other two types of defined
Collation is defined as a set of rules that determine how data can be sorted as well as
compared. Character data is sorted using the rules that define the correct character
sequence along with options for specifying case-sensitivity, character width etc.
Autoincrement keyword allows the user to create a unique number to get generated
AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword can be
from multiple sources of information. Those data are consolidated, transformed and
made available for the mining as well as online processing. Warehouse data also
Q112. 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
Click Start> Programs> Microsoft SQL Server and click SQL Enterprise
Manager to run SQL Enterprise Manager from the Microsoft SQL Server
program group.
Select SQL Server Configuration Properties, and choose the Security page.
where,
length: It refers to the number of characters in the string which are substituted.
replacement_string: They are the new characters which are injected in the string.
REPLACE function: This function is used to replace the existing characters of all the
occurrences. Syntax:
replacement_string.
So this brings us to the end of the SQL interview questions blog. I hope this set of
SQL Interview Questions will help you ace your job interview. All the best for your
interview!
Apart from this SQL Interview Questions Blog, if you want to get trained from
professionals on SQL, you can opt for a structured training from edureka! Click
Check out this MySQL DBA Certification Training by Edureka, a trusted online
learning company with a network of more than 250,000 satisfied learners spread
across the globe. This course trains you on the core concepts & advanced tools and
techniques to manage data and administer the MySQL Database. It includes hands-
MySQL Connector, Database Design, MySQL Command line, MySQL Functions etc.
End of the training you will be able to create and administer your own MySQL
If you wish to learn Microsoft SQL Server and build a career in the relational
databases, functions, and queries, variables etc domain, then check out our
interactive, live-online SQL Certification Course here, which comes with 24*7
If you want to start a career in the MongoDB field then check out this MongoDB
Got a question for us? Please mention it in the comments section of this “SQL
Interview Questions” blog and we will get back to you as soon as possible.