SQL Interview Questions and Answers

Last updated on Feb 06, 2023
  • Share
SQL Interview Questions

SQL, or Structured Query Language, is a language that is used to interact or communicate with a database. This language assists in performing tasks like retrieval, insertion, updating, and deletion of data from databases. This information is commonly asked in SQL interview questions. An ANSI (American National Standards Institute) standard, SQL helps developers execute queries, insert records in tables, update records, create databases, create tables, or delete tables.

No doubt other programming languages such as ASP, PHP, and ColdFusion helped in making the Internet very dynamic, but SQL has revolutionized how users interact with websites in general. Any reputed webpage that allows the user to provide content uses SQL.

Most Frequently Asked SQL Interview Questions

Here in this article, we will be listing frequently asked SQL Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q21. Explain the difference between DROP and TRUNCATE commands in SQL?
Answer
TRUNCATE
  • It removes all rows from a table.
  • It does not require a WHERE clause.
  • Truncate cannot be used with indexed views.
  • It is performance wise faster.
DROP
  • It removes a table from the database.
  • All table's rows, indexes, and privileges will also be removed when we used this command.
  • The operation cannot be rolled back.

 

You can download here sql interview questions pdf after registeration or subscribe.

 

Q22. Write a query to find the names of users that begin with "um" in SQL?
Answer

SELECT * FROM employee WHERE name LIKE 'um%';

Q23. Explain CLAUSE in SQL?
Answer

It is the source of a rowset to be operated upon in a DML statement. These clauses are very common which is used with Select statement, Update statement and Delete statement.

SQL provides with the following clauses that are given below:

  • WHERE
  • GROUP BY
  • HAVING
  • ORDER BY etc
Q24. How to use distinct and count in SQL query? Explain
Answer

count(): It returns the number of rows in a table satisfying the condition specified in the WHERE clause. It would return 0 if there were no matching conditions.

Syntax:
SELECT COUNT(*) FROM category WHERE 'status' = 1;

distinct(): It is used to return only different values. In a table, a column often contains many duplicate values, and sometimes we want to list the different values. It can be used with aggregates functions.

Syntax:
SELECT DISTINCT class FROM College ORDER BY department

 

This information was frequently asked during SQL interview questions for testers.

Q25. What has stored procedures in SQL and how we can use it?
Answer

It is a set of precompiled SQL statements that are used to perform a particular task. A procedure has a name, a parameter list, and SQL statement, etc. It will help in reduce network traffic and increase the performance.

Example
CREATE PROCEDURE simple_function
AS
    SELECT first_name, last_name
    FROM employee;

EXEC simple_function;
Reviewed and verified by Baliram Prasad
Baliram Prasad

Baliram Prasad is a Technical Lead in Coldfusion. I am working closely with B2C and B2B Clients. I am having 13+ years of experience. I love programming and most of my time goes in learning the best w...