SQL Interview Questions

Ques.1. What is a database?
Ans. A database is a structured collection of data for faster and better access, storage and manipulation of data.
A database can also be defined as a collection of tables, schema, views, and other database objects.

Ques.2. What is database testing?
Ans. Database testing involves checking the integrity of actual data in the front end with the data present in the database. It involves validating the data in the database, checking that there are no orphan records (record with a foreign key to a parent record that has been deleted”), no junk records are present, updating records in the database and verify the value in the front end.

Ques.3. What is RDBMS?
Ans. An RDBMS or Relational Database Management System is a type of DBMS having relationships between the tables using indexes and different constraints like primary key, foreign key etc. The use of indexes and constraints helps in faster retrieval and better management of data within the databases.

Ques.4. What is the difference between DBMS and RDBMS?
Ans. The primary difference between DBMS and RDBMS is, in RDBMS we have relations between the tables of the database. Whereas in DBMS there is no relation between the tables(data may even be stored in files).
RDBMS has primary keys and data is stored in tables. DBMS has no concept of primary keys with data stored in navigational or hierarchical form.
RDBMS defines integrity constraints in order to follow ACID properties. While DBMS doesn’t follow ACID properties.

Ques.5. What is a table?
Ans. Tables are the database object that is used for storing related records in the form of rows and columns.

Ques.6. What is the field in a table?
Ans. A field is an entity used for storing a particular type of data within a table like numbers, characters, dates, etc.

Ques.7. What is a tuple, record or row in a table?
Ans. A tuple or record is an ordered set of the related data item in a table.

Ques.8. What is SQL?
Ans. SQL stands for Structured Query Language, it is a language used for creating, storing, fetching and updating of data and database objects in RDBMS.

Ques.9. What are the different types of SQL commands?
Ans. SQL commands are the set of commands used to communicate and manage the data present in the database. The different type of SQL commands are-

  1. DDL – Data Definition Language
  2. DML – Data Manipulation Language
  3. DCL – Data Control Language
  4. TCL – Transactional Control Language

Ques.10. Explain DDL commands. What are the different DDL commands in SQL?
Ans. DDL refers to Data Definition Language, it is used to define or alter the structure of the database. The different DDL commands are-

  • CREATE – Used to create a table in the database
  • DROP – Drops the table from the database
  • ALTER – Alters the structure of the database
  • TRUNCATE – Deletes all the records from the database but not its database structure
  • RENAME – Renames a database object

Ques.11. Explain DML commands. What are the different DML commands in SQL?
Ans. DML refers to Data Manipulation Language, it is used for managing data present in the database. Some of the DML commands are-select, insert, update, delete, etc.

Ques.12. Explain DCL commands. What are the different DCL commands in SQL?
Ans. DCL refers to Data Control Language, these commands are used to create roles, grant permission and control access to the database objects. The three DCL commands are-

  • GRANT – Grants permission to a database user
  • REVOKE – Removes access privileges from a user-provided with the GRANT command
  • Deny – Explicitly prevents a user from receiving particular permission(e.g. preventing a particular user belonging to a group to receive the access controls

Ques.13. Explain TCL commands. What are the different TCL commands in SQL?
Ans. TCL refers to Transaction Control Language, it is used to manage the changes made by DML statements. These are used to process a group of SQL statements comprising a logical unit. The three TCL commands are-

  • COMMIT – Commit write the changes to the database
  • SAVEPOINT – Savepoints are the breakpoints, these divide the transaction into smaller logical units which could be further roll-backed.
  • ROLLBACK – Rollbacks are used to restore the database since the last commit.

Ques.14. What are SQL constraints?
Ans. SQL constraints are the set of rules that impose some restriction while insertion, deletion or update of data in the databases. In SQL we have both column level as well as table level constraints which are applied at columns and tables respectively. Some of the constraints in SQL are – Primary Key, Foreign Key, Unique Key, Not NULL, DEFAULT, CHECK and Index constraint.

Ques.15. What is a Unique constraint?
Ans. A unique constraint is used to ensure that the field/column will have only a unique value(no duplication).

Ques.16. What is a Primary Key?
Ans. A primary key is a column or a combination of columns that uniquely identifies a record in the database. A primary key can only have unique and not NULL values and there can be only one primary key in a table.

Ques.17. What is the difference between unique key and primary key?
Ans. A unique key allows null value(although only one) but a primary key doesn’t allow null values. A table can have more than one unique keys columns while there can be only one primary key. A unique key column creates a non-clustered index whereas the primary key creates a clustered index on the column.

Ques.18. What is a composite key?
Ans. A composite key is a primary key with multiple columns as in case of some tables a single field might not guarantee unique and not null values, so a combination of multiple fields is taken as primary key.

Ques.19. What is a NULL value?
Ans. A NULL value in SQL is an unknown or blank value. Since NULL is unknown value so, NULL value cannot be compared with another NULL value. Hence we cannot use ‘=’ operator in where condition with NULL. For this, we have IS NULL clause that checks if the value in the field is NULL or not.

Ques.20. What is a Not Null constraint?
Ans. A Not NULL constraint is used for ensuring that the value in the field cannot be NULL.

Ques.21. What is a Foreign Key?
Ans. A foreign key is used for enforcing referential integrity in which a field marked as a foreign key in one table is linked with a primary key of another table. With this referential integrity, we can have only the data in foreign key which matches the data in the primary key of the other table.

Ques.22. What is a Check constraint?
Ans. A check constraint is used to limit the value entered in a field. E.g. we can ensure that field ‘Salary’ can only have a value greater than 1000 using check constraint-


Ques.23. What is a Default constraint?
Ans. A Default constraint is used for providing a default value to a column when no value is supplied at the time of insertion of record in the database.

Ques.24. What is a clustered index?
Ans. Clustered indexes physically sort the rows in the table based on the clustering key(by default primary key). The clustered index helps in the fast retrieval of data from the databases. There can be only one clustered index in a table.

Ques.25. What is a non-clustered index?
Ans. Non clustered indexes have a jump table containing key-values pointing to a row in the table corresponding to the keys. There can be multiple clustered indexes in a table.

Continue with the remaining SQL Interview Questions – [Ques.25 – Ques.50]

2 thoughts on “SQL Interview Questions”

Leave a Comment