, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

SQL SERVER Interview Questions & Answers – SET 1 (50 Questions & Answers)

Download – Pawan Kumar Khowal – SQL SERVER Interview Questions with Answers

PAGE – 1


Question 1. What are statistics? Where they are used and how to check statistics.

SQL server optimizer uses the statistics to choose the best query plan. If the statistics are incorrect (means outdated), then there are chances that SQL server engine might choose an incorrect query plan. You can check statistics by using below command –

Table Name – TestRIDInxs
Index Name - 'Ix_Index

Output of the above query is given below-



Question 2. What are the types of Fragmentations

Answer –Pawan Kumar Khowal – SQL SERVER Interview Questions with Answers
Fragmentation means the data is NOT stored contiguously on disk. There are two types of Fragmentation. There are two  kinds of fragmentation-

  1. Logical fragmentation – Here the next logical page as determined by the index order is not the next physical page in the data file.
  2. Physical (or internal) fragmentation – Here the space is being wasted on index pages. The rows inside the page are not contiguous.

These can both affect query performance, as well as the expense of having to do the page split in the first place.

If you want to understand this in detail please visit – http://www.sqlskills.com/blogs/paul/category/fragmentation/


Question 3. Can we use GUID as Primary key in a table?

Answer – We can use GUID as primary key in a table But we should NOT. It will create fragmentation issue.

For details please visit – https://msbiskills.com/2015/04/09/guid-causes-fragmentation-in-clustered-indexes/


Question 4. What is the difference between Unique Index and Unique Constraint?

Answer –
A unique index is just an index, whereas a unique constraint is a unique index that’s listed as a constraint object in the database. In the sysobjects table, the unique constraint will have an xtype value of “UQ.”. Unique key basically creates a unique index internally to maintain uniqueness.

Note – Unique index and a unique constraint have same effect on a table. Performance is also same for both. Command to create unique index and unique constraint are given below.

--Command to add Index

--Command to add constraint

Now if you check the table definition (shortcut – ALT+F1) it will give you below information-



Question 5. What are RED Flags in SQL Server and what is there usage?

Answer – 
There are some flags in execution plan which normally reduces the performance of the query. Some of them are given below.

  1. High Percentage Operations
  2. Table Scans, Index Scans, Clustered Index Scans
  3. Spools
  4. Parallelism operations
  5. Warnings
  6. Thick Arrows
  7. Hash Joins
  8. Bookmark Lookups
  9. Sorting

For details please visit below-



Question 6. What are the types of physical joins in SQL Server? What are the different join operators in SQL Server?

Answer –
There are three types of physical joins given below-

Nested Loop

  • Used when one table is significantly small
  • The larger table has an index which allows seeking it using the join key

Merge Join

  • Both inputs are sorted on the join key
  • An equality operator is used
  • Excellent for very large tables

Hash Match

  • If the SQL Server can’t use any of the above mentioned joins then it will use Hash Match join.
  • Uses a hash table and a dynamic hash match function to match rows

For details please visit below links-
Nested Loop Joins: http://blogs.msdn.com/b/craigfr/archive/2006/07/19/671712.aspx Merge Joins: http://blogs.msdn.com/b/craigfr/archive/2006/08/03/merge-join.aspx
Hash Joins: http://blogs.msdn.com/b/craigfr/archive/2006/08/10/687630.aspx


Question 7. What is a Latch in SQL Server?

Latches perform the task of thread synchronization. For example, if a thread is reading a page from disk and creating a memory structure to contain it, it will create one or more Latches to prevent corruption of these structures. Once the operation is complete, the Latches will be released and other threads will be able to access that page and memory structure again. For the most part, latches are transient, taking a few milliseconds to complete.

A latch can be defined as an object that ensures data integrity on other objects in SQL Server memory, particularly pages. They are a logical construct that ensures controlled access to a resource and isolationism when required for pages in use. In contrast to locks, latches are an internal SQL Server mechanism that isn’t exposed outside the SQLOS. They come in many different types but can be split into roughly two classes – buffer latches, and non-buffer latches.

A latch is a lightweight synchronization object used by the Storage Engine to protect memory structures used internally by SQL Server. A latch is nothing more than a so-called Critical Section in multi-threaded programming – with some differences.


Question 8. Difference between Latch and Lock.

Latches are internal to the SQL Server engine. They are used to provide memory consistency. Locks are used by SQL Server to provide logical transactional consistency.

For details please visit –



Question 9. Could you please provide SQL 2014 New Features in DB Engine?

New features in SQL 2014 Db engine are given below –

  1. In-Memory OLTP (In-Memory Optimization)
  2. SQL Server Data Files in Windows Azure
  3. Host a SQL Server Database in a Windows Azure Virtual Machine
  4. Backup and Restore Enhancements

◾SQL Server Backup to URL
◾SQL Server Managed Backup to Windows Azure
◾Encryption for Backups

  1. New Design for Cardinality Estimation
  2. Delayed Durability
  3. Updateable Column Store Indexes
  4. Incremental Statistics & Partition Enhancement
  5. Buffer Pool Extension to Solid State Drives (SSDs).
  6. Managing Locks in Online Index
  7. Always On Improvements
  8. Resource Governor Enhancements

For details please refer – https://pawankkmr.wordpress.com/2015/04/08/sql-server-2014-new-features/

Question 10. In which scenarios we should not use CTE’s.

We should not use CTE’s for large tables. A CTE can be used:

  • For recursion
  • Substitute for a view when the general use of a view is not required; that is, you do not have to store the definition in metadata.

Reference the resulting non large table multiple times in the same statement.