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

Top 70+ SQL Interview Questions and Answers (Mostly Asked)

The document provides an overview of a blog post on top SQL interview questions and answers for 2022. It contains 72 SQL questions divided into basic, intermediate, and advanced categories to help readers learn SQL thoroughly. The questions cover SQL fundamentals like what is a database, normalization, joins, and more. The blog aims to guide readers through various SQL concepts and help prepare for SQL interviews.

Uploaded by

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

Top 70+ SQL Interview Questions and Answers (Mostly Asked)

The document provides an overview of a blog post on top SQL interview questions and answers for 2022. It contains 72 SQL questions divided into basic, intermediate, and advanced categories to help readers learn SQL thoroughly. The questions cover SQL fundamentals like what is a database, normalization, joins, and more. The blog aims to guide readers through various SQL concepts and help prepare for SQL interviews.

Uploaded by

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

Top 72 SQL Interview

Questions and Answers for


2022
Updated on June 15, 2022

Go through these top Structured Query


Language (SQL) interview questions for
developers to learn SQL programming
thoroughly. SQL is one of the most widely
used..Read More

Become a Certified Professional

Top SQL Interview Questions

A relational database management system (RDBMS)


is the most common database used across
organizations, making SQL a must-have skill. This
blog aims to guide you through various SQL
questions from concepts such as MS SQL Server,
MySQL database, etc. This blog contains SQL
interview questions for freshers and experienced
professionals. It is a one-stop resource through
which you can avail maximum benefits and prepare
for job interviews easily. Check out the top SQL
interview questions asked by recruiters today:

Q1. Define database


Q2. What is DBMS and RDBMS? Explain the differenc
e between them.
Q3. What is SQL?
Q4. What is normalization and its types?
Q5. What is denormalization?
Q6. What are Joins in SQL?
Q7. Explain the types of SQL Joins
Q8. What are the subsets of SQL?
Q9. What are the applications of SQL?
Q10. What is a DEFAULT constraint?

This blog on SQL interview questions and answers


can be divided into three parts:

1. Basic SQL Interview Questions

2. Intermediate SQL Interview Questions

3. Advanced SQL Interview Questions

Watch this video on SQL Interview Questions and


Answers:

SQL Interview Questions an…

Basic SQL Interview Questions

1. Define database.

A database is an organized collection of structured


data that can be stored, easily accessed, managed,
and retrieved digitally from a remote or local
computer system. Databases can be complex and
vast and are built with a fixed design and modeling
approach. While smaller databases can be stored on
a file system, large ones are hosted on computer
clusters or cloud storage.

2. What is DBMS and RDBMS? Explain the


difference between them.

A database management system or DBMS is system


software that can create, retrieve, update, and
manage a database. It ensures the consistency of
data and sees to it that it is organized and easily
accessible by acting as an interface between the
database and its end-users or application software.
DBMS can be classified into four types:

Hierarchical Database: It has a treelike structure


with the data being stored in a hierarchical
format. The parent in a database can have
multiple children, but a child can have only a
single parent.
Network Database: This type of database is
presented as a graph that can have many-to-
many relationships allowing children to have
multiple children.
Relational Database: It is the most widely used
and easy-to-use database. It is represented as a
table and the values in the columns and rows are
related to each other.
Object-oriented Database: The data values and
operations are stored as objects in this type of
database, and these objects have multiple
relationships among them.

RDBMS stores data in the form of a collection of tabl


es. The relations are defined between the common
fields of these tables. MS SQL Server, MySQL, IBM
DB2, Oracle, and Amazon Redshift are all based on
RDBMS.

DBMS vs RDBMS

Parameters DBMS RDBMS

Access Data Multiple data


elements elements can
need to be be accessed at
accessed the same time
separately

Relationship No Data in tables


Between Data relationship is related to
between each other
data

Normalization It is not It is present


present

Distributed It does not It supports


Database support distributed
distributed database
database

Data Storage Data is Data is stored


Format stored in in a tabular
either a structure with
navigational headers being
or the column
hierarchical names and the
form rows
containing
corresponding
values

Amount of It deals with It deals with a


Data a small larger amount
quantity of of data
data

Data It is Keys and


Redundancy prevalent indexes do not
allow data
redundancy

Number of It supports a It supports


Users single user multiple users

Data Fetching It is slower It is speedy


for large due to the
amounts of relational
data approach

Data Security Low-security Multiple levels


levels when of data
it comes to security exist
data
manipulation

Software and Low  High


Hardware
Requirements

Examples XML, MySQL, SQL


Window Server, Oracle,
Registry, etc. Microsoft
Access,
PostgreSQL,
etc.

3. What is SQL?

SQL stands for Structured Query Language. It is the


standard language for RDBMS and is useful in
handling organized data that has entities or variables
with relations between them. SQL is used for
communicating with databases.

According to ANSI, SQL is used for maintaining


RDBMS and for performing different operations of
data manipulation on different types of data by using
the features of SQL. Basically, it is a database
language that is used for the creation and deletion of
databases. It can also be used, among other things,
to fetch and modify the rows of a table.

4. What is normalization and its types?

Normalization is used in reducing data redundancy


and dependency by organizing fields and tables in
databases. It involves constructing tables and setting
up relationships between those tables according to
certain rules. The redundancy and inconsistent
dependency can be removed using these rules to
make normalization more flexible.

The different forms of normalization are: 

First Normal Form: If every attribute in a relation


is single-valued, then it is in the first normal
form. If it contains a composite or multi-valued
attribute, then it is in violation of the first normal
form.
Second Normal Form: A relation is said to be in
the second normal form if it has met the
conditions for the first normal form and does not
have any partial dependency, i.e., it does not
have a non-prime attribute that relies on any
proper subset of any candidate key of the table.
Often, the solution to this problem is specifying a
single-column primary key.
Third Normal Form: A relation is in the third
normal form when it meets the conditions for
the second normal form and there is not any
transitive dependency between the non-prime
attributes, i.e., all the non-prime attributes are
decided only by the candidate keys of the
relation and not by other non-prime attributes.
Boyce-Codd Normal Form: A relation is in the
Boyce-Codd normal form or BCNF if it meets the
conditions of the third normal form, and for
every functional dependency, the left-hand side
is a super key. A relation is in BCNF if and only if
X is a super key for every nontrivial functional
dependency in form X –> Y.

5. What is denormalization?

Denormalization is the opposite of normalization;


redundant data is added to speed up complex
queries that have multiple tables that need to be
joined. Optimization of the read performance of a
database is attempted by adding or grouping
redundant copies of data.

6. What are Joins in SQL?

Join in SQL is used to combine rows from two or


more tables based on a related column between
them. There are various types of Joins that can be
used to retrieve data, and it depends on the
relationship between tables.

There are four types of Joins:

Inner Join
Left Join
Right Join
Full Join

7. Explain the types of SQL joins.

There are four different types of SQL Joins:

(Inner) Join: It is used to retrieve the records


that have matching values in both the tables
that are involved in the join. Inner Join is
mostly used to join queries.

SELECT *
FROM Table_A
JOIN Table_B;
SELECT *
FROM Table_A
INNER JOIN Table_B;

Left (Outer) Join: Use of left join is to retrieve


all the records or rows from the left and the
matched ones from the right.

SELECT *
FROM Table_A A
LEFT JOIN Table_B B
ON A.col = B.col;

Right (Outer) Join: Use of Right join is to


retrieve all the records or rows from the right
and the matched ones from the left.

SELECT *
FROM Table_A A
RIGHT JOIN Table_B B
ON A.col = B.col;

Full (Outer) Join: The use of Full join is to retrieve


the records that have a match either in the left
table or the right table.

SELECT *
FROM Table_A A
FULL JOIN Table_B B
ON A.col = B.col;

Get 100% Hike!


Master Most in Demand Skills Now !

Email Address

Phone Number
+91  IN          INDIA

Submit

8. What are the subsets of SQL?

SQL queries are divided into four main categories:

Data Definition Language (DDL)


DDL queries are made up of SQL commands that
can be used to define the structure of the
database and modify it.

CREATE Creates databases, tables, schema,


etc.
DROP: Drops tables and other database
objects
DROP COLUMN: Drops a column from any
table structure
ALTER: Alters the definition of database
objects
TRUNCATE: Removes tables, views,
procedures, and other database objects
ADD COLUMN: Adds any column to the table
schema

Data Manipulation Language (DML)


These SQL queries are used to manipulate data
in a database.

SELECT INTO: Selects data from one table


and inserts it into another
INSERT: Inserts data or records into a table
UPDATE: Updates the value of any record in
the database
DELETE: Deletes records from a table

Data Control Language (DCL)


These SQL queries manage the access rights and
permission control of the database.

GRANT: Grants access rights to database


objects
REVOKE: Withdraws permission from
database objects

Transaction Control Language (TCL)


TCL is a set of commands that essentially
manages the transactions in a database and the
changes made by the DML statements. TCL
allows statements to be grouped together into
logical transactions. 

COMMIT: Commits an irreversible


transaction, i.e., the previous image of the
database prior to the transaction cannot be
retrieved
ROLLBACK: Reverts the steps in a transaction
in case of an error
SAVEPOINT: Sets a savepoint in the
transaction to which rollback can be
executed
SET TRANSACTION: Sets the characteristics
of the transaction

9. What are the applications of SQL?

The major applications of SQL include:

Writing data integration scripts


Setting and running analytical queries
Retrieving subsets of information within a
database for analytics applications and
transaction processing
Adding, updating, and deleting rows and
columns of data in a database

10. What is a DEFAULT constraint?

Constraints in SQL are used to specify some sort of


rules for processing data and limiting the type of
data that can go into a table. Now, let us understand
what is a default constraint.

A default constraint is used to define a default value


for a column so that it is added to all new records if
no other value is specified. For example, if we assign
a default constraint for the E_salary column in the
following table and set the default value to 85000,
then all the entries of this column will have the
default value of 85000, unless no other value has
been assigned during the insertion.

Now, let us go through how to set a default


constraint. We will start by creating a new table and
adding a default constraint to one of its columns.

Code:

create table stu1(s_id int, s_name varcha


select *stu1

Output:

Now, we will insert the records.

Code:

insert into stu1(s_id,s_name) values(1,’S


insert into stu1(s_id,s_name) values(2,’B
insert into stu1(s_id,s_name) values(3,’M
select *from stu1

Output:

Also, learn from our blog on MySQL Interview Ques


tions and Answers to crack any Interview.

11. What is a UNIQUE constraint?

Unique constraints ensure that all the values in a


column are different. For example, if we assign a
unique constraint to the e_name column in the
following table, then every entry in this column
should have a unique value.

First, we will create a table.

create table stu2(s_id int unique, s_name

Now, we will insert the records.

insert into stu2 values(1,’Julia’)


insert into stu2 values(2,’Matt’)
insert into stu2 values(3,’Anne’)

Output:

A PRIMARY KEY constraint will automatically have a


UNIQUE constraint. However, unlike a PRIMARY KEY,
multiple UNIQUE constraints are allowed per table.

12. What is meant by table and field in


SQL?

An organized data in the form of rows and columns


is said to be a table. Simply put, it is a collection of
related data in a table format.

Here rows and columns are referred to as tuples and


attributes, and the number of columns in a table is
referred to as a field. In the record, fields represent
the characteristics and attributes and contain specific
information about the data.

13. What is a primary key?

A primary key is used to uniquely identify all table


records. It cannot have NULL values and must
contain unique values. Only one primary key can
exist in one table, and it may have single or multiple
fields, making it a composite key.

Now, we will write a query for demonstrating the use


of a primary key for the employee table:

//
CREATE TABLE Employee (
ID int NOT NULL,
Employee_name varchar(255) NOT NULL,
Employee_designation varchar(255),
Employee_Age int,
PRIMARY KEY (ID)
);

14. What is a unique key?

The key that can accept only a null value and cannot
accept duplicate values is called a unique key. The
role of a unique key is to make sure that all columns
and rows are unique.

The syntax for a unique key will be the same as the


primary key. So, the query using a unique key for the
employee table will be:

//
CREATE TABLE Employee (
ID int NOT NULL,
Employee_name varchar(255) NOT NULL,
Employee_designation varchar(255),
Employee_Age int,
UNIQUE(ID)
);

15. What is the difference between


primary key and unique key?
2
BothBecome a Certified
primary and uniqueProfessional
keys carry unique
! values
Chat

You might also like