Books MVC ASP.NET C# SQL Server WCF Written Test HR Round Subscribe SQL Tutorial C# Programs Buy DVD

SQL Server Interview Questions by topic

Basic SQL Server Interview Questions

What is the difference between Having and Where clause

SQL Server Interview Questions on Temporary Tables

SQL Server Interview Questions on Indexes - Part 1

SQL Server Interview Questions on Indexes - Part 2

What is the difference between a Temporary Table and a Table Variable

What is the use of COALESCE in SQL Server

SQL Server Interview Questions on triggers

Difference between User Defined Function and Stored Procedure

SQL Server Interview Questions on Views - Part 1

SQL Server Interview Questions on Views - Part 2

Basic SQL Server Interview Questions on Joins

Explain Inner Join with an example

Explain Left Outer Join with an example

Explain Right Outer Join with an example

Explain Full Outer Join with an example

Explain Self Join with an example

What is the difference between Index Scan and Index Seek

Write a SQL Query to delete from a table that is involved in a SQL join

What are the advantages of using stored procedures?

What are the different ways to replace NULL values in SQL Server?

SQL Server interview questions on string manipulation functions

Write a Stored Procedure that takes column name as a parameter and returns the result sorted by the column that is passed

What is deferred name resolution in SQL Server?


  1. Can u please add more questions on SQL Server 2008? Thanks

  2. Select * from tblA, tblB
    What is O/P.

    Ans: Cross product.
    It is a Cross Join.

    1. two tables data will be displayed

  3. what is the order of execution of where having and groupby clause

    1. The order is first, WHERE gets executed, followed by GROUP BY and then Having clause.
      WHERE - Filters the rows to be selected from the tables
      GROUP BY - Groups the filtered rows
      HAVING - Filters the Groups
      ORDER BY - Finally sorts the groups

  4. write a sql which will return nth(2nd highest salary) value from Employee table?

  5. nth highest salary from Emp table

    select * from Emp E1 where (n-1) =
    (select count(*) from Emp E2 where E1.salary <= E2.salary)

    please make a different link for all question i added as anonymous.
    Please correct my ans

    1. elect salary from Employees1 where salary<(SELECT MIN(salary) salary FROM ( select top n salary from Employees1 order by salary desc) AS A)

  6. Assume you have been asked to design the database structure for job site .what NORMALIZED table data model/table design would you recommended for storing the personal data of the candidate like name , address, and phone no. and their skill in multiple langauge so as to ensure that when a company searches based on a particular set of skill. the query is quick to return the result .
    Note that each candidate would have multiple skills

    Also write a query to retrive a list of all candidate along with their skill names

  7. A friend of mine was asked a question in an interview. Here is the question. What is coalesce in SQL and when do you use this function?

  8. Can u please explain what is ql tunning(database tunning)?

  9. Excuse me, how to convert a type FLOAT to INT in SQL Server, but this field that was updated, should be insert into the table where comes. How do it?
    For example: I got a field into the table XYZ of FLOAT type. I need convert this field with all his data to INT, but this registers should appear in the table XYZ. When I use: "select * from XYZ" show or print the new field with the all datas updated.

  10. show report header above the report parameters in report view using SSRS?
    Is it possible ? pls suggest.

  11. I have been asked a question, what are Concurrent Subqueries.


  12. What is difference between Is Null,IsNull,= Null,Null ,' '(Empty Statement) & When it’s use ?

  13. Find the second Max salary from max of salaries from a table having employee id and salary as columns

    1. select top 1 id,sal from
      (select top 2 id,sal from table_name order by sal) temp
      order by sal desc

    2. select top 1 sal from(select distinct top 2 sal from emp order by sal desc) a order by sal

  14. How to avoid deadlock

  15. Sir How to connect sql server database from C# programming form

  16. ---How to avoid Divide by zero error ?
    Create table tblcompute
    Numerator int not null,
    Denominator int not null,
    Result as (Numerator / Denominator)
    insert into tblcompute values (3,0)

    when we issue a select querry
    Select * from tblcompute
    Msg 8134, Level 16, State 1, Line 1
    Divide by zero error encountered.

    even after adding new row also getting the same error
    insert into tblcompute values (10,2)

    Finally i comeup with these querys!
    Select * from tblcompute where Result !=0
    SELECT Numerator , Denominator, NULLif(Result, 0) as Results from tblcompute
    SELECT Numerator , Denominator, NULLif(Result, null) as Results from tblcompute

    Can you plz make a video session for clear explanation how it works & also i wanted to show the null value results as null

  17. How to retrieve in between records from table without using where condition for eg in 100records would like to get 20-30 records it possible???

  18. Mouni, try group by with having. Where and having statement have different performance with queries. You might wanna check which is more effective

  19. sir join 2 tables employee and department and
    i want result insuch a way that


    1. Select DEPTNAME ,
      NAME Employeename, SAL from
      TBLEmp E
      inner join TBLDEPT D
      on E.DEPTID = D.DPTID
      Where E.Sal in (Select max(sal) From TBLemp Group by DEPTID)

  20. write a sql which will return nth(2nd highest salary) value from Employee table?

    select top 1 sal from(select distinct top 2 sal from emp order by sal desc) a order by sal

    Sandeep nath

  21. how to set identity column to random number generate.

  22. can u please explain mirroring concepts?

  23. Hi Venkat,

    When im trying to add new column in tblperson table its created with the null type.

    But when im creating the same using not null its shows in error. (Error mention below)

    Msg 4901, Level 16, State 1, Line 1
    ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'place' cannot be added to non-empty table 'tblperson' because it does not satisfy these conditions.

  24. hello sir,
    how can avoid errors during creating tables... how can i coded it..explain me sir

  25. Hello Sir,
    I have 2 tables T1(Id,Name) T2(Id,Name) I want to swap T1.Name to T2.Name and T2.Name to T1.Name Column values how to do it Please Answer me

  26. Hello Sir,

    Recently I attended a interview and I was asked, if a procedure is taking more time for executing what will you do and how will you do to reduce the execution time. Running each query is not an option because the procedure has more than 50 queries. Can you please tell me is there any tool or option in sql server which we can use for this.

    Thanks in advance.


If you are aware of any other sql server questions asked in an interview, please post them below. If you find anything missing or wrong, please feel free to correct by submitting the form below.

Disclaimer - Terms of use - Contact Us