Skip to content

Top 25+ Important SQL Interview Questions & Answers

Reading Time: 3 minutes

SQL Interview Questions and Answers, in this section we have given the most frequently asked questions and answers here for SQL interviews. If you prefer jobs related to Database or SQL related, then I hope these questions will help you to do your interview better. I have listed the top 25 SQL interview questions with a simple explanation.

SQL Interview Questions & Answers

SQL Interview Questions or Database Interview Questions available are generally frequently asked questions & answers. So it will be a great help to your upcoming interview to place the job in SQL – Database Industry

See also  25+ Important Data Modeling Interview Questions

1. What is DBMS?

DBMS-Database Management System is a program that helps the user to store, delete, update and retrieve data from a database.

2. What is SQL?

SQL-Structural Query Language is a language specially designed for communicating with the database. It is used to perform tasks, such as updating, retrieval, insertion, and deletion of data from a database.

3. What is a field in the database?

A field in a database is defined as the area within a record reserved for a specific piece of data.

4. What is RDBMS?

RDBMS-Relational Database Management System is based on the relational model. It stores the data into a collection of tables that are related to common fields.

5.  What is Trigger?

A trigger executes as a response to an action on the table, i.e. insert, delete or update. It is a kind of store procedure and can’t be explicitly invoked.

6. List different kinds of SQL statements?

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

7. What is a record in the database?

A record in the database is defined as the collection of values or fields of a specific entity.

8. What is a table in the database?

A table is defined as the collection of records of a specific type.

9.  What is a primary key?

The primary key helps to uniquely identify the items in a table.

10. What is a foreign key?

The foreign key helps to uniquely identify the items in a different table.

11. What is a constraint?

Constraints are used to specify the limits of the data type of table. It is specified while creating or altering the table statement.

See also  GROUPBY vs HAVING

12.  List some samples of constraints?

  • NOT NULL.
  • CHECK.
  • DEFAULT.
  • PRIMARY KEY.
  • FOREIGN KEY.
  • UNIQUE.

13.  Define Join and their different types?

It is used to join two or more tables, The join keyword fetches the data based on the common field between them.

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

14. What is the difference between DELETE and TRUNCATE commands?

DELETE is a DML command and it locks each row in the table for deletions, While TRUNCATE is a DDL command and it locks the table and page but not each row.

sql interview questions

SQL Query

Table Name: Employee

Employee_idFirst nameLast nameSalaryDepartment
1ViratKohli50000Banking
2RockySingh80000Insurance
3JohnMichael70000Banking
4JerryJose60000Insurance
5TomPicasso65000Insurance

15. Query to get all employee details from the employee table

SELECT * FROM Employee

16. Get the first name, and last name from the employee table

SELECT  FIRST NAME, LAST NAME from employee

17. Get a unique Department from the employee table

SELECT  distinct DEPARTMENT  from employee

18. Get employee details whose first name is ‘Tom’

Select * from EMPLOYEE where FIRSTNAME='Tom'

19. Get the employee details whose first name contains ‘E’

Select * from EMPLOYEE where FIRSTNAME like '%e%'

20. Get the top 2 salaries from the employee table

select * from (select * from employee order by salary desc) where employeeid <4

21. What is a Relationship and list their types?

The relationship is defined as the connection between the tables in a database. Types of relationships are

  • One to Many Relationship.
  • Many to One Relationship.
  • Self-Referencing Relationship.
  • One-to-One Relationship.
See also  ASP.NET Interview Questions

22. What is a view?

The view in the database is a virtual table based on the set of an SQL statement. It contains rows and columns, just like a real table in the database.

23. How to create a table in a database?

By using the ‘CREATE TABLE’ command table can be created

CREATE TABLE "EMPLOYEE"

{

EmployeeID int,

FirstName varchar(255),

LastName varchar(255),

Salary int,

Department varchar(255),
 );

24. How to create a Database?

CREATE DATABASE employee;

25. What are the advantages of views in a database?

  • It doesn’t store data in a physical location.
  • It can be used to hide some of the columns from the tables
  • It can provide access restrictions.

Leave a Reply