Advanced SQL interview questions, Advanced SQL Queries, Advanced SQL tutorial, Advanced SQL tutorial pdf, Can we use GUID as Primary key in a table?, Could you please provide SQL 2014 New Features in DB Engine, Difference between Latch and Lock, difference between Unique Index and Unique Constraint?, Difficult SQL Interview Questions, Download SQL Interview Questions, Download SQL Questions, Download SQL Server Interview Question in PDF, Download SQL SERVER Interview questions, Download SQL Server Interview questions and answers, download sql server interview questions and answers pdf, download sql server interview questions by Pawan Khowal, download sql server interview questions by Pawan Kumar, download sql server interview questions by Pawan Kumar Khowal, Download T-SQL Interview Questions, Free Download SQL SERVER Interview questions, In which scenarios we should not use CTE's, Interview Qs.SQL SERVER Questions, Interview Questions on SQL, InterviewQuestions, InterviewQuestions for SQL, Joins Puzzle, Puzzles, Queries for SQL Interview, SQL, SQL 2012, SQL 2014, SQL 2014 Interview Questions, SQL Common Interview Questions, SQL Common Interview Questions and answers, SQL FAQ, SQL FAQs, SQL Interview Q & A, SQL Interview Questions, SQL Joins, SQL Queries, SQL Queries asked in interviews, SQL Questions, SQL Server, SQL Server - General Interview Questions and Answers, SQL Server developer Interview questions and answers, SQL Server developer Interview questions with answers, SQL SERVER Interview questions, SQL SERVER Interview questions & Answers, SQL Server Interview questions and answers, SQL Server Interview Questions and Answers - Free PDF, SQL SERVER Interview questions and answers for experienced, sql server interview questions and answers for net developers, SQL SERVER Interview questions for experienced, SQL SERVER Interview questions pdf, SQL SERVER Tips, SQL SERVER Tricky questions, SQL Skills, SQL Tips & Tricks, SQL Tips and Tricks, SQL Tricks, SQL Tricky question, SQL Tutorial, SQLSERVER, T-SQL, T-SQL Interview questions, T-SQL Programming, T-SQL Server Interview Questions, T-SQL Tutorial, TOP 100 SQL SERVER INTERVIEW QUESTIONS, Top 50 SQL Server Questions & Answers, Tough PL SQL Interview Questions, Tough SQL Interview Questions, Tough SQL Queries, Tough SQL Queries Interview Questions, Tough SQL Questions, Tricky SQL Interview Questions, Tricky SQL Interview Questions and answers, Tricky SQL Queries for Interview, Tricky SQL SERVER Interview Questions and answers, TSQL, TSQL Interview questions, TSQL Queries, types of physical joins in SQL Server, What are RED Flags in SQL Server and what is there usage?, What are statistics? Where they are used and how to check statistics, What are the types of Fragmentations, What is a Latch in SQL Server, What is the difference between Unique Index and Unique Constraint?
SQL SERVER Interview Questions & Answers – SET 1 (50 Questions & 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 –
DBCC SHOW_STATISTICS('TestRIDInxs','Ix_Index') 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-
- Logical fragmentation – Here the next logical page as determined by the index order is not the next physical page in the data file.
- 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?
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 CREATE UNIQUE INDEX Ix_Indexer ON TestRIDInxs(EId) --Command to add constraint ALTER TABLE TestRIDInxs ADD CONSTRAINT UNQ_Constraint UNIQUE (EId)
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?
There are some flags in execution plan which normally reduces the performance of the query. Some of them are given below.
- High Percentage Operations
- Table Scans, Index Scans, Clustered Index Scans
- Parallelism operations
- Thick Arrows
- Hash Joins
- Bookmark Lookups
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?
There are three types of physical joins given below-
- Used when one table is significantly small
- The larger table has an index which allows seeking it using the join key
- Both inputs are sorted on the join key
- An equality operator is used
- Excellent for very large tables
- 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 –
- In-Memory OLTP (In-Memory Optimization)
- SQL Server Data Files in Windows Azure
- Host a SQL Server Database in a Windows Azure Virtual Machine
- Backup and Restore Enhancements
◾SQL Server Backup to URL
◾SQL Server Managed Backup to Windows Azure
◾Encryption for Backups
- New Design for Cardinality Estimation
- Delayed Durability
- Updateable Column Store Indexes
- Incremental Statistics & Partition Enhancement
- Buffer Pool Extension to Solid State Drives (SSDs).
- Managing Locks in Online Index
- Always On Improvements
- 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.