Top 20 Important SQL Interview Questions & Answers

5.00 avg. rating (97% score) - 2 votes

SQL is an important querying language which used to create and modify databases. If you are preparing for an SQL interview, this article will help you to understand the important questions which are asked and the answers associated with it.

There are various profiles like data analyst, database administrator and data architect that requires the knowledge of SQL. Apart from guiding you in your interviews, this article will also give a basic knowledge of SQL.

Here are some of the probable SQL Interview questions that may be asked in a SQL interview:

 

Q1. What is a DBMS?

 

Before starting with SQL, let us have a brief understanding of DBMS (Database Management System). In simple it is a software that is used to create and manage databases. We are going to stick with RDBMS (relational DBMS) in this article (SQL). There is also non-relational DBMS like MongoDB used for big data analysis.

 

Q2. What is SQL?

 

SQL (structured querying language) is the language used to create, update and modify a database. Pronounced both as ‘Se-quell’ and ‘S-Q-L’.

 

Q3. What are the subsets of SQL?

 

There are three subsets of SQL – 1) data definition language (DDL), 2) data manipulation language (DML) and 3) data control language (DCL).

 

Q4. What is DDL?

 

DDL (data definition language) allows end-users to CREATE, ALTER and DELETE database objects.

 

Q5. What is DML?

 

DML (data manipulation language) allows end-users insert, update, retrieve and delete data in a database.

 

Q6. What is DCL?

 

DCL (data control language) allows end-users to control the access to the database, to GRANT or REVOKE permissions to manipulate or modify the database.

 

 

Q7. What is a primary key?

 

A primary key is used to define a column which uniquely identifies each row. Null value is not allowed.

 

Q8. What is a foreign key?

 

A foreign key is used to maintain the referential link integrity between two data tables. It prevents actions that can destroy links between a child and a parent table.

 

Also Read>> Data Science vs. Big Data vs. Data Analytics

 

Q9. What is a unique key?

 

A unique key is used to uniquely identify each record in a database. A primary key is a special kind of unique key.

 

Q10. What are the three types of indexes in SQL?

 

The three type of indexes in SQL are – unique index, clustered index and non-clustered index.

 

Also Read>> How to Become a Data Analyst from Scratch?

 

Q11. What is the difference between TRUNCATE and DELETE?

 

DELETE TRUNCATE
Delete command is used to delete a row in a table. Truncate is used to delete all the rows from a table.
You can rollback data after using delete statement. You cannot rollback data.
It is a DML command. It is a DDL command.
It is slower than a truncate statement. It is faster.

 

Q12. What is the difference?

 

SELECT * FROM MyTable WHERE MyColumn <> NULL

SELECT * FROM MyTable WHERE MyColumn IS NULL

The first line will not work because NULL means no value and you cannot use scalar value operators. This is why there is a separate IS NULL predicate in SQL.

 
 

Also Read>> Data Science vs Data Analysis: Which one is better?

 

Q13. What are joins and what are the different types of joins?

 

Join is a query which retrieves related columns or rows. There are four types of joins – inner join, left join, right join and full/outer join.

 

Q14. What port does the SQL server use?

 

The standard port for SQL server is 1433.

 

Q15. What is the difference between CHAR and VARCHAR?

 

CHAR is a fixed-length character data type while VARCHAR is a variable-length character data type.

 

Q16. What is a subquery in SQL?

 

A subquery is a query within another query. When there is a query within a query, the outer query is called the main query, while the inner query is called subquery.

How to find:

duplicate records with one field?

duplicate records with more than one field?

Finding duplicates:

with one field

SELECT COUNT(field)

FROM table_name

GROUP BY field

HAVING COUNT(field) > 1

with more than one field

SELECT field1,field2,field3, COUNT(*)

FROM table_name

GROUP BY field1,field2,field3

HAVING COUNT(*) > 1

 

Q17. Write an SQL query where to find names in a column starting with the letter A?

 

SELECT * FROM table_name WHERE column_name LIKE ‘A%’

 

Q18. What is a constraint and how many levels of constraints are there?

 

Constraints are the representation of a column to enforce data entity and consistency. There are two levels of constraint – column level and table level.

 

Q19. What is Auto Increment in SQL?

 

Auto increment allows a unique number to be generated whenever a new record is created in a table. Usually used with PRIMARY KEY.

The above questions will help you to prepare for an SQL interview and get an idea what type of questions are asked. You can also go for a certification course to improve your skills and knowledge. Naukri Learning offers a plethora of online database courses to help you become an expert and crack the interviews easily.

About the Author

Hasibuddin Ahmed

Hasibuddin Ahmed

Hasib is a professional writer associated with learning.naukri.com. He has written a number of articles related to technology, marketing, and career on various blogs and websites. As an amateur career guru, he often imparts nuggets of knowledge related to leadership and motivation. He is also an avid reader and passionate about the beautiful game of football.
Topics : IT and Telecom
Tags :