Frequently Asked Database, DBMS, and SQL Interview Questions and answers for fresher and Experienced developers covering topics such as Record, Field, Table, Database Transactions, Locks, Normalization, Foreign Key, Primary Key, Constraints, SQL Commands, Pattern Matching, SQL Joins, Views, Stored procedure, Trigger, Cluster and Non-cluster Index. These SQL interview questions cover basic and advanced topics.

 Q1. What is DBMS?

The database management system is a collection of programs that enables users to store, retrieve, update, and delete information from a database.

Q2. What is RDBMS?

A relational Database Management system (RDBMS) is a database management system (DBMS) that is based on the relational model. Data from relational databases can be accessed or reassembled in many different ways without having to reorganize the database tables. Data from the relational databases can be accessed using an API, Structured Query Language (SQL)

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

Q4. What is the different type of SQL?

Frequently asked SQL Interview Questions

  • Data Definition Language (DDL)  is a standard for commands that define the different structures in a database. DDL statements create, modify, and remove database objects such as tables, indexes, and users. Common DDL statements are CREATE, ALTER, and DROP.
  • Data Manipulation Language (DML) is used to retrieve, store, modify, delete, insert, and update data in the database. Examples: SELECT, UPDATE, INSERT statements. DDL is an abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in the database. DML is used for the manipulation of the data itself. Typical operations are inserting, Delete, Update, and retrieving the data from the table.
  • Data Control Language (DCL) is used to control the visibility of data like granting database access and setting privileges to create tables etc. DCL is a syntax similar to a computer programming language used to control access to data stored in a database (Authorization). In particular, it is a component of Structured Query Language (SQL). Examples of DCL commands include GRANT to allow specified users to perform specified tasks.
Q5. What are the Advantages of SQL
  1. SQL is not a proprietary language used by specific database vendors. Almost every major DBMS supports SQL, so learning this one language will enable programmers to interact with any database like ORACLE, SQL, MYSQL, etc.
  2. SQL is easy to learn. The statements are all made up of descriptive English words, and there aren’t that many of them.
  3. SQL is actually a very powerful language and by using its language elements you can perform very complex and sophisticated database operations.
Q6. What is a field in a database?

A field is an area within a record reserved for a specific piece of data. Examples: Employee Name, Employee ID, etc.

Q7. What is a Record in a database?

A record is the collection of values/fields of a specific entity: i.e. an Employee, Salary, etc.

Q8. What is a Table in a database?

A table is a collection of records of a specific type. For example, the employee table, salary table, etc.

Q9. What is a database transaction?

Database transactions take the 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.

Q10. What are the properties of a transaction?

The properties of the transaction can be summarized as ACID Properties.

  1. Atomicity: In this, a transaction consists of many steps. When all the steps in the transaction go completed it gets reflected in DB or if any step fails, all the transactions are rolled back.
  2. 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.
  3. Isolation: Every transaction should operate as if it is the only transaction in the system
  4. Durability: Once a transaction has been completed successfully, the updated rows/records must be available for all other transactions on a permanent basis
Q11. What is a Database Lock?

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

Q12. What is the type of lock?
  1. Shared Lock: When a shared lock is applied to the data item, other transactions can only read the item, but can’t write into it.
  2. Exclusive Lock: When an exclusive lock is applied to a data item, other transactions can’t read or write into the data item.
Q13. What is 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.
  2. 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
  3. 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
Q 14. 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. In the examples given below “Employee_ID” field is the primary key.

  1. To define a field as a primary key, the following conditions had to be met.
  2. No two rows can have the same primary key value.
  3. Every row must have a primary key value.
  4. The primary key field cannot be null.
  5. Values in primary key columns can never be modified or updated.
Q15. What is a SQL Composite Primary Key

A Composite primary key is a set of columns whose values uniquely identify every row in a table. For example, in the table given above, if “Employee_ID” and “Employee Name” together uniquely identify a row it’s called a Composite Primary Key. In this case, both columns will be represented as a primary key.

Q16. What is a Composite Primary Key?

A Composite primary key is a set of columns whose values uniquely identify every row in a table. For example, in the table given above, if “Employee_ID” and “Employee Name” together uniquely identify a row it’s called a Composite Primary Key. In this case, both columns will be represented as the primary keys.

Q17. 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. In the example given below, the salary of an employee is stored in the salary table. The relation is established via the foreign key column “Employee_ID_Ref” which refers “Employee_ID” field in the Employee table.

Q18. What is a Unique Key?

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

Q19. Define SQL Insert Statement.

The SQL INSERT statement is used to add rows to a table. For a full row insert, SQL Query should start with an “insert into “ statement followed by the table name and values command followed by the values that need to be inserted into the table. The insert can be used in several ways:

  1. To insert a single complete row.
  2. To insert a single partial row
Q20. Define SQL Update Statement.

SQL Update is used to update data in a row or set of rows specified in the filter condition. The basic format of an SQL UPDATE statement is, the Update command followed by the table to be updated and the SET command followed by column names and their new values followed by a filter condition that determines which rows should be updated

Q21. Define SQL Delete Statement.

SQL Delete is used to delete a row or set of rows specified in the filter condition. The basic format of an SQL DELETE statement is, the DELETE FROM command followed by table name followed by filter condition that determines which rows should be updated

Q22. What are wild cards used in the database for Pattern Matching?

SQL ‘Like’ search takes more time to process. So before using the like operator following tips should be considered. Don’t overuse wild cards. If another search operator will do, use it instead. When you do use wild cards, try to not use them at the beginning of the search pattern unless absolutely necessary. Search patterns that begin with wild cards are the slowest to process. Pay careful attention to the placement of the wild card symbols. If they are misplaced, you might not return the data you intended

 Q23. Define Join and explain different types of joins.

In order to avoid data duplication, data is stored in related tables. The join keyword is used to fetch data from the related table. Join return rows when there is at least one match in both tables. Type of joins are

  1. Right Join: Return all rows from the right table, even if there are no matches in the left table.
  2. Outer Join
  3. Left Join: Return all rows from the left table, even if there are no matches in the right table.
  4. Full Join: Return rows when there is a match in one of the tables.
Q24. What is Self-Join?

Self-join is a query used to join a table to itself. Aliases should be used for the same table comparison.

Q25. What is Cross Join?

Cross Join will return all records where each row from the first table is combined with each row from the second table.

 Q26. What is a view?

Views are virtual tables. Unlike tables that contain data, views simply contain queries that dynamically retrieve data when used.

Q27. What is a materialized view?

Materialized views are also a view but are disk-based. Materialized views get updated on a specific duration, based on the interval specified in the query definition. We can index materialized views.

Q28. What are the advantages and disadvantages of views in a database?


  1. Views don’t store data in a physical location.
  2. The view can be used to hide some of the columns from the table.
  3. Views can provide Access Restriction, since data insertion, update, and deletion is not possible on the view.


  1. When a table is dropped, the associated view becomes irrelevant.
  2. Since views are created when a query requesting data from a view is triggered, it’s a bit slow.
  3. When views are created for large tables, they occupy more memory.
Q29. What is a stored procedure?

The Stored Procedure is a function that contains a collection of SQL Queries. The procedure can take inputs, process them and send back output.

Q30. What are the advantages of a stored procedure?

Stored Procedures are pre-compiled and stored in the database. This enables the database to execute the queries much faster. Since many queries can be included in a stored procedure, round trip time to execute multiple queries from source code to database and back is avoided.

Q31. What is a trigger?

Databases are a set of commands that get executed when an event(Before Insert, After Insert, On Update, On delete of a row) occurs on a table, view.

Q32. Explain the difference between DELETE, TRUNCATE, and DROP commands.

Once the delete operation is performed Commit and Rollback can be performed to retrieve data. But after the transect statement, Commit and Rollback statements can’t be performed. Where condition can be used along with the delete statement but it can’t be used with the truncate statement. Drop command is used to drop the table or keys like primary, foreign from a table.

Q33. What is the difference between Cluster and Noncluster Index?

A clustered index reorders the way records in the table are physically stored. There can be only one clustered index per table. It makes data retrieval faster. A non-clustered index does not alter the way it was stored but creates a completely separate object within the table. As a result, inserting and updating commands will be faster.

Q34. What are Union, minus, and Interact commands?

MINUS operator is used to return rows from the first query but not from the second query. INTERSECT operator is used to return rows returned by both queries.

The article was published on May 21, 2017 @ 3:03 PM

Leave a Comment

1 Comment