Frequently Asked SQL Interview Questions

SQL interview questions

SQL stands for Structured Query Language for managing the data in Database. 

Following is a list of SQL interview questions and answers, which can be asked during the interview.  

1. What is SQL?

SQL stands for Structured Query Language. It is used to communicates with the Database to retrieve, update insertion, and deletion of data from a database.

2. What is a Database?

The database is a collection of logical related data.

Example: School Management Database, Bank Management Database.

3. What is DBMS?

A Database Management System (DBMS) software designed to define, store, retrieve, and manage data in a database using SQL queries.

4. What is RDBMS?

RDBMS stands for Relational Database Management System. In RDBMS the data stored into the collection of tables and relations between tables are maintained.

5. What is a primary key?

The primary key is a key that uniquely identifies a single record in a relation/table. Primary Key cannot be NULL and all values are unique.

6. What is a unique key?

The unique key specified that all values in the column should be unique. But the difference between the primary and unique key is Unique key allows to contain NULL values.

8. What is a foreign key?

The relationship needs to be created between two tables by referencing a foreign key with the primary key of another table.

9. What is a join?

if you want to fetch multiple tables in a single query then Joins. I fetch data based on the join conditions.

10. What are the types of join and explain each?

Various types of join Are as bellow,

1)Inner Join.

Inner join returns only matched records between the tables based on the join condition.

2)Right Join.

Right join return rows which are common between the tables plus all records of the Right-hand side table. Simply, it returns all the rows from the right-hand side table even though there are no matches in the left-hand side table.

3)Left Join.

Left join return records which are common between the tables plus all rows of the Left-hand side table. Simply, it returns all the rows from the Left-hand side table even though there are no matches on the Right-hand side.

4)Full Join.

Full join combine the effect of both left join and right join. It returns all the matched and unmatched records.

11. What is Union?

Union and Union ALL are used to combine results from two or more select statements. The only difference between Union and Union ALL is Union removes duplicates.

12. What is Subquery or Nested Query?

A subquery is a query within a query. It is used in SELECT, FROM, WHERE, HAVING clauses.

13. Define Correlated Subquery?

The query in which the inner query depends on the outer query for its execution.

14. Define Independent Subquery?

The query in which the inner query does not depend on the outer query for its execution.

15. What is normalization?

Normalization is a process of reorganizing data in a database So that data redundancy or duplications are reduced.

16.What are different types of normal forms?

A.First Normal Form.

A relation R is in 1NF if and only if ,

1)Each attribute contains atomic values that is cannot split further. Eg- Ganesh Jondhalekar. Ganesh should present in Firstname and Jondhalekar should present in the LastName column.

2) No multivalued attributes. For Eg Two Mobile No should not contain in a single column.

B. Second Normal Form.

A relation R is in 2NF if and only if ,

1) Relation R is in 1NF.

2) No Partial dependency between non-key attributes and key attributes.

C. Third Normal Form.

A relation R is in 3NF if and only if ,

1) Relation R is in 2NF.

2) No Transitive dependency between key attributes and non-key attributes through another non-key attribute.

17.Why Database use Indexes?

It allows us to search data in tables quickly and efficiently.

18. What is a relationship and what are they?

The connection between the tables in a database called a Relationship. They are as follows,

1)One to One relationship.

2)One to Many relationship.

3)Many to Many relationship.

4)Self-Referencing relationship.

19. What is a Cursor?

A database Cursor is a control that enables traversal over the rows or records in the table. This can be viewed as a pointer to one row in a set of rows. 

20. What is a trigger?

A trigger is a code or program that automatically executes in response to some event on a table or view in a database.

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

DELETE command is used to remove rows from the table using where clauses. Commit and Rollback can be performed after deleting the statement.

TRUNCATE removes all rows from the table. The truncate operation cannot be rolled back.

22. What is a constraint?

Constraint can be used to specify the limit on the data type of table.

NOT NULL.

CHECK.

UNIQUE.

PRIMARY KEY.

FOREIGN KEY.

23. What is an ALIAS command?

ALIAS is a name given to a table or column. It is can be referred to in the WHERE clause to identify the table or column.

24. What is the difference between TRUNCATE and DROP statements?

The TRUNCATE command removes all the rows from the table, and it cannot be rolled back. DROP command removes a table from the database and cannot be rolled back.

Leave a Comment