<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Journey to SQL Authority with Pinal Dave &#187; SQL Index</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-index/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 01:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Journey to SQL Authority with Pinal Dave &#187; SQL Index</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<item>
		<title>SQL SERVER &#8211; Size of Index Table &#8211; A Puzzle to Find Index Size for Each Index on Table</title>
		<link>http://blog.sqlauthority.com/2009/11/18/sql-server-size-of-index-table-a-puzzle-to-find-index-size-for-each-index-on-table/</link>
		<comments>http://blog.sqlauthority.com/2009/11/18/sql-server-size-of-index-table-a-puzzle-to-find-index-size-for-each-index-on-table/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 01:30:16 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7388</guid>
		<description><![CDATA[It is very easy to find out some basic details of any table using the following Stored Procedure.
USE AdventureWorks
GO
EXEC sp_spaceused [HumanResources.Shift]
GO
Above query will return following resultset

The above SP provides basic details such as rows, data size in table, and Index size of all the indexes on the table.
If we look at this carefully, a total [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7388&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">It is very easy to find out some basic details of any table using the following Stored Procedure.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_spaceused </span><span style="color:black;">[HumanResources.Shift]<br />
GO</span></code></p>
<p style="text-align:justify;">Above query will return following resultset</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sp_spaceused1.jpg" alt="" width="369" height="153" /></p>
<p style="text-align:justify;">The above SP provides basic details such as rows, data size in table, and Index size of all the indexes on the table.</p>
<p style="text-align:justify;">If we look at this carefully, a total of three indexes can be found on the table HumanResources.Shift.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.indexes<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_ID </span><span style="color:blue;">= </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'HumanResources.Shift'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">The above query will give result with query listing all the index on the table.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/indexspace.jpg" alt="" width="500" height="248" /></p>
<p style="text-align:justify;">There is a small puzzle for all of you here. The puzzle is to write a query that will return the size for each index that is listed in above query. We need a query that will return an additional column in the above listed query and it should contain the size of the index. In our case, we will have three different sizes, which should add up to a total of 40 KB as shown in earlier query, where the total size is displayed.</p>
<p style="text-align:justify;">I will publish the solution with due credit on this blog.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Index, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7388/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7388/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7388/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7388/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7388/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7388/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7388/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7388/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7388/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7388/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7388&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/18/sql-server-size-of-index-table-a-puzzle-to-find-index-size-for-each-index-on-table/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/sp_spaceused1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/indexspace.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 2008 &#8211; Backup, Integrity Check and Index Optimization By Ola Hallengren</title>
		<link>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/</link>
		<comments>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:30:27 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[SQLAuthority Website Review]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7410</guid>
		<description><![CDATA[Script of Backup, Integrity Check and Index Optimization are the most important scripts for any developer. SQL Expert and true SQL enthusiast Ola Hallengren is known for his excellent scripts.
Please try it out and let me  know what you think. The documentation is available on http://ola.hallengren.com/Documentation.html and the script can be downloaded from http://ola.hallengren.com.
Here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7410&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Script of Backup, Integrity Check and Index Optimization are the most important scripts for any developer. SQL Expert and true SQL enthusiast Ola Hallengren is known for his excellent scripts.</p>
<p style="text-align:justify;">Please try it out and let me  know what you think. The documentation is available on <a href="http://ola.hallengren.com/Documentation.html" target="_blank">http://ola.hallengren.com/Documentation.html</a> and the script can be downloaded from <a href="http://ola.hallengren.com/" target="_blank">http://ola.hallengren.com</a>.</p>
<p style="text-align:justify;">Here is brief documentation sent by Ola himself for his script in his own words.</p>
<h2 style="text-align:justify;">Backup Maintenance</h2>
<p style="text-align:justify;">I  think that most of you have experienced the error messages &#8220;BACKUP  LOG cannot be performed because there is no current database backup.&#8221;  and &#8220;Cannot perform a differential backup for database &#8220;&#8221;,  because a current database backup does not exist.&#8221;.</p>
<p style="text-align:justify;">This usually happens when you  have created a new database or when you have changed recovery model  of a database from Simple to Full.</p>
<p style="text-align:justify;">The consequence is that the  database is not getting backed up, until a full backup (or a differential  backup for the BACKUP LOG error message if that can be done) has been  performed. It will also create some noise in your monitoring system.</p>
<p style="text-align:justify;">The solution is to check if  a differential or transaction log backup can be performed before doing  the backup. This can be done by checking sys.master_files.differential_base_lsn  and sys.database_recovery_status.last_log_backup_lsn.</p>
<p style="text-align:justify;">The backup solution that I  have developed has a parameter called @ChangeBackupType.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">EXECUTE </span><span style="color:black;">dbo.DatabaseBackup </span><span style="color:#434343;">@Databases </span><span style="color:blue;">= </span><span style="color:red;">'USER_DATABASES'</span><span style="color:gray;">, </span><span style="color:#434343;">@Directory </span><span style="color:blue;">= </span><span style="color:red;">'C:\Backup'</span><span style="color:gray;">, </span><span style="color:#434343;">@BackupType </span><span style="color:blue;">= </span><span style="color:red;">'LOG'</span><span style="color:gray;">, </span><span style="color:#434343;">@ChangeBackupType </span><span style="color:blue;">= </span><span style="color:red;">'Y'</span></code></p>
<p style="text-align:justify;">If it&#8217;s a new database in Full  recovery model, the backup type for that database and job run will be  changed to full. If it&#8217;s a database that was newly changed to Full recovery  model, then the backup type for that database and job run will be changed  to differential. The next time the job runs a transaction log backup  will be performed for that database.</p>
<p style="text-align:justify;">New databases start getting  backed up quickly and no more &#8220;BACKUP LOG cannot be performed because  there is no current database backup.&#8221; and &#8220;Cannot perform  a differential backup for database &#8220;&#8221;, because a current database  backup does not exist.&#8221;.</p>
<h2 style="text-align:justify;">Index Optimization</h2>
<p style="text-align:justify;">The design idea is categorize all indexes based on their fragmentation level (High, Medium or Low) and whether there are columns with LOB (Large Object) data types. For each category you can define an action. The possible actions are to rebuild indexes online or offline, reorganize indexes, update statistics, reorganize indexes and update statistics or to do nothing.</p>
<p style="text-align:justify;">Here’s an example.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">EXECUTE </span><span style="color:black;">dbo.IndexOptimize<br />
</span><span style="color:#434343;">@Databases </span><span style="color:blue;">= </span><span style="color:red;">'USER_DATABASES'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationHigh_LOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REBUILD_OFFLINE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationHigh_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REBUILD_ONLINE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationMedium_LOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REORGANIZE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationMedium_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REORGANIZE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLow_LOB </span><span style="color:blue;">= </span><span style="color:red;">'NOTHING'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLow_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'NOTHING'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLevel1 </span><span style="color:blue;">= </span><span style="color:black;">5</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLevel2 </span><span style="color:blue;">= </span><span style="color:black;">30</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@PageCountLevel </span><span style="color:blue;">= </span><span style="color:black;">1000<br />
</span></code></p>
<p style="text-align:justify;">Indexes with a fragmentation above 30% are to be rebuilt, online if possible (no LOB columns), otherwise offline (LOB columns). Indexes with a fragmentation between 5% and 30% are to be reorganized. Indexes with a fragmentation below 5% or a size below 1000 pages are not to be touched.</p>
<p style="text-align:justify;">If you are using partitioning IndexOptimize has a parameter, @PartitionLevel to do index rebuilds and reorganizations on the partition level. If you prefer to do sort operations in tempdb you can do that with the parameter @SortInTempdb and if you would like to set a fillfactor you can do that with the parameter @FillFactor.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;text-align:justify;"><span style="font-family:Times New Roman;font-size:small;">Please try it out and let me  know what you think. The documentation is available on <a href="http://ola.hallengren.com/Documentation.html" target="_blank">http://ola.hallengren.com/Documentation.html</a> and the script can be downloaded from <a href="http://ola.hallengren.com/" target="_blank">http://ola.hallengren.com</a>.</span></div>
Posted in Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQLAuthority News, SQLAuthority Website Review, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7410&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Disable CHECK Constraint &#8211; Enable CHECK Constraint</title>
		<link>http://blog.sqlauthority.com/2009/11/12/sql-server-disable-check-constraint-enable-check-constraint/</link>
		<comments>http://blog.sqlauthority.com/2009/11/12/sql-server-disable-check-constraint-enable-check-constraint/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 01:30:14 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7198</guid>
		<description><![CDATA[Foreign Key and Check Constraints are two types of constraints that can be disabled or enabled when required. This type of operation is needed when bulk loading operations are required or when there is no need to validate the constraint. The T-SQL Script that does the same is very simple.
USE AdventureWorks
GO
-- Disable the constraint
ALTER TABLE HumanResources.Employee
NOCHECK CONSTRAINT CK_Employee_BirthDate
GO
-- Enable the constraint
ALTER TABLE HumanResources.Employee
WITH CHECK CHECK CONSTRAINT CK_Employee_BirthDate
GO
It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7198&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Foreign Key and Check Constraints are two types of constraints that can be disabled or enabled when required. This type of operation is needed when bulk loading operations are required or when there is no need to validate the constraint. The T-SQL Script that does the same is very simple.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">-- Disable the constraint<br />
</span><span style="color:blue;">ALTER TABLE </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">NOCHECK CONSTRAINT </span><span style="color:black;">CK_Employee_BirthDate<br />
GO<br />
</span><span style="color:green;">-- Enable the constraint<br />
</span><span style="color:blue;">ALTER TABLE </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WITH CHECK CHECK CONSTRAINT </span><span style="color:black;">CK_Employee_BirthDate<br />
GO</span></code></p>
<p style="text-align:justify;">It is very interesting that when the constraint is enabled, the world CHECK is used twice – WITH CHECK CHECK CONSTRAINT. I often ask those to find the mistake in this script when they claim to know the syntax very well.</p>
<p style="text-align:justify;">Have you ever disabled and enabled constraints in your production environment? I would like to know why you did so.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/">http://blog.sqlauthority.com</a>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7198&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/12/sql-server-disable-check-constraint-enable-check-constraint/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Authority News &#8211; Training MS SQL Server 2005/2008 Query Optimization And Performance Tuning</title>
		<link>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/</link>
		<comments>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:30:30 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Training]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7357</guid>
		<description><![CDATA[This is very short note announcing details about my course details for &#8216;MS SQL Server 2005/2008 Query Optimization And Performance Tuning&#8216;.
The course is scheduled to be delivered from 19th Nov, 2009 and 21st Nov, 2009 in Pune, India.
This three day course is an intensive course designed to give attendees an in-depth look at the query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7357&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This is very short note announcing details about my course details for &#8216;<strong>MS SQL Server 2005/2008 Query Optimization And Performance Tuning</strong>&#8216;.</p>
<p style="text-align:justify;">The course is scheduled to be delivered from <strong><em>19th Nov, 2009 and 21st Nov, 2009</em></strong> in <em><strong>Pune, India</strong></em>.</p>
<p style="text-align:justify;">This three day course is an intensive course designed to give attendees an in-depth look at the query optimization and performance tuning concepts and methods found in SQL Server 2005/2008. This course is designed to prepare the SQL Server developers and administrators for a transition to SQL Server 2005/2008 while discussing best practices for a variety of topics.</p>
<p style="text-align:justify;"><strong>Day 1 : Strengthen the basics along with SQL Server 2005/2008 New Features</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 01: Subqueries, Ranking Functions, Joins and Set Operations<br />
Module 02: Table Expressions<br />
Module 03: TOP and APPLY<br />
Module 04: SQL Server 2008 Enhancements</p>
<p style="text-align:justify;"><strong>Day 2: Query Optimization &amp; Performance Tuning 1</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 05: Logical Query Processing<br />
Module 06: Query Tuning<br />
Module 07:  Introduction to the Query Processor<br />
Module 08:  Review of common query coding which causes poor performance</p>
<p style="text-align:justify;"><strong>Day 3: Query Optimization &amp; Performance Tuning 2</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 09:  SQL Server Indexing and index maintenance<br />
Module 10:  Plan Guides, query hints, UDFs, and Computed Columns<br />
Module 11:  Understanding SQL Server Execution Plans<br />
Module 12: Real World Index and Optimization Tips</p>
<p style="text-align:justify;">The space are limited and I encourage you to register as soon as possible.</p>
<p style="text-align:justify;"><strong>Call to register</strong> &#8211; +91 98817 95739, +91 98508 43664, +91 99229 33319</p>
<p style="text-align:justify;"><strong>Email to register</strong> &#8211; workshop &#8220;at&#8221; seedinfotech.com</p>
<p style="text-align:justify;">If due to any reason, you can not attend this course, please call or email on details above for future schedule for the course and location.</p>
<div class="wp-caption alignnone" style="width: 510px"><a href="http://www.pinaldave.com/bimg/MSQOPT.jpg"><img title="Click to Enlarge" src="http://www.pinaldave.com/bimg/MSQOPT.jpg" alt="" width="500" height="955" /></a><p class="wp-caption-text">Click to Enlarge</p></div>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL Training, SQLAuthority News, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7357/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7357&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/MSQOPT.jpg" medium="image">
			<media:title type="html">Click to Enlarge</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Removing Key Lookup &#8211; Seek Predicate &#8211; Predicate &#8211; An Interesting Observation Related to Datatypes</title>
		<link>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/</link>
		<comments>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 01:30:12 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7088</guid>
		<description><![CDATA[Recently, I have been working on Query Optimization project. While working on it, I found the following interesting observation. This entire concept may appear very simple, but if you are working in the area of query optimization and server tuning, you will find such useful hints.
Before we start, let us understand the difference between Seek [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7088&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Recently, I have been working on Query Optimization project. While working on it, I found the following interesting observation. This entire concept may appear very simple, but if you are working in the area of query optimization and server tuning, you will find such useful hints.</p>
<p style="text-align:justify;">Before we start, let us understand the difference between Seek Predicate and Predicate. Seek Predicate is the operation that describes the b-tree portion of the Seek. Predicate is the operation that describes the additional filter using non-key columns. Based on the description, it is very clear that Seek Predicate is better than Predicate as it searches indexes whereas in Predicate, the search is on non-key columns – which implies that the search is on the data in page files itself.</p>
<p style="text-align:justify;">Earlier, I had posted regarding how to remove key lookup and bookmark lookup in the following:</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
<p style="text-align:justify;">Let us see an example where we will remove the bookmark lookup first using the covering index. On removing the bookmark lookup, it resulted in Index Scan, which is not good for performance. When Index Scan is converted to Index Seek, it provides  a significant improvement in performance.</p>
<p style="text-align:justify;">Run following SELECT, which is based on the database AdventureWorks.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Enforces Key Lookup<br />
-- Try 1<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO</span></code></p>
<p style="text-align:justify;">Let us check the execution plan for the same. The execution plan consists of the key lookup because there are columns that we are trying to retrieve in SELECT as well in WHERE clause.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek1.jpg" alt="" width="500" height="217" /></p>
<p style="text-align:justify;">Let us create a covering index on this table HumanResources.Employee.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Non clustered Index<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">ASC</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">After creating above index, let us run the same SELECT statement again.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup, but it still enforces Index Scan<br />
-- Try 2<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO</span></code></p>
<p style="text-align:justify;">Due to non-clustered index, Key Lookup is removed along with Nested Loops but <em>Index Scan</em> still remains, and this is not good for performance.<span style="color:black;"> </span></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek2.jpg" alt="" width="500" height="131" /></p>
<p style="text-align:justify;">I tried to remove the scan, but my attempts were unsuccessful. I finally looked at the datatype of the NationalIDNumber. All this time, I was assuming that this datatype is INT, but on a careful check, I found that the datatype of NationalIDNumber is nvarchar(15).</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekdt.jpg" alt="" width="327" height="175" /></p>
<p style="text-align:justify;">In the SELECT statement, we were comparing the datatype of NVARCHAR to INT, and this was forcing the <strong>predicate </strong>operation while executing the query.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre.jpg" alt="" width="492" height="668" /></p>
<p style="text-align:justify;">As discussed earlier, due to predicate operation, there has to be explicit conversion on the side of NationalIDNumber, which forces the query optimizer to not use the index and instead it has to scan the complete data in table to get the necessary data. This is not the desired solution. Index Scan reduces performance. The reason for this conversion is because I am using INT value in WHERE clause instead of NVARCHAR.</p>
<p style="text-align:justify;">I changed my WHERE clause and passed STRING as the parameter instead of INT.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek<br />
-- Try 3<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">'14417807'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">After running the query with the changed WHERE clause, the Index Scan is now converted into Index Seek.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek3.jpg" alt="" width="500" height="145" /></p>
<p style="text-align:justify;">Index Seek is definitely the most optimal solution in this particular scenario.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre1.jpg" alt="" width="510" height="584" /></p>
<p style="text-align:justify;">When the detail execution plan was checked, I found the following two notable points. First, the predicate is converted to seek predicate, which is the reason for performance improvement, as described earlier. Instead of scanning data in the table, Index Seek is performed. Second, as the datatype of the NationalIDNumber is NVARCHAR and the parameters are passed as VARCHAR, the conversion happens on the parameters instead of NationalIDNumber column, and this forces Index Scan to Index Seek.</p>
<p style="text-align:justify;">If we pass the parameter as NVARCHAR instead of VARCHAR, the execution plan will remain the same, but CONVERT_IMPLICIT will not be required any more. Let us run the following query, which has NVARCHAR as the parameter.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek and no CONVERT_IMPLICIT<br />
-- Try 4<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">N'14417807'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">The execution plan of the above query is very similar to that in which we had passed the parameter as VARCHAR.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/klseek3.jpg" alt="" width="500" height="145" /></p>
<p style="text-align:justify;">Now let us check the execution plan for the same.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre2.jpg" alt="" width="502" height="675" /></p>
<p style="text-align:justify;">In the WHERE condition, the operators we have on both the sides of &#8220;=&#8221; are of NVARCHAR. NationalIDNumber and parameter passed – both are NVARCHAR, which has removed CONVERT_IMPLICIT. However, there are no changes in the execution plan.</p>
<p style="text-align:justify;"><strong>In summary, when Key Lookup is removed and index seek replaces index scan, the performance is tuned up. </strong>Let us quickly compare the execution plan of the above four options. I have included the complete code here for easy reference.</p>
<p><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Enforces Key Lookup<br />
-- Try 1<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO<br />
</span><span style="color:green;">-- Create Non clustered Index<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">ASC</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO<br />
</span><span style="color:green;">--WAITFOR DELAY '00:00:30'<br />
-- CTRL + M Removes Key Lookup, but it still enforces Index Scan<br />
-- Try 2<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek<br />
-- Try 3<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">'14417807'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek and no CONVERT_IMPLICIT<br />
-- Try 4<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">N'14417807'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* What is the reason for difference between Try 2 and Try 3?<br />
Check the exeuction plan<br />
*/<br />
-- Drop Index<br />
</span><span style="color:blue;">DROP INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee </span><span style="color:blue;">WITH </span><span style="color:gray;">( </span><span style="color:black;">ONLINE </span><span style="color:blue;">= OFF </span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Let us look at the execution plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek.jpg" alt="" width="500" height="521" /></p>
<p style="text-align:justify;">Summary points:</p>
<ul style="text-align:justify;">
<li>In      general, Index Seek is better than Index Scan (I am not talking about it      depends conditions)</li>
<li>Understand      Predicates and Seek Predicates and see if you have only Seek Predicates.</li>
<li>In      case of key lookup or bookmark lookup, see if you can create a covering      index or included column index.</li>
<li>Use      the datatype wisely even though there is no change in the resultset.</li>
</ul>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7088/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7088&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/klseek1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekdt.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; How to Enable Index &#8211; How to Disable Index &#8211; Incorrect syntax near &#8216;ENABLE&#8217;</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/</link>
		<comments>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 01:30:36 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121</guid>
		<description><![CDATA[Many times I have seen that the index is disabled when there is large update operation on the table. Bulk insert of very large file updates in any table using SSIS is usually preceded by disabling the index and followed by enabling the index. I have seen many developers running the following query to disable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7121&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Many times I have seen that the index is disabled when there is large update operation on the table. Bulk insert of very large file updates in any table using SSIS is usually preceded by disabling the index and followed by enabling the index. I have seen many developers running the following query to disable the index.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">----Diable Index<br />
</span><span style="color:blue;">ALTER INDEX </span><span style="color:black;">[IX_StoreContact_ContactTypeID] </span><span style="color:blue;">ON </span><span style="color:black;">Sales.StoreContact DISABLE<br />
GO</span></code></p>
<p style="text-align:justify;">While enabling the same index, I have seen developers using the following INCORRECT syntax, which results in error.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">----INCORRECT Syntax Index<br />
</span><span style="color:blue;">ALTER INDEX </span><span style="color:black;">[IX_StoreContact_ContactTypeID] </span><span style="color:blue;">ON </span><span style="color:black;">Sales.StoreContact <span style="color:#ff0000;">ENABLE</span><br />
GO</span></code></p>
<p style="text-align:left;"><span style="color:#ff0000;">Msg 102, Level 15, State 1, Line 1<br />
Incorrect syntax near &#8216;ENABLE&#8217;.</span></p>
<p style="text-align:justify;">This is because once the index is disabled, it cannot be enabled, but it must be rebuilt. The following syntax will enable and rebuild the index with optimal performance.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO</span><span style="color:black;"><br />
</span><span style="color:green;">----Enable Index<br />
</span><span style="color:blue;">ALTER INDEX </span><span style="color:black;">[IX_StoreContact_ContactTypeID] </span><span style="color:blue;">ON </span><span style="color:black;">Sales.StoreContact REBUILD<br />
GO</span></code></p>
<p style="text-align:justify;">I hope that now you have understood why enabling this syntax in the index throws an error and also how to enable an index with optimal performance.</p>
<p style="text-align:justify;">If you want to read just the syntax, I have written a similar article earlier <a href="http://blog.sqlauthority.com/2007/05/17/sql-server-disable-index-enable-index-alter-index/" target="_blank"><strong>SQL SERVER – Disable Index – Enable Index – ALTER Index</strong></a>.</p>
<p style="text-align:justify;">
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7121&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Comic Slow Query &#8211; SQL Joke</title>
		<link>http://blog.sqlauthority.com/2009/10/13/sql-server-comic-slow-query-sql-joke/</link>
		<comments>http://blog.sqlauthority.com/2009/10/13/sql-server-comic-slow-query-sql-joke/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 01:30:35 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Humor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority Author Visit]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7050</guid>
		<description><![CDATA[Community TechDays at Ahmedabad was a great successful event. In fact, this can be considered the biggest event held in Ahmedabad thus far along with the community. I have posted a detail report of the same at SQLAuthority News – Community TechDays in Ahmedabad – A Successful Event. After the event, I received many emails [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7050&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Community TechDays at Ahmedabad was a great successful event. In fact, this can be considered the biggest event held in Ahmedabad thus far along with the community. I have posted a detail report of the same at <a href="http://blog.sqlauthority.com/2009/10/05/sqlauthority-news-community-techdays-in-ahmedabad-a-successful-event/" target="_blank"><strong>SQLAuthority News – Community TechDays in Ahmedabad – A Successful Event</strong></a>. After the event, I received many emails requesting the comic strip I had shown in my presentation.</p>
<p style="text-align:justify;">I had presented two different comic strips: one before the presentation and the other after the presentation. Both the comic strips are shown here; if you click on the images, you can see the larger version. Let me know what you think of them. If you are interested in the whole session of &#8220;The other side of Index,&#8221; let me know so that I can present the same at your UG event as well.</p>
<h3 style="text-align:justify;">Before Presentation</h3>
<p style="text-align:justify;">Click on the image to see the enlarged version</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/slowquery.jpg"><img class="alignnone" src="http://www.pinaldave.com/bimg/slowquery.jpg" alt="" width="500" height="198" /></a></p>
<h3 style="text-align:justify;">After Presentation</h3>
<p style="text-align:justify;">Click on the image to see the enlarged version</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/slowquery1.jpg"><img class="alignnone" src="http://www.pinaldave.com/bimg/slowquery1.jpg" alt="" width="500" height="198" /></a></p>
<p style="text-align:justify;">Let me know what you think about these.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Humor, SQL Index, SQL Query, SQL Server, SQL Tips and Tricks, SQLAuthority Author Visit, SQLAuthority News, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7050/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7050/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7050/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7050/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7050/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7050/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7050/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7050/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7050/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7050/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7050&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/13/sql-server-comic-slow-query-sql-joke/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/slowquery.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/slowquery1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup &#8211; Part 3</title>
		<link>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/</link>
		<comments>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 01:30:16 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7057</guid>
		<description><![CDATA[Earlier I have written two different articles on the subject Remove Bookmark Lookup. This article is as part 3 of original article. Please read first two articles here before continuing reading this article.
SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup
SQL SERVER – Query Optimization – Remove [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7057&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Earlier I have written two different articles on the subject Remove Bookmark Lookup. This article is as part 3 of original article. Please read first two articles here before continuing reading this article.</p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></strong></p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></strong></p>
<p style="text-align:justify;">We read in above articles that we can remove bookmark lookup using covering index. Covering Index is the index, which contains all the columns used in SELECT as well in JOINs and WHERE conditions. In our example we have created clustered index first.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Clustered Index<br />
</span><span style="color:blue;">CREATE CLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_ID] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[ID] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Based on clustered index we have created following non clustered index. Please note that we do not have to create both the index together. We can create either covering index or included column index along with it. Please note, I am suggesting to create either of it, not both of it.</p>
<p style="text-align:justify;">In earlier article I have suggested to include all columns but in reality in any non clustered index there is no need to include columns included in clustered index. All non clusteredindex automatically contains pointers to clustered index any way.</p>
<p style="text-align:justify;">We should create index described in earlier article as following.</p>
<p style="text-align:justify;"><strong>Method 1: Creating covering non-clustered index.</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:black;"><br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;"><strong>Method 2: Creating included column non-lustered index.</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Let us examine the execution plan and compare the query costs and also verify that if both the index usages are forcing index seek instead of index scan.</p>
<p style="text-align:justify;"><span style="color:black;"><img src="http://www.pinaldave.com/bimg/keylook6.jpg" alt="" width="500" height="294" /></span></p>
<p style="text-align:justify;">As discussed in the example, any non clustered index does not need to include columns which are included in the clustered index.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7057/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7057&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook6.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/</link>
		<comments>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 01:30:53 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6967</guid>
		<description><![CDATA[This article is follow up of my previous article SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup. Please do read my previous article before continuing further.
I have described there two different methods to reduce query execution cost. Let us compare the performance of the SELECT statement [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6967&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This article is follow up of my previous article <strong><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup</a></strong>. Please do read my previous article before continuing further.</p>
<p style="text-align:justify;">I have described there two different methods to reduce query execution cost. Let us compare the performance of the SELECT statement of the previous query.</p>
<p style="text-align:justify;">We have created two different indexes on the table.</p>
<p style="text-align:justify;"><strong>Method 1: Creating covering non-clustered index.</strong></p>
<p style="text-align:justify;">In this method, we will create a non-clustered index that contains the columns used in the SELECT statement along with the column used in the WHERE clause.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:gray;">, </span><span style="color:black;">ID<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;"><strong>Method 2: Creating included column non-lustered index.</strong></p>
<p style="text-align:justify;">In this method, we will create a nonclustered index that includes the columns used in the SELECT statement along with the column used in the WHERE clause. Here, we will use new syntax introduced in SQL Server 2005. An index with included nonkey columns can significantly improve query performance when all the columns in the query are included in the index.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">ID</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Let us compare the performance of our query by running the following query with two different indexes.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex </span><span style="color:blue;">WITH </span><span style="color:gray;">(</span><span style="color:blue;">INDEX</span><span style="color:gray;">(</span><span style="color:black;">IX_OneIndex_Cover</span><span style="color:gray;">))<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex </span><span style="color:blue;">WITH </span><span style="color:gray;">(</span><span style="color:blue;">INDEX</span><span style="color:gray;">(</span><span style="color:black;">IX_OneIndex_Include</span><span style="color:gray;">))<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Let us examine the execution plan and compare the query costs.</p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook6.jpg" alt="" width="500" height="294" /><br />
</span></p>
<p style="text-align:justify;">In fact, in this example, the performance of both the queries is quite same. In this case, we can use either of the query and obtain the same performance.</p>
<p style="text-align:justify;">I have mentioned in my previous article that I prefer the Method 2. The reason is that method 2 has many advantages over method 1.</p>
<p style="text-align:justify;">1) Index can exceed the 900-byte limitation of the index key.</p>
<p style="text-align:justify;">2) Index can include datatypes that are not allowed as key columns – varchar(max), nvarchar(max) or XML.</p>
<p style="text-align:justify;">3) Size of the key index can be reduced, which improves the overall performance of the index operation.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6967/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6967&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook6.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup</title>
		<link>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/</link>
		<comments>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 01:30:49 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6960</guid>
		<description><![CDATA[Today, I would like to share one very quick tip about how to remove bookmark lookup or RID lookup. Let us first understand Bookmark lookup or RID lookup. Please note that from SQL Server 2005 SP1 onwards, Bookmark look up is known as Key look up.
When a small number of rows are requested by a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6960&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today, I would like to share one very quick tip about how to remove bookmark lookup or RID lookup. Let us first understand Bookmark lookup or RID lookup. Please note that from SQL Server 2005 SP1 onwards, Bookmark look up is known as Key look up.</p>
<p style="text-align:justify;">When a small number of rows are requested by a query, the SQL Server optimizer will try to use a non-clustered index on the column or columns contained in the WHERE clause to retrieve the data requested by the query. If the query requests data from columns not present in the non-clustered index, SQL Server must go back to the data pages to get the data in those columns. Even if the table has a clustered index or not, the query will still have to return to the table or clustered index to retrieve the data.</p>
<p style="text-align:justify;">In the above scenario, if table has clustered index, it is called <strong>bookmark lookup</strong> (or key lookup); if the table does not have clustered index, but a non-clustered index, it is called <strong>RID lookup</strong>. This operation is very expensive. To optimize any query containing bookmark lookup or RID lookup, it should be removed from the execution plan to improve performance. There are two different ways to remove bookmark/RID lookup.</p>
<p style="text-align:justify;">Before we understand these two methods, we will create sample table without clustered index and simulate RID lookup. RID Lookup is a bookmark lookup on a heap that uses a supplied row identifier (RID).</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">tempdb<br />
GO<br />
</span><span style="color:green;">-- Create Table OneIndex with few columns<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">OneIndex </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">FirstName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">),<br />
</span><span style="color:black;">LastName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">),<br />
</span><span style="color:black;">City </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Insert One Hundred Thousand Records<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">OneIndex </span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">,</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">LastName</span><span style="color:gray;">,</span><span style="color:black;">City</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">100000 ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">) </span><span style="color:black;">RowID</span><span style="color:gray;">,<br />
</span><span style="color:red;">'Bob'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE </span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">2 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Smith'<br />
</span><span style="color:blue;">ELSE </span><span style="color:red;">'Brown' </span><span style="color:blue;">END</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">1000 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'New York'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">5 </span><span style="color:blue;">THEN </span><span style="color:red;">'San Marino'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">3 </span><span style="color:blue;">THEN </span><span style="color:red;">'Los Angeles'<br />
</span><span style="color:blue;">ELSE </span><span style="color:red;">'Houston' </span><span style="color:blue;">END<br />
FROM </span><span style="color:black;">sys.all_objects a<br />
</span><span style="color:gray;">CROSS </span><span style="color:blue;">JOIN </span><span style="color:black;">sys.all_objects b<br />
GO</span></code></p>
<p style="text-align:justify;">Now let us run following select statement and check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook1.jpg" alt="" width="472" height="295" /></span></p>
<p style="text-align:justify;"><span style="color:black;">As there is no index on table, scan is performed over the table. We will create a clustered index on the table and check the execution plan once again. </span></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Clustered Index<br />
</span><span style="color:blue;">CREATE CLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_ID] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[ID] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Now, run following select on the table once again.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook2.jpg" alt="" width="473" height="274" /></p>
<p><!--[if gte mso 9]&gt;  800x600  &lt;![endif]--></p>
<p><!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE            MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                             &lt;![endif]--></p>
<p style="text-align:justify;">It is clear from execution plan that as a clustered index is created on the table, table scan is now converted to clustered index scan. In either case, base table is completely scanned and there is no seek on the table.</p>
<p style="text-align:justify;">Now, let us see the WHERE clause of our table. From our basic observation, if we create an index on the column that contains the clause, a performance improvement may be obtained. Let us create non-clustered index on the table and then check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Index on Column City As that is used in where condition<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_City] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[City] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">After creating the non-clustered index, let us run our select statement again and check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook3.jpg" alt="" width="486" height="351" /></p>
<p><!--[if gte mso 9]&gt;  800x600  &lt;![endif]--></p>
<p style="text-align:justify;">As we have an index on the WHERE clause, the SQL Server query execution engine uses the non-clustered index to retrieve data from the table. However, the columns used in the SELECT clause are still not part of the index, and to display those columns, the engine will have to go to the base table again and retrieve those columns. This particular behavior is known as bookmark lookup or key lookup.</p>
<p style="text-align:justify;">There are two different methods to resolve this issue. I have demonstrated both the methods together; however, it is recommended that you use any one of these methods for removing key lookup. I prefer Method 2.</p>
<p style="text-align:justify;"><strong>Method 1: Creating non-clustered cover index.</strong></p>
<p style="text-align:justify;">In this method, we will create non-clustered index containing the columns, which are used in the SELECT statement, along with the column which is used in the WHERE clause.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:gray;">, </span><span style="color:black;">ID<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Once the above non-clustered index, which covers all the columns in query, is created, let us run the following SELECT statement and check our execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">From the execution plan, we can confirm that key lookup is removed the only index seek is happening. As there is no key lookup, the SQL Server query engine does not have to go to retrieve the data from data pages and it obtains all the necessary data from index itself.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook4.jpg" alt="" width="469" height="262" /></p>
<p style="text-align:justify;"><strong>Method 2: Creating an included column non-clustered index.</strong></p>
<p style="text-align:justify;">Here, we will create non-clustered index that also includes the columns, which are used in the SELECT statement, along with the column used in the WHERE clause. In this method, we will use new syntax introduced in SQL Server 2005. An index with included nonkey columns can significantly improve query performance when all columns in the query are included in the index.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">ID</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">From the execution plan, it is very clear that this method  also removes the key lookup as well.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook5.jpg" alt="" width="467" height="263" /></p>
<p style="text-align:justify;">In summary, Key lookup, Bookmark lookup or RID lookup reduces the performance of query, and we can improve the performance of query by using included column index or cover index.</p>
<p style="text-align:justify;">I will cover few additional concepts related to the optimal method in another article.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:2058px;width:1px;height:1px;text-align:justify;">
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
</div>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6960/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6960&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook4.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook5.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Interesting Observation &#8211; Query Hint &#8211; FORCE ORDER</title>
		<link>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/</link>
		<comments>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 01:30:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6916</guid>
		<description><![CDATA[SQL Server never stops to amaze me. As regular readers of this blog already know that besides conducting corporate training, I work on large-scale projects on query optimizations and server tuning projects. In one of the recent projects, I have noticed that a Junior Database Developer used the query hint Force Order; when I asked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6916&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">SQL Server never stops to amaze me. As regular readers of this blog already know that besides conducting corporate training, I work on large-scale projects on query optimizations and server tuning projects. In one of the recent projects, I have noticed that a Junior Database Developer used the query hint Force Order; when I asked for details, I found out that the basic concept was not properly understood by him.</p>
<p style="text-align:justify;">Today, let us try to understand its working and the effect of this hint. Further, we will see the extent of difference in performance created by this one query hint. I also have one interesting question for all of you as well; I will give the answer in one of my later posts.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployee </span><span style="color:green;">-- 290 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployeeAddress </span><span style="color:green;">-- 290 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.EmployeeAddress<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployeeDepartmentHistory </span><span style="color:green;">-- 296 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee e<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeAddress ea </span><span style="color:blue;">ON </span><span style="color:black;">ea.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory edh </span><span style="color:blue;">ON </span><span style="color:black;">edh.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee e<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeAddress ea </span><span style="color:blue;">ON </span><span style="color:black;">ea.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory edh </span><span style="color:blue;">ON </span><span style="color:black;">edh.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">OPTION </span><span style="color:gray;">(</span><span style="color:black;">FORCE </span><span style="color:blue;">ORDER</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p style="text-align:justify;">In above example, I have used three tables and their row count is listed as well. Employee and EmployeeAddress – both have same number rows, and EmployeeDepartmentHistory table has around 6 rows more than the other two tables. Now let us run the query without using OPTION (FORCE ORDER) and run it along with the query hint and check the execution plan. You will find a difference in the query cost.</p>
<p style="text-align:justify;">We all accept that the table with least number of rows should be listed as the base table, and the same is done here. We have two such tables with the least number of rows, which are listed as base tables. Now before we further explain this, let us see the execution plan for the same.</p>
<p style="text-align:justify;">
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/forceorder.jpg" alt="" width="500" height="404" /></p>
<p style="text-align:justify;">It is very clear from the above execution plan that when I order is forced the query cost goes high. This proves that the SQL Server has already made a good decision with regard to the optimized query plan. When plan is forced in the case of the joins more than 2 table the performance matters. Let us see the execution order of the table in both the cases.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/forceorder1.jpg" alt="" width="500" height="618" /></p>
<p style="text-align:justify;">Now, from the example, it is very clear when you force order the query, it evaluates the table Employee first and when it is not forced, it evaluates EmployeeAddress first. Even though both the tables have same number of rows, the query optimizer processes them differently and uses different types of join logic. When the order is not forced, it uses hash join; further, in case of forced order, it uses nested loop – this creates a significant difference in the query cost.</p>
<p style="text-align:justify;">The conclusion of this whole exercise is very simple.</p>
<ul style="text-align:justify;">
<li>SQL      Server Query Execution Engine is pretty smart to decide the best execution      plan with least query cost for any query.</li>
<li>Order      of the tables in any query can make a significant impact on the query.</li>
</ul>
<p style="text-align:justify;">Now the question for you: We have seen that using query hint of OPTION (FORCE ORDER) reduces the performance; give an example wherein we can use this hint to improve the performance?</p>
<p style="text-align:justify;">Please leave your comment here. I will publish the answer to this question with due credit and with my own example in a later post.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Index, SQL Joins, SQL Optimization, SQL Performance, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6916/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6916&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/forceorder.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/forceorder1.jpg" medium="image" />
	</item>
		<item>
		<title>SQLAuthority News &#8211; SQL Server 2008 &#8211; The Other Side of Index &#8211; Live Presentation in Ahmedabad</title>
		<link>http://blog.sqlauthority.com/2009/10/02/sqlauthority-news-sql-server-2008-the-other-side-of-index-live-presentation-in-ahmedabad/</link>
		<comments>http://blog.sqlauthority.com/2009/10/02/sqlauthority-news-sql-server-2008-the-other-side-of-index-live-presentation-in-ahmedabad/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 01:30:55 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Humor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL User Group]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6970</guid>
		<description><![CDATA[
Community Tech Days are here Tomorrow in Ahmedabad on Oct 3, 2009. I will be presenting the session ‘SQL Server 2008 – The Other Side of Index’. I will be available there whole day if you want to meet and discuss SQL. I will be starting my session with following cartoon. You will have to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6970&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/ctd/ctd3.jpg" alt="" width="464" height="174" /></p>
<p style="text-align:justify;">Community Tech Days are here Tomorrow in Ahmedabad on Oct 3, 2009. I will be presenting the session ‘<strong>SQL Server 2008 – The Other Side of Index</strong>’. I will be available there whole day if you want to meet and discuss SQL. I will be starting my session with following cartoon. You will have to attend the session in person to see what I am going to cover in the session.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/slowquery3.jpg"><img class="alignnone" src="http://www.pinaldave.com/bimg/slowquery3.jpg" alt="" width="498" height="197" /></a></p>
<p style="text-align:justify;">I suggest you do not miss session of <strong><a href="http://extremeexperts.com/" target="_blank">Vinod Kumar </a></strong> and <a href="http://beyondrelational.com/blogs/jacob/"><strong>Jacob Sebastian</strong></a>. They are technology rock stars. You can read about them in following posts.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/09/30/sqlauthority-news-community-tech-days-oct-3-2009-sql-server-2008-the-other-side-of-index/" target="_blank">SQLAuthority News – Community Tech Days – Oct 3, 2009 – SQL Server 2008 – The Other Side of Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/09/18/sqlauthority-news-community-tech-days-oct-3-2009-ahmedabad/" target="_blank">SQLAuthority News – Community Tech Days Oct 3, 2009 – Ahmedabad</a></p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Humor, SQL Index, SQL Query, SQL Server, SQL Tips and Tricks, SQL User Group, SQLAuthority News, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6970/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6970/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6970/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6970&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/02/sqlauthority-news-sql-server-2008-the-other-side-of-index-live-presentation-in-ahmedabad/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/ctd/ctd3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/slowquery3.jpg" medium="image" />
	</item>
		<item>
		<title>SQLAuthority News &#8211; Community Tech Days &#8211; Oct 3, 2009 &#8211; SQL Server 2008 &#8211; The Other Side of Index</title>
		<link>http://blog.sqlauthority.com/2009/09/30/sqlauthority-news-community-tech-days-oct-3-2009-sql-server-2008-the-other-side-of-index/</link>
		<comments>http://blog.sqlauthority.com/2009/09/30/sqlauthority-news-community-tech-days-oct-3-2009-sql-server-2008-the-other-side-of-index/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 01:30:48 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[MVP]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL User Group]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[PASS]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6924</guid>
		<description><![CDATA[Microsoft Community Tech Days are here! Dive deep into the world of Microsoft technologies at the Community TechDays and get  trained on the latest from Microsoft.

Community Tech Days are coming to Ahmedabad on Oct 3, 2009. I will be presenting the session &#8216;SQL Server 2008 &#8211; The Other Side of Index&#8217;. I will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6924&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Microsoft Community Tech Days are here! Dive deep into the world of Microsoft technologies at the Community TechDays and get  trained on the latest from Microsoft.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/ctd/ctd3.jpg" alt="" width="464" height="174" /></p>
<p style="text-align:justify;">Community Tech Days are coming to Ahmedabad on Oct 3, 2009. I will be presenting the session &#8216;SQL Server 2008 &#8211; The Other Side of Index&#8217;. I will be talking about the other side of Index where we will be thinking out of the typical way of creating Indexes. Take a look at the following common conversation.</p>
<p style="padding-left:30px;text-align:justify;"><em><strong>Person 1: My Query is running slow.<br />
Person 2: <span style="color:#0000ff;">How about create an index on it?</span><br />
Person 1: Good point!</strong></em></p>
<p style="text-align:justify;">Every time I listen to such conversations, I sense a lack of complete understanding on how the Index affects performance. I will be starting the session with the above mentioned conversation and will continue to explain how index and performance are related. We will not talk about the regular creation of index but will explore the different sides of Index. We will also discuss about common concepts that are related to index, such as deadlock, execution plan, indexed view, and few other issues. I assure you that this whole session will be a two-way interaction between the attendees and me.</p>
<p style="text-align:justify;">Again, we will have a lot of interesting demos, examples and conversations. If you have not registered for this event, I suggest that you do the same right away.</p>
<p style="text-align:justify;"><strong><a href="http://www.communitytechdays.com/default.aspx" target="_blank"></a></strong><a href="http://www.communitytechdays.com/default.aspx" target="_blank"><img class="alignnone" src="http://www.pinaldave.com/bimg/ctd/ctdreg.jpg" alt="" width="455" height="108" /></a></p>
<p style="text-align:justify;">Please note that there is no video recording of this event or live telecast. This event should be attended in person.</p>
<p style="text-align:justify;">I am not only attending this event to deliver my tech session, but also to listen to two of my colleagues.</p>
<p style="text-align:justify;">I am an avid listener of <a href="http://extremeexperts.com/" target="_blank"><strong>Vinod Kumar</strong></a>’s sessions and I make sure that I do not miss any of them. I always feel that he is capable of instilling his passion in all who listen. He is well known for his community site <a href="http://extremeexperts.com/" target="_blank"><strong>ExtremeExperts.com</strong></a> and also is the top evangelist from Microsoft. He will be presenting two excellent sessions. I am looking forward to listen both the sessions – Tips and Tricks with Office 2010 and Windows 7 – A Dream Operating System for IT Professionals.</p>
<p style="text-align:justify;"><a href="http://beyondrelational.com/blogs/jacob/" target="_blank"><strong>Jacob Sebastian</strong></a> is an SQL Server MVP and also my friend. We work together on all the community-related aspects. We are leaders of <a href="http://ahmedabad.sqlpass.org/" target="_blank">Ahmedabad </a>SQL Server User Group and <a href="http://gandhinagar.sqlpass.org/" target="_blank">Gandhinagar</a> SQL Server User Group. Jacob is going to speak at PASS Global Summit in November 2009. He will be presenting an excellent session on the Best Practices for Exception Handling and Defensive Programming in Microsoft SQL Server.</p>
<p style="text-align:justify;">I insist all of you to register for this event to make the maximum use of it. We can meet after the session and talk about some good SQL.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in MVP, Pinal Dave, SQL, SQL Authority, SQL Index, SQL Query, SQL Server, SQL Tips and Tricks, SQL User Group, SQLAuthority News, T SQL, Technology Tagged: PASS <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6924/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6924/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6924/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6924/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6924/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6924/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6924&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/30/sqlauthority-news-community-tech-days-oct-3-2009-sql-server-2008-the-other-side-of-index/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/ctd/ctd3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/ctd/ctdreg.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Interesting Observation &#8211; Execution Plan and Results of Aggregate Concatenation Queries</title>
		<link>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/</link>
		<comments>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:30:32 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL View]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6930</guid>
		<description><![CDATA[Working with SQL Server has never seems to be monotonous – no matter how long one has worked with it. Quite often, I come across some excellent comments that I feel like acknowledging them as blog posts. Recently, I wrote an article on SQL SERVER – Execution Plan and Results of Aggregate Concatenation Queries Depend [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6930&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Working with SQL Server has never seems to be monotonous – no matter how long one has worked with it. Quite often, I come across some excellent comments that I feel like acknowledging them as blog posts. Recently, I wrote an article on <a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/" target="_blank"><strong>SQL SERVER – Execution Plan and Results of Aggregate Concatenation Queries Depend Upon Expression Location</strong></a>, which is well received in community.</p>
<p style="text-align:justify;">Before you read this article further, I request you to read <a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/" target="_blank">original article</a>. I received very interesting comments from Bob on the blog, where he explained why this is happening. Further, he talked about a similar kind of example. Let us first read his comment, and then we will execute his example and see the resultset.</p>
<p style="text-align:justify;">Comment from <strong><a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/#comment-56103" target="_blank">Bob</a></strong></p>
<p style="padding-left:30px;text-align:justify;">pinaldave,</p>
<p style="padding-left:30px;text-align:justify;">If you want to see what’s going on here, I think you need to shift your point of view from an implementation-centric view to an ANSI point of view. ANSI does not guarantee processing order. Figure 2 is interesting, but it will be potentially misleading if you don’t understand the ANSI rule-set SQL Server operates under in most cases. Implementation thinking can certainly be useful at times when you really need that multi-million row query to finish before the backups fire off, but in this case, it’s counterproductive to understanding what is going on.</p>
<p style="padding-left:30px;text-align:justify;">First off, your statements all return a single row, which were properly sorted according to your ORDER BY expression; which is to say that there was really no sorting to be done because only a single row is returned. So let’s forget about the ORDER BY. Forget that the execution plan shows 2 rows being sorted — that’s implementation specific. A different vendor’s product could have an optimizer smart enough to see that only a single row can ever be returned from this query and therefore, avoid the unnecessary sort altogether.</p>
<p style="padding-left:30px;text-align:justify;">Secondly, you are not guaranteed that the string concatenation will occur in any particular order. The ORDER BY clause only pertains to the final results from an ANSI perspective (at least, for these queries). MS SQL Server is right in line with ANSI and will not guarantee you anything different. Don’t expect to get AB in every case.</p>
<p style="padding-left:30px;text-align:justify;">Finally, SQL works using relational sets, so the construct varchar = varchar + varchar forms a relational set that is evaluated accordingly. I have seen this type of construct used many times and it works sometimes – until it doesn’t. This is why you get only B in one example where I suspect you wanted AB. After thinking about it a bit, I built this example which I hope is just different enough to show you the same mechanism is at work here:<br />
DECLARE @sum INT<br />
SELECT @sum = 0<br />
SELECT @sum = @sum + num FROM (<br />
SELECT 1 [num] UNION SELECT 2 [num]<br />
) [a] ORDER BY (num * num)<br />
SELECT @sum [Is it 3]</p>
<p style="padding-left:30px;text-align:justify;">I tried to show two things here. The first is that the ORDER BY isn’t doing what you think it’s doing with respect to the order of concatenation in your query. The order here is nonsensical. The second thing I think the example shows is that 1+2 doesn’t equal 3 with this @ = @ + col construct in all cases. It’s a bad construct to use. Remove the ORDER BY and you get 3, leave it in and you get 2. Heck, someone else could get 1 in theory. There’s a case I see all the time where this is used, but I can’t quite recall it. I’ll post it if I think of it again.</p>
<p style="text-align:justify;">I must admit that he has made excellent point and explained the concept very well as well. Just for clarity, we will see the implementation of the example mentioned by him to understand how it works.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sum </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:#434343;">@sum </span><span style="color:gray;">+ </span><span style="color:black;">num </span><span style="color:blue;">FROM </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">1 [num] </span><span style="color:blue;">UNION SELECT </span><span style="color:black;">2 [num]<br />
</span><span style="color:gray;">) </span><span style="color:black;">[a] </span><span style="color:blue;">ORDER BY </span><span style="color:gray;">(</span><span style="color:black;">num </span><span style="color:gray;">* </span><span style="color:black;">num</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:black;">WithOrderBy<br />
GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sum </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:blue;">= </span><span style="color:#434343;">@sum </span><span style="color:gray;">+ </span><span style="color:black;">num </span><span style="color:blue;">FROM </span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">1 [num] </span><span style="color:blue;">UNION SELECT </span><span style="color:black;">2 [num]<br />
</span><span style="color:gray;">) </span><span style="color:black;">[a]<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sum </span><span style="color:black;">WithoutOrderBy<br />
GO</span></code></p>
<p style="text-align:justify;">Let us see the result when we run the above two queries with and without ORDER BY clause.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/orderby.jpg" alt="" width="370" height="442" /></p>
<p style="text-align:justify;">Again, it is interesting to see how results are different from each other when there is only change of inclusion of ORDER BY clause. Bob has explained why this is happening in his comment earlier. He also explains further in another comment in the same article that.</p>
<p style="text-align:justify;">Comment from <strong><a href="http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/#comment-56106" target="_blank">Bob</a></strong>:</p>
<p style="padding-left:30px;text-align:justify;">One more item to note is that if you built:</p>
<p style="padding-left:30px;text-align:justify;">SELECT @Str0 = @Str0 + C1 FROM T1</p>
<p style="padding-left:30px;text-align:justify;">into a table expression (i.e. VIEW, FUNCTION, FROM (SELECT)), you may get the results you want over and over until the one day where you call the view or function with the combination of syntax that triggers the unexpected behavoir.</p>
<p style="padding-left:30px;text-align:justify;"><em>pinaldave,</em></p>
<p style="padding-left:30px;text-align:justify;"><em><strong>On my final point</strong>, I think it’s unclear/weak. I’d like to add that the most clear reason as to why you can’t expect to get AB or BA, but might in fact get just A or just B, is that the construct @=@ +col is non-deterministic and therefore, for the same range of input values, is not guaranteed to produce the same result in every instance.</em></p>
<p style="text-align:justify;"><strong>Bob</strong>, Thank you very much for excellent explanation and your participation in the community.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Index, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: SQL View <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6930/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6930/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6930/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6930&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/29/sql-server-interesting-observation-execution-plan-and-results-of-aggregate-concatenation-queries/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/orderby.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Outer Join in Indexed View &#8211; Question to Readers</title>
		<link>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/</link>
		<comments>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:30:46 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL White Papers]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL View]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6910</guid>
		<description><![CDATA[Today I have question for you. Just a day ago I was reading whitepaper Improving Performance with SQL Server 2008 Indexed Views. Following is question and answer I read in the white paper.
Q. Why can&#8217;t I use OUTER JOIN in an indexed view?
A. Rows can logically disappear from an indexed view based on OUTER JOIN [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6910&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today I have question for you. Just a day ago I was reading whitepaper <a href="http://msdn.microsoft.com/en-us/library/dd171921.aspx" target="_blank">Improving Performance with SQL Server 2008 Indexed Views</a>. Following is question and answer I read in the white paper.</p>
<p style="padding-left:30px;text-align:justify;"><em><strong>Q. Why can&#8217;t I use OUTER JOIN in an indexed view?</strong></em></p>
<p style="padding-left:30px;text-align:justify;"><em>A. Rows can logically disappear from an indexed view based on OUTER JOIN when you insert data into a base table. This makes incrementally updating OUTER JOIN views relatively complex to implement, and the performance of the implementation would be slower than for views based on standard (INNER) JOIN.</em></p>
<p style="text-align:justify;">Here I would like to ask you one question, do you have example for kind of OUTER JOIN where you insert data into base table, it will make a row disappear from query?</p>
<p style="text-align:justify;">Please post your answer as comment.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Joins, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLServer, T SQL, Technology Tagged: SQL View <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6910/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6910&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Interesting Observation &#8211; Index on Index View Used in Similar Query</title>
		<link>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/</link>
		<comments>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 01:30:36 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL White Papers]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6895</guid>
		<description><![CDATA[Recently, I was working on an optimization project for one of the large organizations. While working on one of the queries, we came across a very interesting observation. We found that there was a query on the base table and when the query was run, it used the index, which did not exist in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6895&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Recently, I was working on an optimization project for one of the large organizations. While working on one of the queries, we came across a very interesting observation. We found that there was a query on the base table and when the query was run, it used the index, which did not exist in the base table. On careful examination, we found that the query was using the index that was on another view. This was very interesting as I have personally never experienced a scenario like this. In simple words, &#8220;Query on the base table can use the index created on the indexed view of the same base table.&#8221;</p>
<p style="text-align:justify;">If you have skipped the first paragraph, I suggest you go over the first paragraph one more time and try to understand the intended meaning. According to me, this is a very interesting observation and we rarely come across such an instance. I have made very small attempt to recreate this particular behavior.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">tempdb<br />
GO<br />
</span><span style="color:green;">-- Create Table<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">IndexViewAggr </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Insert One Hundred Thousand Records<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">IndexViewAggr </span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">100000 ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">) </span><span style="color:black;">RowID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.all_objects a<br />
</span><span style="color:gray;">CROSS </span><span style="color:blue;">JOIN </span><span style="color:black;">sys.all_objects b<br />
GO<br />
</span><span style="color:green;">-- Create View on the table<br />
</span><span style="color:blue;">CREATE VIEW </span><span style="color:black;">ViewAggr </span><span style="color:blue;">WITH </span><span style="color:black;">SCHEMABINDING<br />
</span><span style="color:blue;">AS<br />
SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Following query is very identical to View<br />
-- Run the query on base table<br />
-- Please note that in execution plan there is Table Scan<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Create Index on the View<br />
-- Please note that this index is on View and not on table<br />
</span><span style="color:blue;">CREATE UNIQUE CLUSTERED INDEX </span><span style="color:black;">IndexView </span><span style="color:blue;">ON </span><span style="color:black;">ViewAggr</span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Run the query on base table again<br />
-- Please note that in execution plan there is Index Scan<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Please note that there are difference in "Query Cost"<br />
-- Clean up Database<br />
</span><span style="color:blue;">DROP VIEW </span><span style="color:black;">ViewAggr<br />
GO<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">IndexViewAggr<br />
GO</span></code>
</p>
<p style="text-align:justify;">Now let us quickly observe two performance comparison of two of the selects. One object is created before the creation of the index over the view, and the other object is created after the creation of the index over the view. Please note that we are talking about two different objects here. Let me explain this schematically.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/queryindex.jpg" alt="" width="500" height="513" /></p>
<p style="text-align:justify;">This is a very interesting behavior as the index created on view affects the query that runs on the base table. Let me show you the execution plan of the query before and after index creation.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/indexview1.jpg" alt="" width="500" height="285" /></p>
<p style="text-align:justify;">From this example, it is very clear that there is a very big difference between the query costs when the index is created on the table. In fact, there is a very simple explanation of this behavior in the white paper <a href="http://msdn.microsoft.com/en-us/library/dd171921.aspx" target="_blank">Improving Performance with SQL Server 2008 Indexed Views</a>.</p>
<p style="text-align:justify;">The reason for this behavior is that the query optimizer works when it checks for the index on view and finds that the execution plan of the query is similar to that of the view.</p>
<p style="text-align:justify;">Let me know your thoughts about this article. I do understand that this concept is slightly complicated. Further, this type of behavior is rarely encountered in real world. I hope that this article will give you a better insight to such a situation.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6895/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6895&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/queryindex.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/indexview1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Index Seek vs. Index Scan &#8211; Diffefence and Usage &#8211; A Simple Note</title>
		<link>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/</link>
		<comments>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 01:30:18 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6648</guid>
		<description><![CDATA[In this article we shall examine the two modes of data search and retrieval using indexes- index seeks and index scans, and the differences between the two.
Firstly, let us revisit indexes briefly. An index in a SQL Server database is analogous to the index at the start of a book. That is, its function is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6648&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">In this article we shall examine the two modes of data search and retrieval using indexes- index seeks and index scans, and the differences between the two.</p>
<p style="text-align:justify;">Firstly, let us revisit indexes briefly. An index in a SQL Server database is analogous to the index at the start of a book. That is, its function is to allow you to quickly find the data you are searching for inside the book; in the case of a database, the “book” is a table.</p>
<p style="text-align:justify;">An index scan means that SQL Server reads all rows in a table, and then returns only those rows that satisfy the search criteria. When an index scan is performed, all the rows in the leaf level of the index are scanned. This essentially means that all of the rows of the index are examined instead of the table directly. This is sometimes contrasted to a table scan, in which all the table data is read directly. However, there is usually little difference between an index scan and a table scan.</p>
<p style="text-align:justify;">You may wonder why the Query Optimizer may choose to do an index or table scan. Surely it is much faster to first look up data using an index than to go through all the rows in a table? In fact, for small tables data retrieval via an index or table scan is faster than using the index itself for selection. This is because the added overhead of first reading the index, then reading the pages containing the rows returned by the index, does not offer any performance improvement for a table with only a few rows.</p>
<p style="text-align:justify;">Other reasons to use an index scan would be when an index is not selective enough, and when a query will return a large percentage (greater than 50%) of rows from the table. In such cases the additional overhead of first using the index may result in a small degradation of performance.</p>
<p style="text-align:justify;">An index seek, on the other hand, means that the Query Optimizer relies entirely on the index leaf data to locate rows satisfying the query condition. An index seek will be most beneficial in cases where a small percentage (less than 10 or 15%) of rows will be returned. An index seek will only affect the rows that satisfy a query condition and the pages that contain these qualifying rows; this is highly beneficial, in performance terms, when a table has a very large number of rows.</p>
<p style="text-align:justify;">It is also worth noting that it is usually not worthwhile to create indexes on low-cardinality columns as they would rarely be used by the Query Optimizer. A low-cardinality column is one that contains a very small range of distinct values, for example a ‘Gender’ column would have only two distinct values- Male or Female. An example of a high-cardinality column is of course the primary key column, in which each value is distinct.</p>
<p style="text-align:justify;">In summary, the Query Optimizer generally tries to perform an index seek. If this is not possible or beneficial (for example when the total number of rows is very small) then an index scan is used instead.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6648/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6648&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Discussion &#8211; Effect of Missing Identity on System &#8211; Real World Scenario</title>
		<link>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/</link>
		<comments>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 01:30:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6524</guid>
		<description><![CDATA[About a week ago, SQL Server Expert, Imran Mohammed, provided a script, which will list all the missing identity values of a table in a database. In this post, I asked my readers if any could write a similar or better script. The results were interesting. While no one provided a new script, my question [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6524&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">About a week ago, SQL Server Expert, <strong>Imran Mohammed,</strong> provided a script, which will list all the missing identity values of a table in a database. In this <a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/">post</a>, I asked my readers if any could write a similar or better script. The results were interesting. While no one provided a new script, my question sparked a very active <a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/">discussion</a> that is still ongoing.</p>
<p style="text-align:justify;">When providing the script, Imran asked me if I knew of any specific circumstances in which this kind of query could be useful, as he could not think of an instance where it would be necessary to find a missing identity. I was unable to think of a single reason for listing missing identities in a table. I posted Imran&#8217;s script on the assumption that someone would come up with an improved script, but as mentioned earlier, nobody did. Instead, we have been able to follow a very interesting discussion on subject of the need, if any, for listing Missing Identity values.</p>
<p style="text-align:justify;">So, the question is this: &#8220;<strong><em>Do you know a real-world scenario where a Missing Identity value in any table can create problems?</em></strong>&#8220;</p>
<p style="text-align:justify;">I have already received some extremely interesting comments from many experts, and all have posed the above question in one form or another. At this moment, I am still trying to think of an example from my own experience, but have yet to find one. Imran has since come up with one good example. Here is what he and other experts have suggested so far.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54117" target="_blank"><strong>Jacob Sebastian</strong></a> &#8211; IDENTITY values are not expected to be sequential and there are all chances of having missing identity values, the most common cause is transaction rollbacks.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54139" target="_blank"><strong>Simon Worth</strong></a> &#8211; The identity column is basically just a random number – even though they come sequentially. A developer making an assumption that the next record inserted will have an identity that is 1 more than the last inserted record. And if this is the case – then there are flaws in the logic of the developer.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54158" target="_blank"><strong>Jacob Sebastian</strong></a> &#8211; What if the value in my table is 1, 2, 3, 5, 6 etc where “4″ is missing from the sequence. So what is the importance of knowing whether a table has missing identity values or not?</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/07/27/sql-server-list-all-missing-identity-values-of-table-in-database/#comment-54184" target="_blank"><strong>Imran Mohammed</strong></a> &#8211; If you use Identity property as your most unique column and Transaction Identifier, then definitely you would want to know why few transaction did not completely, Is there any specific fashion these transaction fails (Can be found out looking at missing values of identity)&#8230; Could be helpful to debug.</p>
<p style="text-align:justify;">Now it is your turn. Let us have your thoughts.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Database, DBA, Pinal Dave, Readers Contribution, Readers Question, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6524/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6524&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/11/sql-server-discussion-effect-of-missing-identity-on-system-real-world-scenario/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Maximum Number of Index per Table</title>
		<link>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/</link>
		<comments>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 01:30:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Contribution]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5733</guid>
		<description><![CDATA[TechEd on Road Ahmedabad, June 20, 2009, was a huge success. This grand event saw over 200 attendees actively participating in the sessions. We had attendees traveling from far and wide, including Delhi, Mumbai, Jaipur, Kerala, Baroda, Himmatnagar, Rajkot, among other cities from India. This enthusiastic participation made the event truly grand. It was a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5733&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/06/22/sqlauthority-news-teched-on-road-ahmedabad-june-20-2009-an-astounding-success/" target="_blank">TechEd on Road Ahmedabad</a></strong>, June 20, 2009, was a huge success. This grand event saw over 200 attendees actively participating in the sessions. We had attendees traveling from far and wide, including Delhi, Mumbai, Jaipur, Kerala, Baroda, Himmatnagar, Rajkot, among other cities from India. This enthusiastic participation made the event truly grand. It was a moment of bliss for me as I had not anticipated such tremendous positive response!</p>
<p style="text-align:justify;">Although the Official time to commence the event was at 1:45 PM we were really excited to see the attendees entering the hall before the official time. We were more than happy to quickly arrange a special session for those attendees who came in early to keep them engaged. They won loads of gifts while waiting for the official sessions to start. We had a brainstorming quiz session. I was happy to see that people in Ahmedabad are now taking keen interest in enhancing their knowledge.</p>
<p style="text-align:justify;">One of the questions was &#8211; <strong>What is the maximum number of Index per table? </strong>I received lots of answers to this question but only two answers are correct. Let us now take a look at them.</p>
<p style="text-align:justify;"><strong>For SQL Server 2005:</strong><br />
1 Clustered Index + 249 Nonclustered Index = 250 Index<br />
<a href="http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx</a></p>
<p style="text-align:justify;"><strong>For SQL Server 2008:</strong><br />
1 Clustered Index + 999 Nonclustered Index = 1000 Index<br />
<a href="http://msdn.microsoft.com/en-us/library/ms143432.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms143432.aspx</a>
</p>
<p style="text-align:justify;">I would like to thank one of the attendees of Ahmedabad TechEd Kruti Kansara for the above comment.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Contribution, Readers Question, SQL, SQL Authority, SQL Index, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5733/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5733&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/29/sql-server-maximum-number-of-index-per-table/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Clustered Index on Separate Drive From Table Location</title>
		<link>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/</link>
		<comments>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 01:30:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5491</guid>
		<description><![CDATA[How to improve performance of SQL Server Queries is a common topic of discussion among many of us. Much has been said, much has been discussed. Few days back, I had an interesting discussion with one of the Junior developers regarding performance improvement of SQL Server Queries. We discussed on how by using a separate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5491&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong>How to improve performance of SQL Server Queries</strong> is a common topic of discussion among many of us. Much has been said, much has been discussed. Few days back, I had an interesting discussion with one of the Junior developers regarding performance improvement of SQL Server Queries. We discussed on how by using a separate hard drive for several database objects can right away improve performance. I suggested him that non clustered index and tempdb can be created on a separate disk to improve performance.</p>
<p style="text-align:justify;">No sooner had I given my suggestion than I received a question &#8211; What will happen if we can create clustered index on a separate drive from the table on which it is built.</p>
<p style="text-align:justify;">My answer is : <strong>No! </strong>It is not possible at all.</p>
<p style="text-align:justify;">Let us first be clear about the difference between a clustered and a non clustered index.</p>
<p style="text-align:justify;"><strong>Clustered Index</strong></p>
<ul>
<li>Only 1 allowed per table</li>
<li>Physically rearranges data in the table to conform to the index constraints</li>
<li>For use on columns that are frequently searched for ranges of data</li>
<li>For use on columns with low selectivity</li>
</ul>
<p style="text-align:justify;"><strong>Non-Clustered Index</strong></p>
<ul>
<li>Up to 249 (for SQL Server 2005) and 999 (for SQL Server 2008) allowed per table</li>
<li>Creates a separate list of key values with pointers to the location of the data in the data pages</li>
<li>For use on columns that are searched for single values</li>
<li>For use on columns with high selectivity</li>
</ul>
<p style="text-align:justify;">A table devoid of primary key index is called heap, and here data is not arranged in a particular order, which gives rise to issues that adversely affect performance. Data must be stored in some kind of order. If we put clustered index on it then the order will be forced by that index and the data will be stored in that particular order.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5491/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5491&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
	</channel>
</rss>