<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Parameter Sniffing &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/parameter-sniffing/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sun, 17 Dec 2017 20:25:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>SQL Server 2016: Introduced Database Scoped Configuration Options</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 04 Jan 2018 16:16:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[cardinality]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database plan]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Genetic Query Optimizer]]></category>
		<category><![CDATA[MAXDOP]]></category>
		<category><![CDATA[Parameter Sniffing]]></category>
		<category><![CDATA[scoped configuration]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4186</guid>

					<description><![CDATA[<div><img width="679" height="450" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope-679x450.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQLScope" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope-679x450.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope.jpg 800w" sizes="(max-width: 679px) 100vw, 679px" /></div>SQL Server 2016 introduced Database Scoped Configuration Options that can set at the database level, which was previously available at the instance level only. In SSMS, you can right click on database -> go to -> option -> find Database Scoped Configuration section. It introduced main four parameters, which we can set at the database [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="450" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope-679x450.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQLScope" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope-679x450.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQLScope.jpg 800w" sizes="(max-width: 679px) 100vw, 679px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&amp;linkname=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer%2F&#038;title=SQL%20Server%202016%3A%20Introduced%20Database%20Scoped%20Configuration%20Options" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-2016-introduced-database-scoped-configuration-options-maxdop-parameter-sniffing-optimizer/" data-a2a-title="SQL Server 2016: Introduced Database Scoped Configuration Options"></a></p><p>SQL Server 2016 introduced Database Scoped Configuration Options that can set at the database level, which was previously available at the instance level only.</p>
<blockquote><p>In SSMS, you can right click on database -> go to -> option -> find Database Scoped Configuration section.<br />
It introduced main four parameters, which we can set at the database level. </p></blockquote>
<p><strong>Legacy Cardinality Estimation:</strong> It enables you to configure the query optimizer cardinality estimation model.</p>
<p><strong>MAXDOP:</strong> Maximum degree of parallelism for an individual database.</p>
<p><strong>Parameter Sniffing:</strong> Previously, we can disable this feature using trace flag 4136, but now you can ON/OFF Parameter Sniffing at the database level. </p>
<p><strong>Query Optimizer Fixes: </strong> You can enable or disable query optimization hotfixes.</p>
<p><strong>Clear Database Plan:</strong> It allows clearing procedure cache at the database level without impacting other databases.</p>
<p>SQL Server 2016 also introduced one DMV to check the current value of Database Scoped Configurations.</p>
<pre class="crayon-plain-tag">SELECT *FROM sys.database_scoped_configurations</pre> </p>
<p>Database user requires Scoped Configuration permission to execute ALTER SCOPED CONFIGURATION.</p>
<pre class="crayon-plain-tag">GRANT ALTER ANY DATABASE SCOPED CONFIGURATION to UserName;</pre> </p>
<p><strong>Related T-SQL Scripts:</strong></p>
<p><strong>Clear atabase Plan Cache:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;</pre><p> </p>
<p><strong>Enable Legacy Cardinality Estimation:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = ON;</pre><p> </p>
<p><strong>Set MAXDOP Value:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 3;</pre><p> </p>
<p><strong>Disable Parameter Sniffing:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;</pre><p> </p>
<p><strong>Enable Query Optimizer Fixes:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = ON;</pre><p> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Use sp_recompile to recompile the stored procedures, triggers, and user-defined functions</title>
		<link>https://www.dbrnd.com/2017/08/sql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 27 Aug 2017 16:16:02 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Parameter Sniffing]]></category>
		<category><![CDATA[sp_recompile]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5986</guid>

					<description><![CDATA[The Parameter Sniffing in SQL Server is a prevalent problem where the previous query execution plan resides in the cache area, and Query Optimizer is not generating new query execution plan for each execution. At first glance, it looks OK because cache always results faster than frequent recompilation, but if data is rapidly changing, new [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions%2F&#038;title=SQL%20Server%3A%20Use%20sp_recompile%20to%20recompile%20the%20stored%20procedures%2C%20triggers%2C%20and%20user-defined%20functions" data-a2a-url="https://www.dbrnd.com/2017/08/sql-server-use-sp_recompile-to-recompile-the-stored-procedures-triggers-and-user-defined-functions/" data-a2a-title="SQL Server: Use sp_recompile to recompile the stored procedures, triggers, and user-defined functions"></a></p><p>The Parameter Sniffing in SQL Server is a prevalent problem where the previous query execution plan resides in the cache area, and Query Optimizer is not generating new query execution plan for each execution.</p>
<p>At first glance, it looks OK because cache always results faster than frequent recompilation, but if data is rapidly changing, new Query Execution plan is needed.</p>
<p><em>You can read more about SQL Server Parameter Sniffing in the check below article:</em></p>
<blockquote class="wp-embedded-content" data-secret="eBHwNgvMlL"><p><a href="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/">SQL Server Parameter Sniffing</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/embed/#?secret=eBHwNgvMlL" data-secret="eBHwNgvMlL" width="600" height="338" title="&#8220;SQL Server Parameter Sniffing&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>Now about the sp_recompile, using this you can explicitly recompile stored procedures, triggers, and user-defined functions. Once you recompile these objects using sp_recompile, will be recompiled the next time that it is run.</p>
<p>If you recompile object like table or view, all the stored procedures, triggers, or user-defined functions that reference the table or view will be recompiled the next time that they are run.</p></blockquote>
<p><strong>Sample:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_recompile N'[dbo].[my_table]'
GO</pre> </p>
<p><strong>Return Message:</strong></p>
<pre class="crayon-plain-tag">Object '[dbo].[my_table]' was successfully marked for recompilation.</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-10)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 21 Jun 2016 19:51:08 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[char]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[NVARCHAR]]></category>
		<category><![CDATA[Parameter Sniffing]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[raiseerror]]></category>
		<category><![CDATA[smallint]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[sql_variant]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[throw]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[VARCHAR]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3063</guid>

					<description><![CDATA[What is the difference between Varchar and NVarchar data type? varchar: Variable-length, non-Unicode character data. The database collation determines which code page the data is stored using. nvarchar: Variable-length Unicode character data. Dependent on the database collation for comparisons. Essentially, NVARCHAR is nothing more than a VARCHAR that supports two-byte characters. The most common use [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10%2F&#038;title=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-10%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-msdtc-parameter-sniffing-sql_variant-throw-raiseerror-day-10/" data-a2a-title="SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-10)"></a></p><p><strong>What is the difference between Varchar and NVarchar data type?</strong></p>
<blockquote><p>varchar: Variable-length, non-Unicode character data. The database collation determines which code page the data is stored using.</p>
<p>nvarchar: Variable-length Unicode character data. Dependent on the database collation for comparisons.</p>
<p>Essentially, NVARCHAR is nothing more than a VARCHAR that supports two-byte characters. The most common use for this sort of thing is to store character data that is a mixture of English and non-English symbols.</p>
<p>The key difference between the two data types is how they&#8217;re stored.</p></blockquote>
<p><strong>What is the difference between Varchar(max) and TEXT data type?</strong></p>
<blockquote><p>The VARCHAR(MAX) type is a replacement for TEXT. The basic difference is that a TEXT type will always store the data in a blob whereas the VARCHAR(MAX) type will attempt to store the data directly in the row unless it exceeds the 8k limitation and at that point it stores it in a blob.</p>
<p>The legacy types (TEXT, NTEXT, IMAGE) are deprecated and support for them will be dropped in a future version of SQL Server.</p></blockquote>
<p><strong>What is the difference between CHAR and VARCHAR?</strong></p>
<blockquote><p>CHAR Data Type is a Fixed Length Data Type. For example if you declare a variable/column of CHAR (10) data type, then it will always take 10 bytes irrespective of whether you are storing 1 character or 10 character in this variable or column.</p>
<p>On the other hand VARCHAR is a variable length Data Type. For example if you declare a variable/column of VARCHAR (10) data type, it will take the no. of bytes equal to the number of characters stored in this column. So, in this variable/column if you are storing only one character then it will take only one byte and if we are storing 10 characters then it will take 10 bytes.</p></blockquote>
<p><strong>What is the difference between Datetime and Datetime2?</strong></p>
<p>DateTime2 is the new Data Type introduced in SQL Server 2008 for storing Date and Time value. Microsoft Suggests to use this new Data Type instead of DateTime that is mainly available for backwards compatibility.</p>
<p><strong>Min and Max values:</strong></p>
<ul>
<li>DateTime: BETWEEN ‘1753-01-01 00:00:00’ AND ‘’9999-12-31 23:59:59.997’</li>
<li>DateTime2: BETWEEN ‘0001-01-01 00:00:00’ AND ‘9999-12-31 23:59:59.9999999’</li>
</ul>
<p><strong>Storage Size:</strong></p>
<ul>
<li>DateTime: 8 Bytes</li>
<li>DateTime2(n): 6 to 8 bytes</li>
</ul>
<p><strong>Precision:</strong></p>
<ul>
<li>DateTime – only allows for precision up to every 3rd milisecond which essentially means that you can get rounding issues for times that are in fact different. The rounding is to increments of .000, .003, or .007 seconds.</li>
<li>DateTime2(n) – The precision scale is 0 to 7 digits, with an accuracy of 100 nanoseconds . The default precision is 7 digits.</li>
</ul>
<p><strong>What is the difference between HAVING and WHERE Clause?</strong></p>
<ul>
<li>HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.</li>
<li>HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.</li>
<li>A query can contain both a WHERE clause and a HAVING clause. The WHERE clause is applied first to the individual rows in the tables . Only the rows that meet the conditions in the WHERE clause are grouped. The HAVING clause, then applied to the rows in the result set. Only the groups that meet the HAVING conditions appear in the query output.</li>
</ul>
<p><strong>What is the difference Between GETDATE and SYSDATETIME?</strong></p>
<p>In case of GETDATE the precision is till miliseconds and in case of SYSDATETIME the precision is till nanoseconds.</p>
<p>&nbsp;</p>
<p><strong>What is the difference between THROW and RAISERROR?</strong></p>
<blockquote><p>When using RAISERROR function, it just returns the last (single) error message and its details, but the previous error message details are not returned by this function.</p>
<p>With the new THROW clause you won’t see any issue of omitting the previous errors. And it returns all error details as thrown by the SQL statement itself.</p></blockquote>
<p><strong>What is bit data type?</strong></p>
<blockquote><p>Bit datatype is used to store boolean information like 1 or 0 (true or false).</p>
<p>Bit datatype can represent a Null state.</p></blockquote>
<p><strong>What is the difference between SMALLINT and TINYINT?</strong></p>
<blockquote><p>The storage of TinyINT is 1 byte and can store range from 0 to 255.</p>
<p>The storage of SmallINT is 2 bytes and can store range from -32768 to 32767.</p></blockquote>
<p><strong>What is the Difference Between Cast and Convert?</strong></p>
<ul>
<li>CAST and CONVERT are both used to convert data from one data type to another.</li>
<li>CAST is part of the ANSI-SQL specification; whereas, CONVERT is not.  In fact, CONVERT is SQL implementation specific.</li>
<li>CONVERT differences lie in that it accepts an optional style parameter which is used for formatting.</li>
<li>For example, when converting a DateTime datatype to Varchar, you can specify the resulting date’s format, such as YYYY/MM/DD or MM/DD/YYYY.</li>
<li>SELECT CONVERT(VARCHAR,GETDATE(),101) as MMDDYYYY, CONVERT(VARCHAR,GETDATE(),111) as YYYYMMDD</li>
</ul>
<p>&nbsp;</p>
<p><strong>Have you ever stored XML type of data into SQL Server?</strong></p>
<blockquote><p>Yes: Using XML Data type, we can store XML formatted data into SQL Server.</p>
<p>XML is a good choice if you want a platform-independent model in order to ensure portability of the data by using structural and semantic markup.</p></blockquote>
<p><strong>What is MSDTC?</strong></p>
<blockquote><p>The Microsoft Distributed Transaction Coordinator is a transaction manager that allows client applications to include several different sources of data in one transaction.</p>
<p>MSDTC coordinates committing the distributed transaction across all the servers enlisted in the transaction.</p></blockquote>
<p><strong>What is Distributed Queries in SQL Server?</strong></p>
<blockquote><p>Distributed query access data from multiple heterogeneous data sources. These data sources can be stored on either the same or different computers. It supports distributed queries by using OLEDB.</p></blockquote>
<p><strong>What is a Two-Phase Commit?</strong></p>
<blockquote><p>In transaction processing, databases, and computer networking, the two-phase commit protocol (2PC) is a type of atomic commitment protocol (ACP). It is a distributed algorithm that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (roll back) the transaction.</p>
<p>Two Phase commit is used in distributed data base systems. This is useful to maintain the integrity of the database so that all the users see the same values. It contains DML statements or Remote Procedural calls that reference a remote object. There are basically 2 phases in a 2 phase commit.</p></blockquote>
<blockquote><p>Prepare Phase : Global coordinator asks participants to prepare</p>
<p>Commit Phase : Commit all participants to coordinator to Prepared, Read only or abort Reply.</p></blockquote>
<p><strong>What do you know about the SQL Server parameter sniffing?</strong></p>
<blockquote class="wp-embedded-content" data-secret="L45xWCklUM"><p><a href="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/">SQL Server Parameter Sniffing</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/embed/#?secret=L45xWCklUM" data-secret="L45xWCklUM" width="600" height="338" title="&#8220;SQL Server Parameter Sniffing&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>How do we recompile a stored procedure at run time?</strong></p>
<blockquote><p>Using WITH RECOMPILE hint option, we can recompile stored procedure at run time.</p></blockquote>
<p><strong>What is a SQL_VARIANT?</strong></p>
<ul>
<li>It is a data type that stores values of various SQL Server-supported data types.</li>
<li>sql_variant can be used in columns, parameters, variables, and the return values of user-defined functions. sql_variant enables these database objects to support values of other data types.</li>
<li>A column of type sql_variant may contain rows of different data types. For example, a column defined as sql_variant can store int, binary, and char values.</li>
<li>sql_variant can have a maximum length of 8016 bytes.</li>
</ul>
<p><strong>What kind of data types which are not supported by SQL_VARIANT?</strong></p>
<ul>
<li>varchar(max)</li>
<li>varbinary(max)</li>
<li>nvarchar(max)</li>
<li>xml</li>
<li>text</li>
<li>ntext</li>
<li>image</li>
<li>rowversion (timestamp)</li>
<li>sql_variant</li>
<li>geography</li>
<li>hierarchyid</li>
<li>geometry</li>
<li>User-defined types</li>
<li>datetimeoffset</li>
</ul>
<p><strong>Would you please explain the logic to split a comma separated values?</strong></p>
<blockquote class="wp-embedded-content" data-secret="x028VWWRz4"><p><a href="https://www.dbrnd.com/2015/12/sql-serverfunction-to-split-string-value-using-different-delimiters/">SQL Server:Function to Split String Value Using Different Delimiters</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/12/sql-serverfunction-to-split-string-value-using-different-delimiters/embed/#?secret=x028VWWRz4" data-secret="x028VWWRz4" width="600" height="338" title="&#8220;SQL Server:Function to Split String Value Using Different Delimiters&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server Parameter Sniffing</title>
		<link>https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/</link>
					<comments>https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 31 May 2015 16:49:49 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[OPTION FOR Hint]]></category>
		<category><![CDATA[OPTION Recompile]]></category>
		<category><![CDATA[Parameter Sniffing]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=215</guid>

					<description><![CDATA[In this post, I am sharing about the Parameter Sniffing of SQL Server. I will discuss, why the query optimizer sometimes fails to choose a proper query plan. One day I experienced that one of my production stored procedure was not returning expected performance, and before two days, same stored procedure was running fine. At that time, I didn&#8217;t know [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&amp;linkname=SQL%20Server%20Parameter%20Sniffing" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fsql-server-parameter-sniffing%2F&#038;title=SQL%20Server%20Parameter%20Sniffing" data-a2a-url="https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/" data-a2a-title="SQL Server Parameter Sniffing"></a></p><div>
<div>
<p>In this post, I am sharing about the Parameter Sniffing of SQL Server. I will discuss, why the query optimizer sometimes fails to choose a proper query plan.</p>
</div>
<div>
<p>One day I experienced that one of my production stored procedure was not returning expected performance, and before two days, same stored procedure was running fine.</p>
</div>
<div>
<p>At that time, I didn&#8217;t know about the Parameter Sniffing and started to look into this problem.</p>
</div>
<div>
<p>I found that before two days there were total 25000 records and later there were total 10,00,00 records.</p>
</div>
<div>
<p>I concluded that records increased quickly, but not increased ten times, and it increased just three times, and even I had already tested this stored procedure for 10,00,00,00 records.</p>
</div>
</div>
<div></div>
<div>
<p><b>Now time to know about the Parameter Sniffing:</b></p>
</div>
<div></div>
<div>
<blockquote><p>Many times query optimizer chooses old query plan for execution because it stores this plan into the cache for frequently running queries.</p></blockquote>
</div>
<blockquote>
<div>
<p>Now, what happened when old query generated table scan for the first set of records and later the same parameter is required to change for index scanning because records increased.</p>
</div>
<div>
<p>I check the query execution plan and found that in my situation query optimizer use old query plan instead of to create a new query plan.</p>
</div>
</blockquote>
<div>
<blockquote><p>The query optimizer was using an old query plan from the query cache.</p></blockquote>
</div>
<div></div>
<div>
<div>
<p><b>Now, this is known as a Parameter Sniffing issue. </b></p>
</div>
<div>
<p>For you guys, this is very important to know why this is happening.</p>
</div>
<div>
<p>The Query optimizer does not always choose the old query plan, but many times due to traffic or load, query optimizer chooses a plan from the query cache.</p>
</div>
<div>
<p>As a DBA, you should monitor all indexes and its usages to identify this kind of problem.</p>
</div>
<p><b>SQL Server Solution for Parameter Sniffing :</b></p>
</div>
<div></div>
<div>
<p><strong>Three options for this solution:</strong></p>
</div>
<ul>
<li>OPTION 1: RECOMPILING</li>
<li>OPTION 2: OPTIMIZE FOR VALUE</li>
<li>OPTION 3: OPTIMIZE FOR UNKNOWN</li>
<li></li>
</ul>
<div>
<p><b>OPTION 1 : RECOMPILING</b></p>
<p>RECOMPILING,  means forcing SQL Server to recompile stored procedure or statement at every execution. You can set recompile hint on stored procedure or statement.</p>
<p>Sample code for Stored procedure and statements.</p>
</div>
<pre class="crayon-plain-tag">/*Stored Procedure with Recomplie option*/
CREATE PROCEDURE dbo.usp_gettestdata @testid INT
WITH RECOMPILE
AS

/*Select statement with Recomplie option*/
SELECT * FROM dbo.tbl_testdata
OPTION (RECOMPILE);</pre>
<div>
<p><b>OPTION 2 : OPTIMIZE FOR VALUE</b></p>
</div>
<div>
<p>As a DBA, you can find a particular set of values which require executing under the best execution plan so you can set OPTIMIZE for a hint for this value. But values and data rapidly change in the database system so this only for those values or data which are not changing frequently.</p>
<p>Sample statement with OPTIMIZE for Hint:</p><pre class="crayon-plain-tag">CREATE PROCEDURE dbo.usp_EmployeeData
 @EmpID INT
AS
SELECT EmployeName, EmployeeDOB, EmployeeClass
FROM dbo.tbl_EmployeeDetails
WHERE EmpID= @EmpID
OPTION (OPTIMIZE FOR (@EmpID=26));</pre><p>
</p></div>
<p><b>OPTION 3 : OPTIMIZE FOR VALUE</b></p>
<p>Basically, you can set UNKNOWN hint for the query optimizer to create a generic execution plan base on statistical data. This may be again generated parameter sniffing issue, but still, you can use this for infrequently running queries.<br />
<pre class="crayon-plain-tag">CREATE PROCEDURE dbo.usp_EmployeeData
 @EmpID INT
AS
SELECT EmployeName, EmployeeDOB, EmployeeClass
FROM dbo.tbl_EmployeeDetails
WHERE EmpID= @EmpID
OPTION (OPTIMIZE FOR UNKNOWN);</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/05/sql-server-parameter-sniffing/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
