If you prefer jobs related to Database 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.
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 the task, such as updating, retrieval, insertion and deletion of data from a database.
3. What is field in database?
A field in 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 which are related by 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 kind of SQL’s 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.
12. List some samples of constraints?
- NOT NULL.
- PRIMARY KEY.
- FOREIGN KEY.
13. Define Join and their different types?
It is used to join two or more tables, The join keyword fetch 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.
Table Name: Employee
|Employee_id||First name||Last name||Salary||Department|
15. Query to get all employee details from employee table
SELECT * FROM Employee
16. Get first name ,last name from employee table
SELECT FIRST NAME, LAST NAME from employee
17. Get unique Department from 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 top 2 salary from 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.
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 table in database?
By using ‘CREATE TABLE’ command table can be created
CREATE TABLE "EMPLOYEE"
24. How to create Database?
CREATE DATABASE <em>employee</em>;
25. What are the advantages of views in a database?
- It doesn’t store data in physical location.
- It can be used to hide some of the columns from the tables
- It can provide access restriction.