SQL Queries Interview Questions and Answers – Crack an interview, interview questions and answers.#Interview


SQL Queries Interview Questions and Answers

Structured Query Language (SQL) is a standard computer language for relational database management and data manipulation. SQL is used to query, insert, update and modify data. This section contains some of the very important SQL Queries Interview Questions.

Interview questions and answers

SQL Interview Questions and Answers

Write SQL Query to display current date.

Ans: SQL has built in function called GetDate () which returns current timestamp.

Mention the difference between clustered and a non-clustered index?

  1. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index.
  2. A non clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Write an SQL Query to find names of employee start with ‘S’.

Ans: SELECT * FROM Employees WHERE EmpName like ‘S%’.

When do you use UPDATE_STATISTICS command?

Ans: This command is used when a large processing of data has occurred. If any large amount of deletions, any modifications, or Bulk Copy into the tables has occurred, it has to update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.

Interview Questions on SQL for Experienced : The sole purpose of these questions is elimination. Often you will find the questions are not loyal to any particular right answer but there is always scope for further improvement in your reply.

What type of Joins have you used?

Ans: The knowledge of Joins is a MUST for every interviewee. Most SQL programmers have used inner join and (left/right) outer join; but the catch point here is to also mention cross join and self-join.

How will you find the 3 rd max salary in the employment table?

Ans: Select distinct salary from employment e1 where 3= (select count (distinct salary) from employment e2 where e1.salary =e2.salary)

How would apply date range filter?

Ans: One can use simple conditions like = and =, or use between/and but the trick here is to know your exact data type.

  • Sometimes date fields contain time and that is where the query can go wrong so it is recommended to use some date related functions to remove the time issue. In SQL Server common function for accomplishing the task datediff () function.
  • Interviewees also have to be aware of different time zones and server time zone.
  • To increase query performance you may still want to use between however you should be aware of proper format you should use if not it might misbehave during filtering.

How will I retrieve all records of employment 1 those should not be present n employment 2?

Ans: (Select * from employment 2)-(Select * from employment 1).

SQL Server Interview Questions and Answers

Which TCP/IP port does SQL Server run on? How can it be changed?

Ans: SQL Server runs on port 1433. It can be changed from the Network Utility TCP/IP properties.

What is SQL Server Agent?

Ans: SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). Its purpose is to ease the implementation of tasks for the DBA, with its full- function scheduling engine, which allows you to schedule your own jobs and scripts.

Which command using Query Analyzer will give you the version of SQL server and operating system?

Ans: SELECT SERVERPROPERTY (‘productversion’), SERVERPROPERTY (‘productlevel’) and SERVERPROPERTY (‘edition’).

Define Trigger.

Ans: Trigger allows us to execute a batch of SQL code when an insert, update or delete command is executed against a specific table.

Triggers are special types of stored procedures that are defined to execute automatically in place of or after data modifications. They can be executed automatically on the insert, delete and update operation.

SQL Server Interview Questions and Answers for Experienced

Define a temp table.

Ans: In a nutshell, a temp table is a temporary storage structure. It means you can use a temp table to store data temporarily so you can manipulate and change it before it reaches its destination format.

In table_user.gender column change ‘male to female’ and ‘female to male’ in one SQL statement.

Ans: UPDATE table_user

WHEN ‘male’ THEN ‘female’

WHEN ‘female’ THEN ‘male’

How to create recursive query in SQL Server?

Ans: Recursive query can be create in SQL using stored procedure but you can also use CTE (Common table expression). It might be also worth asking about performance as CTE is not always very fast.

How will you find out 7th highest salary in a table?

Ans: SELECT * FROM

(SELECT ROW_NUMBER () OVER (ORDER BY sal_amount DESC) row_number, emp_id,

WHERE row_number = 7

HIGHLY RECOMMENDED IF YOU SERIOUSLY WANT TO JOIN A GOOD COMPANY: TO GET ALL THE QUESTIONS WITH ANSWERS, BUY ANY OF THESE BOOK FROM FLIPKART

В SQL Server Interview Questions Answers, Offer Price- Rs. 318 Interview questions and answers

В SQL Server Interview Questions You ll Most Likely be Asked , Offer Price- Rs. 1238В Interview questions and answers

More from my site

Share and Enjoy

  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers
  • Interview questions and answers

Leave a Reply

Your email address will not be published. Required fields are marked *