Top 50+ SQL Interview Questions

In SQL tutorial we will discuss some of the most important asked SQL queries in interviews. The questions will start from basic questions and then move to complex questions.

The SQL Structured Query Language interview questions most important for all candidates who want to start our career in database management sector's.

SQL database interview question

Q1- What is SQL?

SQL stands for Structured Query Language. SQL is a database computer language, it is use to store data from data table by the help of queries. It designed for the retrieval and management of data in a relational database. It is basically a program which is considered when it comes to maintaining, creating, deploying, controlling as well as monitoring the use of a database. It can also be considered as a file manager which is good enough to be trusted for managing the data kept in a database than a file system. More Details →

Q2- What is a query?

A SQL query Or SQL DB query is a code written in order to get the information back from the database. Query can be designed in such a way that it matched with our expectation of the result set. Simply, we can say that a question to the Database.

Q3- What is subquery?

The inner query is called subquery. SubQuery is always executed first, and the result of subquery is passed on to the main query. SubQuery is always inside the main query, and main query is also called outer query. Basically, A subquery is a query within another query.

Q4- What is the difference between SQL and PL/SQL?

SQL is a single query or command executive, it is not a Full programming language PL/SQL is a Full programming language, it is not a command executive language
Data source for reports, web pages Application language to build, format and display report, web pages
Declarative in nature and Manipulating data Procedural in nature and Creating Applications

Q5- What is a primary key?

A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.

  • A Primary key is a set of columns that uniquely identifies each row in the table.
  • Uniquely identifies a single row in the table
  • Null values not allowed

Q6- What is a foreign key?

A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.

Q7- What is the DBMS? What are the different types?

A Database Management System (DBMS) is a software application that interacts with the user, applications and the database itself to capture and analyze data.

  • Relational Database Management System: The data is stored in relations (tables). Example – MySQL.
  • Non-Relational Database Management System: There is no concept of relations, tuples and attributes. Example – Mongo

Q8- What are the uses of SQL?

  • SQL is responsible for maintaining the relational data and the data structures present in the database.
  • To execute queries against a database
  • To retrieve data, insert records, update records, delete records, create new databases, create new table, create views in a database.

Q9- What do you mean by Fields and Tables and how they are useful?

A table is a set of different rows and columns and is organized in a model. The manner of columns and rows are vertical and horizontal. In a table, there are some specific numbers of columns which remains present and is generally known as fields. There is no strict upper limit on the overall number of records which are defined by rows in the table.

Q10- What is a join? What are the types of join?

An SQL JOIN clause combines rows from two or more tables. It creates a set of rows in a temporary table.

Basic SQL Join types:

  • Inner Join
  • Left Join
  • Right Join
  • Full Join

Learn More About Join →

Q11- What is the difference between SQL and MySQL?

SQL is a standard language which stands for Structured Query Language based on the English language whereas MySQL is a database management system.

  • SQL - It is the core of relational database which is used for accessing and managing database.
  • MySQL - It is an Relational Database Management System (RDMS) such as SQL Server, Informix etc.

Q12- Does SQL support programming?

  • SQL refers to the Standard Query Language, which is not actually the programming language.
  • SQL doesn't have a loop, Conditional statement, logical operations, it can not be used for anything other than data manipulation.
  • It is used like commanding (Query) language to access databases.
  • The primary purpose of SQL is to retrieve, manipulate, update and perform complex operations like joins on the data present in the database.

Q13- What is a DDL?

DDL stand for Data Definition Language; it is the subset of the database which defines the data structure of the database in the initial stage when the database is about to be created. It have the following commands: CREATE, ALTER and DELETE database objects such as schema, tables, view etc.

Q14- Why do we use SQL constraints?

Constraints are used to set the rules for all records in the table. If any constraints get violated then it can abort the action that caused it.

Q15- Which constraints we can use while creating database in SQL?

There are 5 constraints are used in SQL to create database:

  • NOT NULL - That indicates that the column must have some value and cannot be left null
  • UNIQUE - This constraint is used to ensure that each row and column has unique value and no value is being repeated in any other row or column
  • PRIMARY KEY - This constraint is used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.
  • FOREIGN KEY - It is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key
  • CHECK - It is used to ensure whether the value in columns fulfills the specified condition

Q16- What are the various levels of constraints?

Constraints are the representation of a column to enforce data entity and consistency. There are two levels of a constraint use in SQL

  • column level constraint
  • table level constraint

Q17- 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.

SELECT * FROM Table_Name where ROLL_NO BETWEEN 10 AND 50;

Example of IN -
SELECT * FROM Table_Name where ROLL_NO IN (8,15,25);

Table Name is like - Students

Q18- What are different Clauses used in SQL?

  • WHERE Clause - This clause is used to define the condition, extract and display only those records which fulfill the given condition
  • GROUP BY Clause - It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.
  • HAVING clause - This clause is used in association with GROUP BY clause. It is applied to the each group of result or the entire result as single group and much similar as WHERE clause, the only difference is you cannot use it without GROUP BY clause
  • ORDER BY clause - This clause is to define the order of the query output either in ascending (ASC) or in descending (DESC) order. Ascending (ASC) is the default one but descending (DESC) is set explicitly.
  • USING clause - USING clause comes in use while working with SQL Joins. It is used to check equality based on columns when tables are joined. It can be used instead ON clause in Joins.

Syntax Example:

WHERE - Select column_name(s) FROM table_name WHERE condition;
GROUP BY - Select column_name(s) FROM table_name GROUP BY column_name;
HAVING - Select column_name(s) FROM table_name GROUP BY column_name HAVING condition;
ORDER BY - Select column_name(s) FROM table_name WHERE condition ORDER BY column_name ASC|DESC;
USING - Select column_name(s) FROM table_name JOIN table_name USING (column_name);

Q19- Is it possible to order the records by two columns?

Yes. It is possible to order the records by using two columns.

Syntax Used to ORDER two colums:
Select * from Table_Name ORDER BY Column1 Column2;

Q20- Why are SQL functions used?

  • Perform some calculations on the data
  • Modify individual data items
  • Manipulate the output
  • Format dates and numbers
  • Convert the data types

Q21- What is normalization?

Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.

Q22- What are all the different normalizations?

  • 1NF - This should remove all the duplicate columns from the table. Creation of tables for the related data and identification of unique columns.
  • 2NF - Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and Creation of relationships between the tables using primary keys.
  • 3NF - This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key constraints.
  • 4NF - Fourth normal form (4NF) is a level of database normalization where there are no non-trivial multivalued dependencies other than a candidate key. It builds on the first three normal forms (1NF, 2NF and 3NF) and the Boyce-Codd Normal Form (BCNF).

Q23- What is Denormalization.

Denormalization is an approach to speeding up read-oriented data retrieval performance in a relational database, where the database administrator selectively adds back specific instances of redundant data after the data structure has been normalized.

  • A denormalized database should not be confused with a database that has never been normalized.
  • Denormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.

Q24- What is an Index?

An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.

Q25- What is the different types of indexes in SQL and define them?

Unique Index - Prevents duplicate entries within uniquely indexed columns. They are automatically generated if a Primary Key is available.

Clustered Index - Used to organize or edit the arrangement within the table, with respect to the key value. Each table is only allowed to have a single clustered index only.

Non Clustered Index - NonClustered Index only manages the order of logic within entries. It does not manage the arrangement and tables can have multiple NonClustered Indexes.

Q26- What is UNION and UNION ALL keyword in SQL?

The UNION operator in SQL combines multiple sets highlighted in the SELECT statements. The restrictions of the set are:

  • Column number must be identical,
  • Data Types in the set must be the same,
  • The order of the column highlighted in the SELECT statement must be the same. It automatically eliminates duplicate rows within the results highlighted in the SELECT statement.

UNION ALL does the same function as the UNION, but it includes all, including the duplicate rows.

C1, C2, C3 & C4 → Column_Name & T1 & T2 → Table_Name

Q27- What is View in SQL?

A View can be defined as a virtual table that contains rows and columns with fields from one or more table.

Syntax Example -
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition;

Q28- What is distinct?

Distinct is used to supress duplicate row in select query More Details →

Q29- What is difference between nested sub query & Co-related sub query?

Nested Sub Query -

  • Nested subquery executes only once for the entire nesting query.
  • Nested subquery does not contain any reference to the outer query row.

Co-related Sub Query -

  • Co-rrelated subquery executes single time for every row which is selected by the outer query.
  • Co-rrelated subquery has a reference to a value from the row selected by the outer query.

Q30- What are the different types of queries in SQL?

These types of queries used in SQL explained below:

  • DDL - Data Definition Language
  • DML - Data Manipulation Language
  • DCL - Data Control Language

Data Definition Language - Allows to work with the Structure or Definition of the data. SQL commands: CREATE, ALTER, DROP, TRUNCATE, COMMENT, RENAME

Data Manipulation Language - It is a query that is used to insert, update, or delete the data from a database table. These queries include INSERT INTO, UPDATE, SELECT and DELETE queries

Data Control Language - It is use to controls the data. SQL Commands: GRANT, REVOKE, DENY. The administrative tasks include creation of user, partitioning of database, providing grants to the user, assigning roles to the user and creating users as well. More Details →

Q31- What are aliases in SQL?

Aliases in SQL are used to provide alternate names for columns and tables in SQL queries. It is used when name of column or table is used other than their original names, but the modified name is only temporary. Aliases are created to make table or column names more readable. The aliases help in resolving anonymity when trying to join tables. If two different tables contain the columns of same name, aliases help in selecting a specific column only in the select clause.

Q32- What are SQL functions?

SQL defines certain standard functions that can be used to perform mathematical manipulations. There are two types of SQL functions, aggregate functions, and scalar(non-aggregate) functions.

SQL Aggregate Function -

  • Aggregate functions are Count, Sum, Avg, Max, Min functions

SQL Arithmetic Fuction -

  • Arithmetic functions are abs(), ceil(), floor(), exp(), In(), mod(), power(), and sqrt()

Q33- What is a wildcard?

A wildcard character is used to substitute any other character(s) in a string. It is used with LIKE operator to provide a wildcard match of values More Details →

Q34- What is Difference between Truncate and Delete in SQL?

We can’t execute a trigger with TRUNCATE A trigger can be executed, DELETE command.
TRUNCATE is a Data Definition Language command DELETE is a Data Manipulation Language command.
TRUNCATE will not store data in rollback space and will directly delete it. When you use DELETE to delete the data, at that time it store the whole data in rollback space from where you can get the data back after deletion

Q35- What is Trigger?

  • A trigger is a special type of stored procedure that automatically executes when an event occurs in the database server.
  • A Trigger is a process of firing an action when some event like Insert, Update or Delete occurs.
  • Triggers can be defined on the table, view, schema, or database with which the event is associated.


We are optimized for learning and job information. We try to improve your knowledge and practical experience through this site but we cannot warrant full correctness of all content. Our Privacy & Policy →

© 2019 | All Rights Reserved