Inteview Questions

  1. What is DBMS ?
    The database management system is a collection of programs that enables user to store, retrieve, update and delete information from a database.


  1. What is SQL ?
    Structured Query Language(SQL) is a language designed specifically for communicating with databases. SQL is an ANSI (American National Standards Institute) standard.


  1. What are the different type of SQL’s statements ?
    This is one of the most frequently asked SQL Interview Questions for freshers. SQL statements are broadly classified into three. They are

    1. DDL – Data Definition Language
      DDL is used to define the structure that holds the data. For example, Create, Alter, Drop and Truncate table.
    2. DML – Data Manipulation Language
      DML is used for manipulation of the data itself. Typical operations are Insert, Delete, Update and retrieving the data from the table. The Select statement is considered as a limited version of the DML, since it can’t change the data in the database. But it can perform operations on data retrieved from the DBMS, before the results are returned to the calling function.
    3. DCL – Data Control Language
      DCL is used to control the visibility of data like granting database access and set privileges to create tables, etc. Example – Grant,


  1. What is a Table in a database ?
    A table is a collection of records of a specific type. For example, employee table, salary table etc.


  1. What is a database transaction?

Database transaction takes database from one consistent state to another. At the end of the transaction the system must be in the prior state if the transaction fails or the status of the system should reflect the successful completion if the transaction goes through.


  1. What are properties of a transaction?

Expect this SQL Interview Questions as a part of an any interview, irrespective of your experience.

Properties of the transaction can be summarized as ACID Properties.

  1. Atomicity

A transaction consists of many steps. When all the steps in a transaction get completed, it will get reflected in DB or if any step fails, all the transactions are rolled back.

  1. Consistency

The database will move from one consistent state to another, if the transaction succeeds and remain in the original state, if the transaction fails.

  1. Isolation

Every transaction should operate as if it is the only transaction in the system.

  1. Durability

Once a transaction has completed successfully, the updated rows/records must be available for all other transactions on a permanent basis.


  1. What is a Database Lock ?

Database lock tells a transaction, if the data item in questions is currently being used by other transactions.


  1. What are the type of locks ?


  1. Shared Lock

When a shared lock is applied on data item, other transactions can only read the item, but can’t write into it.

  1. Exclusive Lock

When an exclusive lock is applied on data item, other transactions can’t read or write into the data item.

Database Normalization Interview Questions


  1. What are the different type of normalization?

In database design, we start with one single table, with all possible columns. A lot of redundant data would be present since it’s a single table. The process of removing the redundant data, by splitting up the table in a well defined fashion is called normalization.

  1. First Normal Form (1NF)

A relation is said to be in first normal form if and only if all underlying domains contain atomic values only. After 1NF, we can still have redundant data.

  1. Second Normal Form (2NF)

A relation is said to be in 2NF if and only if it is in 1NF and every non key attribute is fully dependent on the primary key. After 2NF, we can still have redundant data.

  1. Third Normal Form (3NF)

A relation is said to be in 3NF, if and only if it is in 2NF and every non key attribute is non-transitively dependent on the primary key.

Database Keys and Constraints SQL Interview Questions


  1. What is a primary key?


A primary key is a column whose values uniquely identify every row in a table. Primary key values can never be reused. If a row is deleted from the table, its primary key may not be assigned to any new rows in the future. To define a field as primary key, following conditions had to be met :

  1. No two rows can have the same primary key value.
  2. Every row must have a primary key value.
  3. The primary key field cannot be null.
  4. Value in a primary key column can never be modified or updated, if any foreign key refers to that primary key.


  1. What is a Composite Key ?

A Composite primary key is a type of candidate key, which represents a set of columns whose values uniquely identify every row in a table.

For example –  if “Employee_ID” and “Employee Name” in a table is combined to uniquely identify a row its called a Composite Key.


  1. What is a Composite Primary Key ?

A Composite primary key is a set of columns whose values uniquely identify every row in a table. What it means is that, a table which contains composite primary key will be indexed based on the columns specified in the primary key. This key will be referred in Foreign Key tables.

For example – if the combined effect of columns, “Employee_ID” and “Employee Name” in a table is required to uniquely identify a row, its called a Composite Primary Key. In this case, both the columns will be represented as primary key.




  1. What is a Foreign Key ?

When a “one” table’s primary key field is added to a related “many” table in order to create the common field which relates the two tables, it is called a foreign key in the “many” table.

For example, the salary of an employee is stored in salary table. The relation is established via foreign key column “Employee_ID_Ref” which refers “Employee_ID” field in the Employee table.


  1. What is a Unique Key ?

Unique key is same as primary with the difference being the existence of null. Unique key field allows one value as NULL value.


  1. What’s wrong in the following query?

SELECT subject_code, count(name)

FROM students;


It doesn’t have a GROUP BY clause. The subject_code should be in the GROUP BY clause.

SELECT subject_code, count(name)   FROM students   GROUP BY subject_code;


  1. What’s wrong in the following query?

SELECT student_code, name

FROM students

WHERE marks =

(SELECT MAX(marks)

FROM students

GROUP BY subject_code);

Here a single row operator = is used with a multiple row subquery.


  1. What is the purpose of the MERGE statement in SQL?

The MERGE statement allows conditional update or insertion of data into a database table. It performs an UPDATE if the rows exists, or an INSERT if the row does not exist.


  1. You have a composite index of three columns, and you only provide the value of two columns in WHERE clause of a select query? Will Index be used for this operation? 

For example if Index is on EmpId, EmpFirstName, and EmpSecondName and you write query like

SELECT * FROM Employee WHERE EmpId=2 and EmpFirstName=’Varun’
If the given two columns are secondary index column then the index will not invoke, but if the given 2 columns contain the primary index(first column while creating index) then the index will invoke. In this case, Index will be used because EmpId and EmpFirstName are primary columns.

%d bloggers like this: