<?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>SQL Server Journey with SQL Authority &#187; SQL System Table</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-system-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:51:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>SQL Server Journey with SQL Authority &#187; SQL System Table</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.sqlauthority.com/osd.xml" title="SQL Server Journey with SQL Authority" />
	<atom:link rel='hub' href='http://blog.sqlauthority.com/?pushpress=hub'/>
		<item>
		<title>SQL SERVER &#8211; Resource Database ID &#8211; 32767</title>
		<link>http://blog.sqlauthority.com/2011/05/10/sql-server-resource-database-id-32767/</link>
		<comments>http://blog.sqlauthority.com/2011/05/10/sql-server-resource-database-id-32767/#comments</comments>
		<pubDate>Tue, 10 May 2011 01:30:25 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[PostADay]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=12842</guid>
		<description><![CDATA[Earlier I blogged about SQL SERVER – What Kind of Lock WITH (NOLOCK) Hint Takes on Object?. After reading the post, I got question by one of the blog reader. &#8220;Hi Pinal, I see in your blog post you have Database ID which is 32767. Everytime I want to get the name of the database from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=12842&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Earlier I blogged about <a title="Permanent Link to SQL SERVER – What Kind of Lock WITH (NOLOCK) Hint Takes on Object?" href="http://blog.sqlauthority.com/2011/05/08/sql-server-what-kind-of-lock-with-nolock-hint-takes-on-object/" rel="bookmark">SQL SERVER – What Kind of Lock WITH (NOLOCK) Hint Takes on Object?</a>. After reading the post, I got question by one of the blog reader.</p>
<p style="text-align:justify;">&#8220;Hi Pinal,</p>
<p style="text-align:justify;">I see in your blog post you have Database ID which is 32767. Everytime I want to get the name of the database from database_ID I use following function but this time this function returned NULL.</p>
<p style="text-align:justify;">SELECT DB_NAME(32767)</p>
<p style="text-align:justify;">When I tried to list all the databases uses following script it did not have that database ID as well.</p>
<p style="text-align:justify;">SELECT *<br />
FROM sys.databases</p>
<p style="text-align:justify;">I assume you have created this many database is that true?&#8221;</p>
<p style="text-align:justify;">Very interesting question to me. I have never thought about it when I posted as I assumed few things. Here is the answer. Database_ID 32767 is reserved Resource Database.I have not created that many databases. This database is hidden from users in SSMS but you can see that if you go to file folder. You can read more about the same over here <strong><a href="http://blog.sqlauthority.com/2010/01/31/sql-server-location-of-resource-database-in-sql-server-editions/" target="_blank">SQL SERVER – Location of Resource Database in SQL Server Editions</a></strong>.</p>
<p style="text-align:justify;">The Resource database is a read-only database that contains all the system objects that are included with SQL Server. SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically appear in the sys schema of every database. The Resource database does not contain user data or user metadata. (from BOL).</p>
<p style="text-align:justify;">In SQL Server maximum databases per instances can be created are 32,767. This last number has been reserved by Resource Database itself.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/postaday/'>PostADay</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/12842/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/12842/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/12842/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=12842&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2011/05/10/sql-server-resource-database-id-32767/feed/</wfw:commentRss>
		<slash:comments>8</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; Denali &#8211; ObjectID in Negative &#8211; Local TempTable has Negative ObjectID</title>
		<link>http://blog.sqlauthority.com/2011/03/23/sql-server-denali-objectid-in-negative-local-temptable-has-negative-objectid/</link>
		<comments>http://blog.sqlauthority.com/2011/03/23/sql-server-denali-objectid-in-negative-local-temptable-has-negative-objectid/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 01:30:55 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[PostADay]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=12295</guid>
		<description><![CDATA[I used to run the following script to generate random large results. However, when I ran this on Denali I noticed a very interesting behavior: SELECT o1.OBJECT_ID,o1.name, o2.OBJECT_ID, o2.name FROM sys.all_objects o1 CROSS JOIN sys.all_objects o2 I noticed lots of negative object_ID’s on Denali, whereas my experience on SQL Server 2008 R2 as well as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=12295&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I used to run the following script to generate random large results. However, when I ran this on Denali I noticed a very interesting behavior:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">o1.</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">,</span><span style="color:black;">o1.name</span><span style="color:gray;">, </span><span style="color:black;">o2.</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">, </span><span style="color:black;">o2.name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.all_objects o1<br />
</span><span style="color:gray;">CROSS </span><span style="color:blue;">JOIN </span><span style="color:black;">sys.all_objects o2<br />
</span></code></p>
<p style="text-align:justify;">I noticed lots of negative object_ID’s on Denali, whereas my experience on SQL Server 2008 R2 as well as the earlier versions was it was always giving me a positive number.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/TempNegative.jpg" alt="" width="401" height="314" /></p>
<p style="text-align:justify;">This whole thing interested me so I decided to find out objects which belonged to the negative object_ID. When I looked at the name of the object, it was very evident that it belonged to TempTable.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/TempNegative1.jpg" alt="" width="418" height="453" /></p>
<p style="text-align:justify;">To verify my finding, I ran the following command for a couple of times:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">#LocalTempTable </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">)</span></code></p>
<p style="text-align:justify;">Then, I realized that every time I ran this command, I found one more negative ID added in the objects table. To further clarify this, I ran the following command:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">tempdb.sys.tables</span></code></p>
<p style="text-align:justify;">This command really validated the event that whenever LocalTempTable is created in the Denali, it creates object_ID with negative number. However, in SQL Server 2008 R2 and earlier versions, it is always a positive number.</p>
<p style="text-align:justify;">I attempted to create Global TempTable using the following code. The result was all of the global TempTable created Object_ID’s which yield positive numbers. For the moment, it looks like all the LocalTempTable have negative ID’s.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">##GlobalTempTable </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">)</span></code></p>
<p style="text-align:justify;">Let me ask you a few questions:</p>
<ul style="text-align:justify;">
<li>Are there any other objects in SQL      Server &#8216;Denali&#8217; that have negative object_ID?</li>
<li>What can be the reason behind  the negative object_ID?</li>
</ul>
<p style="text-align:justify;">On a separate note, take a look at the following code:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">IF </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'tempdb.dbo.#LocalTempTable'</span><span style="color:gray;">) &gt; </span><span style="color:black;">0</span></code></p>
<p style="text-align:justify;">If you updated to Denali you should change it to either <code style="font-size:12px;"><span style="color:blue;"><br />
IF </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'tempdb.dbo.#LocalTempTable'</span><span style="color:gray;">) &lt;&gt;</span><span style="color:black;">0</span></code><br />
or<br />
<code style="font-size:12px;"><span style="color:blue;">IF </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'tempdb.dbo.#LocalTempTable'</span><span style="color:gray;">) IS NOT NULL</span></code></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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/postaday/'>PostADay</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/12295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/12295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/12295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=12295&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2011/03/23/sql-server-denali-objectid-in-negative-local-temptable-has-negative-objectid/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/TempNegative.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/TempNegative1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; System Stored Procedure sys.sp_tables</title>
		<link>http://blog.sqlauthority.com/2010/10/17/sql-server-system-stored-procedure-sys-sp_tables/</link>
		<comments>http://blog.sqlauthority.com/2010/10/17/sql-server-system-stored-procedure-sys-sp_tables/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL System Table]]></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=10569</guid>
		<description><![CDATA[I have seen people running the following script quite often, to know the list of the tables from the database: SELECT * FROM sys.tables GO The script above provides various information from create date to file stream, and many other important information. If you need all those information, that script is the one for you. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10569&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I have seen people running the following script quite often, to know the list of the tables from the database:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.tables<br />
GO</span></code></p>
<p style="text-align:justify;">The script above provides various information from create date to file stream, and many other important information. If you need all those information, that script is the one for you. However, if you do not need all those information, I suggest that you run the following script:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">EXEC </span><span style="color:black;">sys.</span><span style="color:darkred;">sp_tables<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">The script above will give all the tables in the table with schema name and qualifiers. Additionally, this will return all the system catalog views together with other views. This Stored Procedure returns all the tables first in the result set, followed by views.</p>
<p style="text-align:justify;">Even though Stored Procedure returns more numbers of rows, it still performs better than the sys.table query.</p>
<p style="text-align:justify;">Let us verify it with two different methods for database AdventureWorks:</p>
<p style="text-align:justify;"><strong>1) SET STATISTICS IO ON</strong></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;">SET STATISTICS </span><span style="color:black;">IO </span><span style="color:blue;">ON<br />
SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.tables<br />
GO<br />
</span><span style="color:blue;">EXEC </span><span style="color:black;">sys.</span><span style="color:darkred;">sp_tables<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p style="text-align:justify;">(81 row(s) affected) (This is for sys.tables)<br />
Table &#8216;syspalvalues&#8217;. Scan count 0, logical reads 162, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br />
Table &#8216;syssingleobjrefs&#8217;. Scan count 0, logical reads 324, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br />
Table &#8216;sysidxstats&#8217;. Scan count 81, logical reads 168, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br />
Table &#8216;syspalnames&#8217;. Scan count 0, logical reads 162, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br />
Table &#8216;sysschobjs&#8217;. Scan count 1, logical reads 16, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">(456 row(s) affected) (This is for sys.sp_tables)<br />
Table &#8216;sysobjrdb&#8217;. Scan count 1, logical reads 29, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<br />
Table &#8216;sysschobjs&#8217;. Scan count 1, logical reads 16, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;"><strong>2) Execution Plan</strong></p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/sp_tables.jpg" alt="" /></p>
<p style="text-align:justify;">You can see that the execution plan for <strong>sys.table</strong> has much higher cost of query batch.</p>
<p style="text-align:justify;">Well, if you only need to know the name of the tables, I suggest that you start using SP_TABLES; at least it takes less typing to do.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-stored-procedure/'>SQL Stored Procedure</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/10569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/10569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/10569/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10569&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/10/17/sql-server-system-stored-procedure-sys-sp_tables/feed/</wfw:commentRss>
		<slash:comments>5</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_tables.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Find Total Number of Transaction on Interval</title>
		<link>http://blog.sqlauthority.com/2010/10/04/sql-server-find-total-number-of-transaction-on-interval/</link>
		<comments>http://blog.sqlauthority.com/2010/10/04/sql-server-find-total-number-of-transaction-on-interval/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 01:30:46 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DMV]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=10377</guid>
		<description><![CDATA[In one of my recent Performance Tuning assignment I was asked how do someone know how many transactions are happening on server during certain interval. I had handy script for the same. Following script displays transactions happened on server at the interval of one minute. You can change the WAITFOR DELAY to any other interval [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10377&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">In one of my recent Performance Tuning assignment I was asked how do someone know how many transactions are happening on server during certain interval. I had handy script for the same. Following script displays transactions happened on server at the interval of one minute. You can change the WAITFOR DELAY to any other interval and it should work.</p>
<p><code style="font-size:12px;"><span style="color:green;">-- First PASS<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@First </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@Second </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@First </span><span style="color:blue;">= </span><span style="color:black;">cntr_value<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'MSSQL$SQLENT1:Databases' </span><span style="color:green;">-- Change name of your server<br />
</span><span style="color:gray;">AND </span><span style="color:black;">counter_name </span><span style="color:blue;">= </span><span style="color:red;">'Transactions/sec'<br />
</span><span style="color:gray;">AND </span><span style="color:black;">instance_name </span><span style="color:blue;">= </span><span style="color:red;">'_Total'</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Following is the delay<br />
</span><span style="color:blue;">WAITFOR </span><span style="color:black;">DELAY </span><span style="color:red;">'00:01:00'<br />
</span><span style="color:green;">-- Second PASS<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Second </span><span style="color:blue;">= </span><span style="color:black;">cntr_value<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'MSSQL$SQLENT1:Databases' </span><span style="color:green;">-- Change name of your server<br />
</span><span style="color:gray;">AND </span><span style="color:black;">counter_name </span><span style="color:blue;">= </span><span style="color:red;">'Transactions/sec'<br />
</span><span style="color:gray;">AND </span><span style="color:black;">instance_name </span><span style="color:blue;">= </span><span style="color:red;">'_Total'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">(</span><span style="color:#434343;">@Second </span><span style="color:gray;">- </span><span style="color:#434343;">@First</span><span style="color:gray;">) </span><span style="color:red;">'TotalTransactions'<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p>If you are using any other method to detect transactions per interval, I request you to post it over here.</p>
<p>Reference: <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/dmv/'>DMV</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-performance/'>SQL Performance</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/10377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/10377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/10377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10377&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/10/04/sql-server-find-total-number-of-transaction-on-interval/feed/</wfw:commentRss>
		<slash:comments>5</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 – Get Query Running in Session</title>
		<link>http://blog.sqlauthority.com/2010/10/01/sql-server-get-query-running-in-session/</link>
		<comments>http://blog.sqlauthority.com/2010/10/01/sql-server-get-query-running-in-session/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 01:30:01 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=10346</guid>
		<description><![CDATA[I was recently looking for syntax where I needed a query running in any particular session. I always remembered the syntax and ha d actually written it down before, but somehow it was not coming to mind quickly this time. I searched online and I ended up on my own article written last year SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10346&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I was recently looking for syntax where I needed a query running in any particular session. I always remembered the syntax and ha d actually written it down before, but somehow it was not coming to mind quickly this time. I searched online and I ended up on my own article written last year <a href="http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/" target="_blank"><strong>SQL SERVER – Get Last Running Query Based on SPID</strong></a>. I felt that I am getting old because I forgot this really simple syntax.</p>
<p style="text-align:justify;">This post is a refresher to me. I knew it was something so familiar since I have used this syntax so many times during my <a href="http://blog.sqlauthority.com/sql-server-performance-tuning/" target="_blank"><strong>performance tuning project</strong></a>.</p>
<p style="text-align:justify;">Run the following query to find out what the latest query that was executed in the session. There are various methods mentioned in my earlier post, so here I am picking only the one that I use most of the time.</p>
<p style="text-align:justify;">Please use Shortcut &#8211; CTRL+T or enable &#8220;result to text&#8221; in the resultset to get formatted output.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sqltext </span><span style="color:blue;">VARBINARY</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sqltext </span><span style="color:blue;">= </span><span style="color:black;">sql_handle<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysprocesses<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">spid </span><span style="color:blue;">= </span><span style="color:black;">(YourSessionID)<br />
</span><span style="color:blue;">SELECT TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:#434343;">@sqltext</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p style="text-align:justify;">You can find a range of active session IDs in your system by running system stored procedure sp_who2.</p>
<p style="text-align:justify;">The following is the resultset where I have selected the session id that is the same as from where I am running above statement.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sysprocesses.jpg" alt="" width="418" height="353" /></p>
<p style="text-align:justify;">Additionally, you can use following T-SQL script as well.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_connections<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">most_recent_sql_handle</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">session_id </span><span style="color:blue;">= </span><span style="color:gray;">(</span><span style="color:black;">yoursessionID</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sql-utility/'>SQL Utility</a>, <a href='http://blog.sqlauthority.com/category/sqlserver/'>SQLServer</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/10346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/10346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/10346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=10346&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/10/01/sql-server-get-query-running-in-session/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>

		<media:content url="http://www.pinaldave.com/bimg/sysprocesses.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER – Check the Isolation Level with DBCC useroptions</title>
		<link>http://blog.sqlauthority.com/2010/05/24/sql-server-check-the-isolation-level-with-dbcc-useroptions/</link>
		<comments>http://blog.sqlauthority.com/2010/05/24/sql-server-check-the-isolation-level-with-dbcc-useroptions/#comments</comments>
		<pubDate>Mon, 24 May 2010 01:30:47 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Transaction Isolation]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9061</guid>
		<description><![CDATA[In recent consultancy project coordinator asked me &#8211; &#8220;can you tell me what is the isolation level for this database?&#8221; I have worked with different isolation levels but have not ever queried database for the same. I quickly looked up bookonline and found out the DBCC command which can give me the same details. You [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9061&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">In recent consultancy project coordinator asked me &#8211; &#8220;can you tell me what is the isolation level for this database?&#8221; I have worked with different isolation levels but have not ever queried database for the same. I quickly looked up bookonline and found out the DBCC command which can give me the same details.</p>
<p style="text-align:justify;">You can run the DBCC UserOptions command on any database to get few details about dateformat, datefirst as well isolation level.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">useroptions</span></code></p>
<pre style="text-align:justify;">Set Option                  Value
--------------------------- --------------
textsize                    2147483647
language                    us_english
dateformat                  mdy
datefirst                   7
lock_timeout                -1
quoted_identifier           SET
arithabort                  SET
ansi_null_dflt_on           SET
ansi_warnings               SET
ansi_padding                SET
ansi_nulls                  SET
concat_null_yields_null     SET
isolation level             read committed</pre>
<p style="text-align:justify;">I thought this was very handy script, which I have not used earlier. Thanks Gary for asking right question.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sqlserver/'>SQLServer</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a> Tagged: <a href='http://blog.sqlauthority.com/tag/transaction-isolation/'>Transaction Isolation</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/9061/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/9061/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/9061/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=9061&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/05/24/sql-server-check-the-isolation-level-with-dbcc-useroptions/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; Find Max Worker Count using DMV &#8211; 32 Bit and 64 Bit</title>
		<link>http://blog.sqlauthority.com/2010/04/20/sql-server-find-max-worker-count-using-dmv-32-bit-and-64-bit/</link>
		<comments>http://blog.sqlauthority.com/2010/04/20/sql-server-find-max-worker-count-using-dmv-32-bit-and-64-bit/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 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 DMV]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=8630</guid>
		<description><![CDATA[During several recent training courses, I found it very interesting that Worker Thread is not quite known to everyone despite the fact that it is a very important feature. At some point in the discussion, one of the attendees mentioned that we can double the Worker Thread if we double the CPU (add the same [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=8630&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">During several recent training courses, I found it very interesting that Worker Thread is not quite known to everyone despite the fact that it is a very important feature. At some point in the discussion, one of the attendees mentioned that we can double the Worker Thread if we double the CPU (add the same number of CPU that we have on current system). The same discussion has triggered this quick article.</p>
<p style="text-align:justify;">Here is the DMV which can be used to find out Max Worker Count</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">max_workers_count<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_sys_info</span></code></p>
<p style="text-align:justify;">Let us run the above query on my system and find the results.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/maxworkercount.jpg" alt="" width="500" height="188" /></p>
<p style="text-align:justify;">As my system is 32 bit and I have two CPU, the Max Worker Count is displayed as 512.</p>
<p style="text-align:justify;">To address the previous discussion, adding more CPU does not necessarily double the Worker Count. In fact, the logic behind this simple principle is as follows:</p>
<p style="text-align:justify;">For x86 (32-bit) upto 4 logical processors  max worker threads = 256<br />
For x86 (32-bit) more than 4 logical processors  max worker threads = 256 + ((# Procs – 4) * 8)<br />
For x64 (64-bit) upto 4 logical processors  max worker threads = 512<br />
For x64 (64-bit) more than 4 logical processors  max worker threads = 512+ ((# Procs – 4) * 8)</p>
<p style="text-align:justify;">In addition to this, you can configure the Max Worker Thread by using SSMS.</p>
<p style="text-align:justify;">Go to Server Node &gt;&gt; Right Click and Select Property &gt;&gt; Select Process and modify setting under Worker Threads.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/maxworkersetting.jpg" alt="" width="500" height="630" /></p>
<p style="text-align:justify;">According to Book On Line, the default Worker Thread settings are appropriate for most of the systems.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-dmv/'>SQL DMV</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/8630/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/8630/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/8630/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=8630&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/04/20/sql-server-find-max-worker-count-using-dmv-32-bit-and-64-bit/feed/</wfw:commentRss>
		<slash:comments>5</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/maxworkercount.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/maxworkersetting.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Plan Recompilation and Reduce Recompilation &#8211; Performance Tuning</title>
		<link>http://blog.sqlauthority.com/2010/02/18/sql-server-plan-recompilation-and-reduce-recompilation-performance-tuning/</link>
		<comments>http://blog.sqlauthority.com/2010/02/18/sql-server-plan-recompilation-and-reduce-recompilation-performance-tuning/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 01:30:05 +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 Stored Procedure]]></category>
		<category><![CDATA[SQL System Table]]></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=8008</guid>
		<description><![CDATA[Recompilation process is same as compilation and degrades server performance. In SQL Server 2000 and earlier versions, this was a serious issue but in SQL server 2005, the severity of this issue has been significantly reduced by introducing a new feature called Statement-level recompilation. When SQL Server 2005 recompiles stored procedures, only the statement that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=8008&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Recompilation process is same as compilation and degrades server performance. In SQL Server 2000 and earlier versions, this was a serious issue but in SQL server 2005, the severity of this issue has been significantly reduced by introducing a new feature called Statement-level recompilation. When SQL Server 2005 recompiles stored procedures, only the statement that causes recompilation is compiled, rather than the entire procedure. Recompilation occurs because of following reason:</p>
<ul style="text-align:justify;">
<li><strong>On schema change of objects. </strong>
<ul>
<li>Adding or dropping column to/from a table or view</li>
<li>Adding or dropping constraints, defaults, or rules to or from a table.</li>
<li>Adding or dropping an index to a table or indexed view if index is used by the plan.</li>
<li>Adding or dropping trigger from a table</li>
<li>Dropping statistics from a table that is used in plan.</li>
</ul>
</li>
<li><strong>On change of the SET options:</strong> When a compiled plan is created, the SQL server also stores the environmental setting of a connection (SET option) with it. If the same stored procedure is executed by another connection that has a different SET option, then the existing cached plan is not reused. To reduce recompilation caused by Environment change, we should not change the SET options in the connection setting and stored procedure.</li>
<li><strong>On statistics change of tables:</strong> Every time the SQL Server uses an already cached compiled plan, it checks the optimality before using it. SQL Server decides whether the plan is optimal for current amount of data in underlying tables. It could be that the data amount in underlying tables changed so much that the previously created plan is not optimized. For each table &amp; index, the SQL server maintains a modification counter and if the counter values exceed the defined threshold, the previously created compiled plan is considered stale plan and a new plan is created.</li>
</ul>
<p style="text-align:justify;"><strong>Detecting recompilations:</strong> The below query retrieves the top 10 statements for which the recompilation count is maximum. Here, plan_generation_num returns a number that indicates the recompilation count of a statement.</p>
<p style="padding-left:30px;text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT TOP </span><span style="color:black;">10<br />
qs.plan_generation_num</span><span style="color:gray;">,<br />
</span><span style="color:black;">qs.execution_count</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DB_NAME</span><span style="color:gray;">(</span><span style="color:black;">st.dbid</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">DbName</span><span style="color:gray;">,<br />
</span><span style="color:black;">st.objectid</span><span style="color:gray;">,<br />
</span><span style="color:black;">st.</span><span style="color:blue;">TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_query_stats qs<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">sql_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">st<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">plan_generation_num </span><span style="color:blue;">DESC</span></code></p>
<p style="text-align:justify;">Another tool is to get recompilation details is the SQL Profiler. Along with the statements text, it also tells the reason of recompilation in EventClass and EventSubClass columns.</p>
<p style="text-align:justify;"><strong>Reducing recompilations: </strong>We have no option to avoid “schema change” and “SET options” based recompilation. But we have following query and stored procedure hints to avoid “statistics change” based recompilation:</p>
<ul style="text-align:justify;">
<li> <strong>KEEP PLAN hint:</strong> The modification counter threshold for a temporary table is 6. This implies that when a stored procedure that creates a temporary table inserts 6 or more rows into this table, Stored Procedures will be recompiled as soon as this table is accessed. For permanent tables, this threshold is at least 500. We can increase the first threshold for the temporary table (6) to same as that of the permanent table (500) by using the KEEP PLAN query hint in the statement where the temporary table is used. For example,</li>
</ul>
<p style="padding-left:60px;text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">TT.col4</span><span style="color:gray;">, </span><span style="color:magenta;">SUM</span><span style="color:gray;">(</span><span style="color:black;">PermTable.col1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.PermTable<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:#434343;">#TempTable </span><span style="color:blue;">AS </span><span style="color:black;">TT<br />
</span><span style="color:blue;">ON </span><span style="color:black;">PermTable.col1 </span><span style="color:blue;">= </span><span style="color:black;">TT.col2<br />
</span><span style="color:blue;">OPTION </span><span style="color:gray;">(</span><span style="color:black;">KEEP </span><span style="color:blue;">PLAN</span><span style="color:gray;">);</span></code></p>
<ul style="text-align:justify;">
<li> <strong>KEEPFIXED PLAN hint:</strong> This hint completely avoids “statistics change” based recompilation of a query.</li>
</ul>
<p style="padding-left:60px;text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">col1</span><span style="color:gray;">, </span><span style="color:black;">col2<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.PermTable<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">col3 </span><span style="color:gray;">&amp;</span><span style="color:black;">lt</span><span style="color:gray;">; </span><span style="color:black;">100<br />
</span><span style="color:blue;">OPTION </span><span style="color:gray;">(</span><span style="color:black;">KEEPFIXED </span><span style="color:blue;">PLAN</span><span style="color:gray;">);</span></code></p>
<ul style="text-align:justify;">
<li> <strong>Use Table variable instead of temporary tables:</strong> Because a change in cardinality of a table variable does not cause recompilations, consider using a table variable instead of a temporary table when faced with a problem of excessive recompilation. However, the use of table variables can lead to poorer query plans. Distribution statistics are not stored for table variables, and cardinality is only available during recompilation and not during initial compilation. One has to check whether this is the case and make an appropriate trade-off.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/sql-index/'>SQL Index</a>, <a href='http://blog.sqlauthority.com/category/sql-optimization/'>SQL Optimization</a>, <a href='http://blog.sqlauthority.com/category/sql-performance/'>SQL Performance</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-stored-procedure/'>SQL Stored Procedure</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/8008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/8008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/8008/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=8008&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/02/18/sql-server-plan-recompilation-and-reduce-recompilation-performance-tuning/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; Find the Size of Database File &#8211; Find the Size of Log File</title>
		<link>http://blog.sqlauthority.com/2010/02/08/sql-server-find-the-size-of-database-file-find-the-size-of-log-file/</link>
		<comments>http://blog.sqlauthority.com/2010/02/08/sql-server-find-the-size-of-database-file-find-the-size-of-log-file/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 01:30:47 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Log File]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7954</guid>
		<description><![CDATA[I encountered the situation recently where I needed to find the size of the log file. When I tried to find the script by using Search@SQLAuthority.com I was not able to find the script at all. Here is the script, if you remove the WHERE condition you will find the result for all the databases. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7954&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I encountered the situation recently where I needed to find the size of the log file. When I tried to find the script by using Search@SQLAuthority.com I was not able to find the script at all. Here is the script, if you remove the WHERE condition you will find the result for all the databases.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">DB_NAME</span><span style="color:gray;">(</span><span style="color:black;">database_id</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">DatabaseName</span><span style="color:gray;">,<br />
</span><span style="color:black;">Name </span><span style="color:blue;">AS </span><span style="color:black;">Logical_Name</span><span style="color:gray;">,<br />
</span><span style="color:black;">Physical_Name</span><span style="color:gray;">, (</span><span style="color:black;">size</span><span style="color:gray;">*</span><span style="color:black;">8</span><span style="color:gray;">)/</span><span style="color:black;">1024 SizeMB<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.master_files<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">DB_NAME</span><span style="color:gray;">(</span><span style="color:black;">database_id</span><span style="color:gray;">) </span><span style="color:blue;">= </span><span style="color:red;">'AdventureWorks'<br />
</span><span style="color:black;">GO</span></code></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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sqlserver/'>SQLServer</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a> Tagged: <a href='http://blog.sqlauthority.com/tag/sql-log-file/'>SQL Log File</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7954/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7954/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7954/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7954&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/02/08/sql-server-find-the-size-of-database-file-find-the-size-of-log-file/feed/</wfw:commentRss>
		<slash:comments>24</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; Get the List of Object Dependencies &#8211; sp_depends and information_schema.routines and sys.dm_sql_referencing_entities</title>
		<link>http://blog.sqlauthority.com/2010/02/04/sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/</link>
		<comments>http://blog.sqlauthority.com/2010/02/04/sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 01:30:43 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=7890</guid>
		<description><![CDATA[Recently, I read a question on my friend Ritesh Shah&#8216;s SQL site regarding the following: sp_depends does not give appropriate results whereas information_schema.routines does give proper answer. I have quite often seen that information_schema.routines gives proper dependency relationship where assp_depends returns an incorrect answer. However, as per book online sp_depends will be deprecated, and instead, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7890&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Recently, I read a question on my friend <a href="http://www.sqlhub.com/2010/01/spdepends-is-very-useful-stored.html" target="_blank">Ritesh Shah</a>&#8216;s SQL site regarding the following: sp_depends does not give appropriate results whereas information_schema.routines does give proper answer.</p>
<p style="text-align:justify;">I have quite often seen that information_schema.routines gives proper dependency relationship where assp_depends returns an incorrect answer. However, as per book online sp_depends will be deprecated, and instead, sys.dm_sql_referencing_entities and sys.dm_sql_referenced_entities are recommended.</p>
<p style="text-align:justify;">Let us quickly see where sp_depends fail and other solutions work fine.</p>
<p style="text-align:justify;">Let us first create two scenarios.</p>
<p style="text-align:justify;"><strong>Scenario 1: Normal Table Creation Order, where objects are created first and then used afterwords.</strong></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:blue;">CREATE TABLE </span><span style="color:black;">dbo.TestTable<br />
</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;">Name </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;">-- dbo.First is not created yet<br />
</span><span style="color:blue;">CREATE PROCEDURE </span><span style="color:black;">dbo.Second<br />
</span><span style="color:blue;">AS<br />
EXEC </span><span style="color:black;">dbo.First<br />
GO<br />
</span><span style="color:blue;">CREATE PROCEDURE </span><span style="color:black;">dbo.First<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;">Name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TestTable<br />
GO<br />
</span></code></p>
<p style="text-align:justify;"><strong>Scenario 2: Objects are created afterwords and they are referenced first.</strong></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:blue;">CREATE TABLE </span><span style="color:black;">dbo.TestTable<br />
</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;">Name </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:blue;">CREATE PROCEDURE </span><span style="color:black;">dbo.First<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;">Name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TestTable<br />
GO<br />
</span><span style="color:green;">-- dbo.First is already created<br />
</span><span style="color:blue;">CREATE PROCEDURE </span><span style="color:black;">dbo.Second<br />
</span><span style="color:blue;">AS<br />
EXEC </span><span style="color:black;">dbo.First<br />
GO</span></code></p>
<p style="text-align:justify;">Now let us run following three queries on both the scenarios.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Method 1: Using sp_depends<br />
</span><span style="color:darkred;">sp_depends </span><span style="color:red;">'dbo.First'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Method 2: Using information_schema.routines<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">information_schema.routines ISR<br />
</span><span style="color:blue;">WHERE CHARINDEX</span><span style="color:gray;">(</span><span style="color:red;">'dbo.First'</span><span style="color:gray;">, </span><span style="color:black;">ISR.ROUTINE_DEFINITION</span><span style="color:gray;">) &gt; </span><span style="color:black;">0<br />
GO<br />
</span><span style="color:green;">-- Method 3: Using DMV sys.dm_sql_referencing_entities<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">referencing_schema_name</span><span style="color:gray;">, </span><span style="color:black;">referencing_entity_name</span><span style="color:gray;">,<br />
</span><span style="color:black;">referencing_id</span><span style="color:gray;">, </span><span style="color:black;">referencing_class_desc</span><span style="color:gray;">, </span><span style="color:black;">is_caller_dependent<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_sql_referencing_entities </span><span style="color:gray;">(</span><span style="color:red;">'dbo.First'</span><span style="color:gray;">, </span><span style="color:red;">'OBJECT'</span><span style="color:gray;">);<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><strong>Result from Scenario 1</strong></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sp_depends1.jpg" alt="" width="500" height="410" /></p>
<p style="text-align:justify;"><strong>Result from Scenario 2</strong></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/sp_depends2.jpg" alt="" width="500" height="393" /></p>
<p style="text-align:justify;">It is clear that sp_depends does not give proper/correct results when the object creation order is different or following deferred name resolution.</p>
<p style="text-align:justify;">I suggest the use of the third method, in which sys.dm_sql_referencing_entities is used.</p>
<p style="text-align:justify;">Use the following script to get correct dependency:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">referencing_schema_name</span><span style="color:gray;">, </span><span style="color:black;">referencing_entity_name</span><span style="color:gray;">,<br />
</span><span style="color:black;">referencing_id</span><span style="color:gray;">, </span><span style="color:black;">referencing_class_desc</span><span style="color:gray;">, </span><span style="color:black;">is_caller_dependent<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_sql_referencing_entities </span><span style="color:gray;">(</span><span style="color:red;">'YourObject'</span><span style="color:gray;">, </span><span style="color:red;">'OBJECT'</span><span style="color:gray;">);<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Let me know the type of scripts you use for finding Object Dependencies. I will post your script with due credit.</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>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/readers-question/'>Readers Question</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/tech/sql-scripts/'>SQL Scripts</a>, <a href='http://blog.sqlauthority.com/category/sql-security/'>SQL Security</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sqlserver/'>SQLServer</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7890/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7890/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7890/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7890&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/02/04/sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/feed/</wfw:commentRss>
		<slash:comments>31</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_depends1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/sp_depends2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Location of Resource Database in SQL Server Editions</title>
		<link>http://blog.sqlauthority.com/2010/01/31/sql-server-location-of-resource-database-in-sql-server-editions/</link>
		<comments>http://blog.sqlauthority.com/2010/01/31/sql-server-location-of-resource-database-in-sql-server-editions/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 01:30:56 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=7881</guid>
		<description><![CDATA[While working on project of database backup and recovery, I found out that my client was not aware of the resource database at all. The Resource database is a read-only database that contains all the system objects that are included with SQL Server. Location of this database is at different places in the different version [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7881&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">While working on project of database backup and recovery, I found out that my client was not aware of the resource database at all. The Resource database is a read-only database that contains all the system objects that are included with SQL Server.</p>
<p style="text-align:justify;">Location of this database is at different places in the different version of SQL Server.</p>
<p style="text-align:justify;"><strong>In SQL Server 2008:</strong></p>
<p style="text-align:justify;"><em>&lt;drive&gt;</em>:\Program Files\Microsoft SQL Server\MSSQL10.<em>&lt;instance_name&gt;</em>\Binn\.<br />
The <strong>Resource</strong> database cannot be moved.</p>
<p style="text-align:justify;">
<div class="mceTemp" style="text-align:justify;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><img title="ResourceDB location in SQL Server 2008" src="http://www.pinaldave.com/bimg/resourcedb.jpg" alt="ResourceDB location in SQL Server 2008" width="501" height="151" /></dt>
<dd class="wp-caption-dd">ResourceDB location in SQL Server 2008</dd>
</dl>
</div>
<p style="text-align:justify;">
<p style="text-align:justify;"><strong>In SQL Server 2005:</strong></p>
<p style="text-align:justify;">Same place where master database is located.<br />
The <strong>Resource</strong> database have to move with master database.</p>
<p style="text-align:justify;">You can run following commands to know resourcedb version and last updated time.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">SERVERPROPERTY</span><span style="color:gray;">(</span><span style="color:red;">'ResourceVersion'</span><span style="color:gray;">) </span><span style="color:black;">ResourceVersion</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">SERVERPROPERTY</span><span style="color:gray;">(</span><span style="color:red;">'ResourceLastUpdateDateTime'</span><span style="color:gray;">) </span><span style="color:black;">ResourceLastUpdateDateTime<br />
GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/resourcedbver.jpg" alt="" width="604" height="157" /></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>
<dl>
<dt> </dt>
</dl>
<br />Filed under: <a href='http://blog.sqlauthority.com/category/tech/pinal-dave/'>Pinal Dave</a>, <a href='http://blog.sqlauthority.com/category/technology/sql/'>SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-authority/'>SQL Authority</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-query/'>SQL Query</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-server/'>SQL Server</a>, <a href='http://blog.sqlauthority.com/category/sql-system-table/'>SQL System Table</a>, <a href='http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/'>SQL Tips and Tricks</a>, <a href='http://blog.sqlauthority.com/category/sqlserver/'>SQLServer</a>, <a href='http://blog.sqlauthority.com/category/technology/t-sql/'>T SQL</a>, <a href='http://blog.sqlauthority.com/category/technology/'>Technology</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7881/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7881/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7881/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7881&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2010/01/31/sql-server-location-of-resource-database-in-sql-server-editions/feed/</wfw:commentRss>
		<slash:comments>9</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/resourcedb.jpg" medium="image">
			<media:title type="html">ResourceDB location in SQL Server 2008</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/resourcedbver.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Recently Executed T-SQL Query</title>
		<link>http://blog.sqlauthority.com/2009/10/16/sql-server-recently-executed-t-sql-query/</link>
		<comments>http://blog.sqlauthority.com/2009/10/16/sql-server-recently-executed-t-sql-query/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 01:30:59 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DMV]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=7073</guid>
		<description><![CDATA[About a year ago, I wrote blog post about SQL SERVER – 2005 – Last Ran Query – Recently Ran Query.  Since, then I have received many question regarding how this is better than fn_get_sql() or DBCC INPUTBUFFER. The Short Answer in is both of them will be deprecated. Please refer to following update query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7073&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">About a year ago, I wrote blog post about <a href="http://blog.sqlauthority.com/2008/01/03/sql-server-2005-last-ran-query-recently-ran-query/" target="_blank">SQL SERVER – 2005 – Last Ran Query – Recently Ran Query</a>.  Since, then I have received many question regarding how this is better than fn_get_sql() or DBCC INPUTBUFFER.</p>
<p style="text-align:justify;"><em>The Short Answer in is both of them will be deprecated. </em></p>
<p style="text-align:justify;">Please refer to following update query to recently executed T-SQL query on database.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">deqs.last_execution_time </span><span style="color:blue;">AS </span><span style="color:black;">[Time]</span><span style="color:gray;">, </span><span style="color:black;">dest.</span><span style="color:blue;">TEXT AS </span><span style="color:black;">[Query]<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_query_stats </span><span style="color:blue;">AS </span><span style="color:black;">deqs<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">deqs.sql_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">dest<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">deqs.last_execution_time </span><span style="color:blue;">DESC</span></code></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;">
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL DMV, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7073/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7073/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7073/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=7073&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/16/sql-server-recently-executed-t-sql-query/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 SERVER &#8211; Get Query Plan Along with Query Text and Execution Count</title>
		<link>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/</link>
		<comments>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 01:30:15 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=6619</guid>
		<description><![CDATA[Quite often, we need to know how many any particular objects have been executed on our server and what their execution plan is. I use the following handy script, which I use when I need to know the details regarding how many times any query has ran on my server along with its execution plan. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=6619&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Quite often, we need to know how many any particular objects have been executed on our server and what their execution plan is. I use the following handy script, which I use when I need to know the details regarding how many times any query has ran on my server along with its execution plan. You can add an additional WHERE condition if you want to learn about any specific object.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">cp.objtype </span><span style="color:blue;">AS </span><span style="color:black;">ObjectType</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:black;">st.objectid</span><span style="color:gray;">,</span><span style="color:black;">st.dbid</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">ObjectName</span><span style="color:gray;">,<br />
</span><span style="color:black;">cp.usecounts </span><span style="color:blue;">AS </span><span style="color:black;">ExecutionCount</span><span style="color:gray;">,<br />
</span><span style="color:black;">st.</span><span style="color:blue;">TEXT AS </span><span style="color:black;">QueryText</span><span style="color:gray;">,<br />
</span><span style="color:black;">qp.query_plan </span><span style="color:blue;">AS </span><span style="color:black;">QueryPlan<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_cached_plans </span><span style="color:blue;">AS </span><span style="color:black;">cp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_query_plan</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">qp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">st<br />
</span><span style="color:green;">--WHERE OBJECT_NAME(st.objectid,st.dbid) = 'YourObjectName'</span></code>
</p>
<p style="text-align:justify;">In result set, you will find the last column QueryPlan with XML text in it. Click on it, and it will open a new tab displaying the graphical execution plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/explan1.jpg" alt="" width="500" height="508" /></p>
<p style="text-align:justify;">You can also save the newly opened tab in XML format with the extension .sqlplan. When this new file is opened in SQL Server Management Studio, it will automatically display the graphical representation of the XML Plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/explan2.jpg" alt="" width="500" height="170" /></p>
<p style="text-align:justify;">It is a quite simple script, but it works all the time.</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;">
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6619/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=6619&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/feed/</wfw:commentRss>
		<slash:comments>11</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/explan1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/explan2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Measure CPU Pressure &#8211; CPU Business</title>
		<link>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/</link>
		<comments>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/#comments</comments>
		<pubDate>Mon, 17 Aug 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 Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=6601</guid>
		<description><![CDATA[Many a time, DBAs face the following question: can the CPU handle the current transaction? I have seen many DBAs getting confused on whether they should get a CPU with higher clock speed or more number of CPUs when it is time to upgrade system. As we all know, the CPU (or the Central Processing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=6601&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Many a time, DBAs face the following question: can the CPU handle the current transaction? I have seen many DBAs getting confused on whether they should get a CPU with higher clock speed or more number of CPUs when it is time to upgrade system. As we all know, the CPU (or the Central Processing Unit) is the core of any system. The CPU is responsible for not only SQL Server operations but also all the OS (Operating System) tasks related to the CPU on the server.</p>
<p style="text-align:justify;">It is quite possible that although we are running very few operations on our SQL Server, we still do not obtain the expected results. This is when the SQL Server CPU has to be checked. Again, please note that I am not suggesting that the CPU is the root cause of poor performance in this case. There are ample chances that the Memory, Input/Output or Tempdb can be responsible for performance degradation. However, to find out the “real” culprit, we must run a test; here, we intend to start running tests on the CPU.</p>
<p style="text-align:justify;">Let us understand the simple meaning of CPU pressure. <strong><em>CPU pressure is a state wherein the CPU is fully occupied with currently assigned tasks and there are more tasks in the queue that have not yet started.</em></strong></p>
<p style="text-align:justify;">We can run several different types of queries to test the CPU. However, my personal favorite is the following one. The resultset will contain as many rows as those being used by the CPU SQL Server.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:black;">scheduler_id</span><span style="color:gray;">,<br />
</span><span style="color:black;">cpu_id</span><span style="color:gray;">,<br />
</span><span style="color:black;">current_tasks_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">runnable_tasks_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">current_workers_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">active_workers_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">work_queue_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">pending_disk_io_count<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_schedulers<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">scheduler_id </span><span style="color:gray;">&lt; </span><span style="color:black;">255</span><span style="color:gray;">;</span></code>
</p>
<p style="text-align:justify;">Above query will give result something like following.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/cpupress.jpg" alt="" width="494" height="308" /></p>
<p style="text-align:justify;">Before we go ahead, let us familiarize ourselves with the terms. First of all, we should understand what a “scheduler” refers to in the SQL Server. Each SQL Server instance behaves and acts like any OS internally. It has schedules and also it synchronizes concurrent tasks by itself without going to OS. Each instance can handle many concurrent requests. However, there is a point at which the instance cannot accept any more requests. SQL Servers have dynamic management view (DMV), which in fact keeps a log of all the scheduler-related tasks and also it provides a good idea about the CPU pressure.</p>
<p style="text-align:justify;">current_tasks_count is the number of counts of the currently running task. However, we should give utmost consideration to runnable_tasks_count. If this number is higher, it indicates that a large number of queries, which are assigned to the scheduler for processing, are waiting for its turn to run. This gives a clear indication of the CPU pressure. Additionally, count pending_disk_io_count displays the tasks that are yet to be processed in the scheduler. For better processing, this count is expected not to be very high.</p>
<p style="text-align:justify;">When we say that the numbers are high or low, it does not make any sense unless we compare it to a standard or any other known count. Therefore, here, these numbers are compared to the worker counts (current_worker_count). If current_worker_count is 24 and there are 1000 tasks in queue, then this is not a good scenario. Thus, you can always look at the numbers and make your own judgement here.</p>
<p style="text-align:justify;">Well, in this article, I have done a lot of talking with very little script. Please do let me know your opinions regarding whether this was simple enough to convey the message regarding CPU pressure.</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;">
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6601/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=6601&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/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/cpupress.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Get Last Running Query Based on SPID</title>
		<link>http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/</link>
		<comments>http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 01:30:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL System Table]]></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=5934</guid>
		<description><![CDATA[We often need to find the last running query or based on SPID need to know which query was executed. SPID is returns sessions ID of the current user process. The acronym SPID comes from the name of its earlier version, Server Process ID. To know which sessions are running currently, run the following command: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5934&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">We often need to find the last running query or based on SPID need to know which query was executed. SPID is returns sessions ID of the current user process. The acronym SPID comes from the name of its earlier version, Server Process ID.</p>
<p style="text-align:justify;">To know which sessions are running currently, run the following command:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:#434343;">@@SPID<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">In our case, we got SPID 57, which means the session that is running this command has ID of 57.</p>
<p style="text-align:justify;">Now, let us open another session and run the same command. Here we get different IDs for different sessions.</p>
<p style="text-align:justify;">In our case, we got SPID 61. Please note here that this ID may or may not be sequential.</p>
<p style="text-align:justify;">In session with SPID 61, we will run any query. In session with SPID 57, we will see which query was run in session with SPID 61.</p>
<p style="text-align:justify;">Let us run a simple SELECT statement in session with SPID 61 and in session with SPID 57 run the following command.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">INPUTBUFFER</span><span style="color:gray;">(</span><span style="color:black;">61</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">Now, here in DBCC command we have passed the SPID of previous session; we will see the text below. The following image illustrates that we get the latest run query in our input buffer.</p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/spid1.png" alt="" width="500" height="206" /><br />
</span>
</p>
<p style="text-align:justify;">There are several ways to find out what is the latest run query from system table sys.sysprocesses.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sqltext </span><span style="color:black;">VARBINARY</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sqltext </span><span style="color:blue;">= </span><span style="color:black;">sql_handle<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysprocesses<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">spid </span><span style="color:blue;">= </span><span style="color:black;">61<br />
</span><span style="color:blue;">SELECT TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:#434343;">@sqltext</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code>
</p>
<p style="text-align:justify;">The following image portrays that we get the latest run query in our input buffer.</p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/spid2.png" alt="" width="500" height="298" /><br />
</span></p>
<p>Please note that in any session there may be multiple running queries, but the buffer only saves the last query and that is what we will be able to retrieve.</p>
<p>There is one more way to achieve the same thing &#8211; using function fn_get_sql
</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@sqltext </span><span style="color:black;">VARBINARY</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@sqltext </span><span style="color:blue;">= </span><span style="color:black;">sql_handle<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysprocesses<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">spid </span><span style="color:blue;">= </span><span style="color:black;">61<br />
</span><span style="color:blue;">SELECT TEXT<br />
FROM </span><span style="color:gray;">::</span><span style="color:darkred;">fn_get_sql</span><span style="color:gray;">(</span><span style="color:#434343;">@sqltext</span><span style="color:gray;">)<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/spid3.png" alt="" width="500" height="321" /><br />
</span></p>
<p>All the three methods are same but I always prefer method 2 where I have used sys.sysprocesses.</p>
<p>Today, we have explored a very simple topic. Let me know if you find it useful.
</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>
<p style="text-align:justify;">
<p style="text-align:justify;"><span style="color:black;"> </span></p>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5934/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5934&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/feed/</wfw:commentRss>
		<slash:comments>21</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/spid1.png" medium="image" />

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

		<media:content url="http://www.pinaldave.com/bimg/spid3.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Performance Counters from System Views &#8211; By Kevin Mckenna</title>
		<link>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/</link>
		<comments>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 01:30:56 +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 Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=5407</guid>
		<description><![CDATA[I just love social media and all the new concepts of Web 2.0. There are bloggers who are overwhelmed by the new concepts of technology and are not able to keep pace with it. But I like taking such challenges. Twitter has acquired tremendous popularity nowadays and just like everybody else I am also fond [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5407&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I just love social media and all the new concepts of Web 2.0. There are bloggers who are overwhelmed by the new concepts of technology and are not able to keep pace with it. But I like taking such challenges. Twitter has acquired tremendous popularity nowadays and just like everybody else I am also fond of this latest vogue. You can <a href="http://twitter.com/pinaldave" target="_blank">follow me</a> at Twitter <a href="http://twitter.com/pinaldave" target="_blank">here</a>. Through twitter I am getting to meet people like me and it’s a great experience interacting with them. I met SQL and .NET expert <strong><a href="http://twitter.com/kev_mck" target="_blank"><strong>Kevin Mckenna</strong></a></strong> on twitter itself.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/kevmck.jpg" alt="" width="200" height="139" /></p>
<p style="text-align:justify;">Kevin is originally from Liverpool, England, and moved to the US in December 2005. He is a DBA for a large warehousing and logistics company based in the US. He has been developing software with SQL backends for approximately 6-7 years, and has been administrating SQL and Oracle databases for the past 4 years.</p>
<p style="text-align:justify;">He is married and has 2 children.  He is a huge football (soccer for the Americans) fan, and when he is not working, he likes spending his time either reading or playing on <a href="http://twitter.com/kev_mck" target="_blank">twitter</a>.</p>
<p style="text-align:justify;">He has recently sent me a very interesting note on Performance Counters from System Views. I really enjoyed reading it and with his permission I am publishing the content here. Let me have your opinion on this.</p>
<p style="text-align:justify;">Many of you are not aware of this fact that access to performance information is readily available in SQL Server and that too without querying performance counters using a custom application or via perfmon. Till now, this fact has remained undisclosed but through this post I would like to explain you can easily access SQL Server performance counter information.</p>
<p style="text-align:justify;">Without putting much effort you will come across the system view <strong>sys.dm_os_performance_counters</strong>. As the name suggests, this provides you easy access to the SQL Server performance counter information that is passed on to perfmon, but you can get at it via tsql.</p>
<p style="text-align:justify;">You can start with a few simple steps:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters</span></code></p>
<p style="text-align:justify;">This returns 701 rows of data on the test machine, with information from Buffer Manager, Buffer Partition, Buffer Node, General Statistics, Locks, and so forth.</p>
<p style="text-align:justify;">I’ll try to make you all understand by making it a bit more simple. Here, we will concentrate on Buffer Manager.</p>
<p style="text-align:justify;">Please note that if you have an instance name, the object name will be MSSQLlt;instance name&gt;: instead of SQLServer:</p>
<p style="text-align:justify;">The next step is</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_performance_counters </span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'SQLServer:Buffer Manager'</span></code></p>
<p style="text-align:justify;">The following screen will be displayed.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/Pcount.png" alt="" width="547" height="449" /><span>XX</span></p>
<p style="text-align:justify;">As you all can notice, what is displayed above via tsql is similar to what is available via perfmon</p>
<p style="text-align:justify;">Let’s take a look at the columns returned:</p>
<p style="text-align:justify;"><strong>field name</strong> data type Description<br />
<strong>object_name</strong> nchar(128) Category to which this counter belongs<br />
<strong>counter_name</strong> nchar(128) Name of the counter<br />
<strong>instance_name </strong>nchar(128) Name of the specific instance of the counter. Often contains the database name<br />
<strong>cntr_value</strong> bigint Current value of the counter<br />
<strong>cntr_type</strong> int Type of counter as defined by the Windows performance architecture
</p>
<p style="text-align:justify;">Now, if you all are wondering what can be done with this information then let me tell you that you have a few things options. We can create a job that will sample a particular value on a timed basis and add it to a table, and view an average value from it. Another option is to just take a glance at it for peace of mind!</p>
<p style="text-align:justify;">One of the most useful things we could derive from this however is trend information.  For example, let’s chart the number of Active Transactions during the work day.</p>
<p style="text-align:justify;">We will start with creating a table, as given below.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:black;">ActiveTrans_sqlGenus </span><span style="color:gray;">(<br />
</span><span style="color:black;">obj_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">counter_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">instance_name </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">),<br />
</span><span style="color:black;">cntr_value bigint</span><span style="color:gray;">,<br />
</span><span style="color:black;">cntr_type </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">datestamp datetime<br />
</span><span style="color:gray;">)</span></code>
</p>
<p style="text-align:justify;">We can then fill up this table on a timed basis:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">INSERT INTO </span><span style="color:black;">ActiveTrans_sqlGenus<br />
</span><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">, </span><span style="color:black;">counter_name</span><span style="color:gray;">, </span><span style="color:black;">instance_name</span><span style="color:gray;">, </span><span style="color:black;">cntr_value</span><span style="color:gray;">,<br />
</span><span style="color:black;">cntr_type</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:black;">sys.dm_os_performance_counters<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:magenta;">OBJECT_NAME </span><span style="color:blue;">= </span><span style="color:red;">'SQLServer:Databases'<br />
</span><span style="color:black;">ANDcounter_name </span><span style="color:blue;">= </span><span style="color:red;">'Active Transactions'<br />
</span><span style="color:black;">ANDinstance_name </span><span style="color:blue;">= </span><span style="color:red;">'sqlGenus'</span></code>
</p>
<p style="text-align:justify;">Here, let’s assume that we are inserting into this table on a consistent basis. We can then issue the following command:</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT</span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">ActiveTrans_sqlGenus<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">datestamp </span><span style="color:gray;">BETWEEN </span><span style="color:red;">'06/02/2009 09:00' </span><span style="color:gray;">AND </span><span style="color:red;">'06/02/2009 17:00'</span></code>
</p>
<p style="text-align:justify;">After that, we can retrieve all the entries between 9am and 5pm, our fictitious work day.</p>
<p style="text-align:justify;">We could manipulate this data even further, averaging out the values, pulling the MAX and MIN and so on.</p>
<p style="text-align:justify;">Obviously, this is a very simple example, and certainly not the best way to store this information over a period of time. However, with some digging into just what you need, you can provide access to your SQL Server performance in a remarkably simple manner.</p>
<p style="text-align:justify;">The biggest disappointment in obtaining this information from SQL Server’s system views is that it only provides SQL Server information, so we do not receive information like Processor, Network and Disk information.  These values still need to be pulled via Performance Counters.  But despite this negative aspect, this view will provide ample usable information to keep your database in an excellent shape.</p>
<p style="text-align:justify;">
You can find more information on this system view from MSDN:
</p>
<p style="text-align:justify;"><a href="http://msdn.microsoft.com/en-us/library/ms187743%28SQL.90%29.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms187743(SQL.90).aspx</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>
<br />Posted in Pinal Dave, Readers Contribution, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5407/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5407&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/10/sql-server-performance-counters-from-system-views-by-kevin-mckenna/feed/</wfw:commentRss>
		<slash:comments>8</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/kevmck.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/Pcount.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; List All Objects Created on All Filegroups in Database</title>
		<link>http://blog.sqlauthority.com/2009/06/01/sql-server-list-all-objects-created-on-all-filegroups-in-database/</link>
		<comments>http://blog.sqlauthority.com/2009/06/01/sql-server-list-all-objects-created-on-all-filegroups-in-database/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 01:30:51 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=5300</guid>
		<description><![CDATA[When I pen down any article I always keep my readers in my mind. With every topic of SQL server I cover, I try to bring readers closer to this technology. So, whenever I receive follow up questions from my readers I am exhilarated! Sometime back I had covered a topic &#8211; SQL SERVER – [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5300&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">When I pen down any article I always keep my readers in my mind. With every topic of SQL server I cover, I try to bring readers closer to this technology. So, whenever I receive follow up questions from my readers I am exhilarated! Sometime back I had covered a topic &#8211; <strong><a href="http://blog.sqlauthority.com/2009/05/31/sql-server-create-multiple-filegroup-for-single-database/" target="_blank">SQL SERVER – Create Multiple Filegroup For Single Database</a></strong>, for which I received a number of follow up questions. In this post I would like to discuss on a question from one of the readers Joginder &#8220;Jogi&#8221; Padiyala.</p>
<p style="text-align:justify;"><strong>“How can I find which object belongs to which filegroup. Is there any way to know this?&#8221;</strong></p>
<p style="text-align:justify;">Well, finding out which object belongs to which table is very simple.<br />
Let us first create a database having multiple filegroups.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Create Database<br />
Please note that there are two Filegroups for newly created datbase.<br />
MDF - Primary and LDF on Secondary */<br />
</span><span style="color:blue;">CREATE DATABASE </span><span style="color:black;">[FGTest] </span><span style="color:blue;">ON  PRIMARY<br />
</span><span style="color:gray;">( </span><span style="color:black;">NAME </span><span style="color:blue;">= </span><span style="color:red;">N'FGTest'</span><span style="color:gray;">,<br />
</span><span style="color:black;">FILENAME </span><span style="color:blue;">= </span><span style="color:red;">N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest.mdf' </span><span style="color:gray;">,<br />
</span><span style="color:black;">SIZE </span><span style="color:blue;">= </span><span style="color:black;">3072KB </span><span style="color:gray;">, </span><span style="color:black;">FILEGROWTH </span><span style="color:blue;">= </span><span style="color:black;">1024KB </span><span style="color:gray;">),<br />
</span><span style="color:black;">FILEGROUP [Secondary]<br />
</span><span style="color:gray;">( </span><span style="color:black;">NAME </span><span style="color:blue;">= </span><span style="color:red;">N'FGTest_2'</span><span style="color:gray;">,<br />
</span><span style="color:black;">FILENAME </span><span style="color:blue;">= </span><span style="color:red;">N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest_2.ndf' </span><span style="color:gray;">,<br />
</span><span style="color:black;">SIZE </span><span style="color:blue;">= </span><span style="color:black;">3072KB </span><span style="color:gray;">, </span><span style="color:black;">FILEGROWTH </span><span style="color:blue;">= </span><span style="color:black;">1024KB </span><span style="color:gray;">)<br />
</span><span style="color:magenta;">LOG </span><span style="color:blue;">ON<br />
</span><span style="color:gray;">( </span><span style="color:black;">NAME </span><span style="color:blue;">= </span><span style="color:red;">N'FGTest_log'</span><span style="color:gray;">,<br />
</span><span style="color:black;">FILENAME </span><span style="color:blue;">= </span><span style="color:red;">N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\FGTest_log.ldf' </span><span style="color:gray;">,<br />
</span><span style="color:black;">SIZE </span><span style="color:blue;">= </span><span style="color:black;">1024KB </span><span style="color:gray;">, </span><span style="color:black;">FILEGROWTH </span><span style="color:blue;">= </span><span style="color:black;">10</span><span style="color:gray;">%)<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">Now create a table on primary filegroup.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Create New table on Primary Filgroup */<br />
</span><span style="color:blue;">USE </span><span style="color:black;">[FGTest]<br />
GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">[dbo].[TestTable]</span><span style="color:gray;">(<br />
</span><span style="color:black;">[ID] [int] </span><span style="color:gray;">NOT NULL,<br />
</span><span style="color:black;">[Col1] [varchar]</span><span style="color:gray;">(</span><span style="color:black;">50</span><span style="color:gray;">) NOT NULL,<br />
</span><span style="color:black;">[Col2] [varchar]</span><span style="color:gray;">(</span><span style="color:black;">50</span><span style="color:gray;">) NOT NULL,<br />
</span><span style="color:blue;">CONSTRAINT </span><span style="color:black;">[PK_TestTable] </span><span style="color:blue;">PRIMARY KEY CLUSTERED<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;">)<br />
) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code>
</p>
<p style="text-align:justify;">Next, create non-clustered index on secondary filegroup.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Create Non Clustered Index on Secondary FileGroup */<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_TestTable_Second] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[TestTable]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[Col1] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[Secondary]<br />
GO</span></code>
</p>
<p style="text-align:justify;">After that, we will run the following T-SQL and determine where all the objects are located on filegroup. We have already created a non-clustered index on our table. Now, non-clustered table creates its own table, which consists of pointers to clustered index. For the same reason, we will search with additional condition of object type, which will list only user created tables. Non- clustered table should be part of user created table group.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Get Details of Object on different filegroup<br />
Finding User Created Tables*/<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">o.[name]</span><span style="color:gray;">, </span><span style="color:black;">o.[type]</span><span style="color:gray;">, </span><span style="color:black;">i.[name]</span><span style="color:gray;">, </span><span style="color:black;">i.[index_id]</span><span style="color:gray;">, </span><span style="color:black;">f.[name]<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.indexes i<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">sys.filegroups f<br />
</span><span style="color:blue;">ON </span><span style="color:black;">i.data_space_id </span><span style="color:blue;">= </span><span style="color:black;">f.data_space_id<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">sys.all_objects o<br />
</span><span style="color:blue;">ON </span><span style="color:black;">i.[object_id] </span><span style="color:blue;">= </span><span style="color:black;">o.[object_id]<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">i.data_space_id </span><span style="color:blue;">= </span><span style="color:black;">f.data_space_id<br />
</span><span style="color:gray;">AND </span><span style="color:black;">o.type </span><span style="color:blue;">= </span><span style="color:red;">'U' </span><span style="color:green;">-- User Created Tables<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/fg1.jpg" alt="" width="502" height="311" /></p>
<p style="text-align:justify;">Let us observe the same query again with different WHERE condition. Here we are retrieving everything that is on secondary filegroup. It is very easy to identify filegroup name and data by just selecting everything from system table sys.filegroups.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Get Detail about Filegroups */<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.filegroups<br />
GO </span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/fg3.jpg" alt="" width="388" height="178" /></p>
<p style="text-align:justify;">In our case, secondary filegroup has data_space_id as 2. Now, we will run the following query and figure out which objects are located on filegroup 2.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Get Details of Object on different filegroup<br />
Finding Objects on Specific Filegroup*/<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">o.[name]</span><span style="color:gray;">, </span><span style="color:black;">o.[type]</span><span style="color:gray;">, </span><span style="color:black;">i.[name]</span><span style="color:gray;">, </span><span style="color:black;">i.[index_id]</span><span style="color:gray;">, </span><span style="color:black;">f.[name]<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.indexes i<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">sys.filegroups f<br />
</span><span style="color:blue;">ON </span><span style="color:black;">i.data_space_id </span><span style="color:blue;">= </span><span style="color:black;">f.data_space_id<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">sys.all_objects o<br />
</span><span style="color:blue;">ON </span><span style="color:black;">i.[object_id] </span><span style="color:blue;">= </span><span style="color:black;">o.[object_id]<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">i.data_space_id </span><span style="color:blue;">= </span><span style="color:black;">f.data_space_id<br />
</span><span style="color:gray;">AND </span><span style="color:black;">i.data_space_id </span><span style="color:blue;">= </span><span style="color:black;">2 </span><span style="color:green;">-- Filegroup<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/fg2.jpg" alt="" width="502" height="300" /></p>
<p style="text-align:justify;">I hope this answers Jogi&#8217;s question and is helpful for those who were curious to know the answer to this topic.</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>
<br />Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=5300&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/01/sql-server-list-all-objects-created-on-all-filegroups-in-database/feed/</wfw:commentRss>
		<slash:comments>24</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/fg1.jpg" medium="image" />

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

		<media:content url="http://www.pinaldave.com/bimg/fg2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; List All the Tables for All Databases Using System Tables</title>
		<link>http://blog.sqlauthority.com/2009/04/26/sql-server-list-all-the-tables-for-all-databases-using-system-tables/</link>
		<comments>http://blog.sqlauthority.com/2009/04/26/sql-server-list-all-the-tables-for-all-databases-using-system-tables/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 01:30:07 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[undocumented SQL]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4540</guid>
		<description><![CDATA[Today we will go over very simple script which will list all the tables for all the database. sp_msforeachdb 'select "?" AS db, * from [?].sys.tables' Update: Based on comments received below I have updated this article. Thank you to all the readers. This is good example where something small like this have good participation from readers. Reference : Pinal Dave [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4540&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Today we will go over very simple script which will list all the tables for all the database.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:darkred;">sp_msforeachdb </span><span style="color:red;">'select "?" AS db, * from [?].sys.tables'</span></code></p>
<p style="text-align:justify;"><strong>Update: </strong>Based on comments received below I have updated this article. Thank you to all the readers. This is good example where something small like this have good participation from readers.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://www.sqlauthority.com/" target="_blank">http://www.SQLAuthority.com</a>)</strong></p>
<br />Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: undocumented SQL <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4540/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4540&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/26/sql-server-list-all-the-tables-for-all-databases-using-system-tables/feed/</wfw:commentRss>
		<slash:comments>24</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 of DMV of Active Transactions and DMV of Current Transactions</title>
		<link>http://blog.sqlauthority.com/2009/04/11/sql-server-interesting-observation-of-dmv-of-active-transactions-and-dmv-of-current-transactions/</link>
		<comments>http://blog.sqlauthority.com/2009/04/11/sql-server-interesting-observation-of-dmv-of-active-transactions-and-dmv-of-current-transactions/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 01:30:34 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DMV]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Transactions]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4285</guid>
		<description><![CDATA[This post is about a riveting observation I made a few days back. While playing with transactions I came across two DMVs  that are associated with Transactions. 1) sys.dm_tran_active_transactions &#8211; Returns information about transactions for the instance of SQL Server. 2) sys.dm_tran_current_transaction &#8211; Returns a single row that displays the state information of the transaction [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4285&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">This post is about a riveting observation I made a few days back. While playing with transactions I came across two DMVs  that are associated with Transactions.</p>
<p style="text-align:justify;">1) sys.dm_tran_active_transactions &#8211; Returns information about transactions for the instance of SQL Server.</p>
<p style="text-align:justify;">2) sys.dm_tran_current_transaction &#8211; Returns a single row that displays the state information of the transaction in the current session.</p>
<p style="text-align:justify;">Now, what really interests me is the following observation. These two DMVs , in actual fact, display the distinction between active transactions and current transactions. Current transaction can be active transaction at the time of execution, but not all active transactions are current transactions for current transactions DMV.</p>
<p style="text-align:justify;">Let us take a look at an example where first we will run both these DMVs together in a single transaction and then run them separately.   We will notice that in the former case (i.e., when they are run in a single transaction) both of them give same transaction ID in result. While in the latter case (i.e., when they are run separately) they give different transaction IDs in result.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_tran_active_transactions<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_tran_current_transaction<br />
</span><span style="color:green;">/* Begin Transation */<br />
</span><span style="color:blue;">BEGIN TRANSACTION<br />
SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_tran_active_transactions<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_tran_current_transaction<br />
</span><span style="color:blue;">COMMIT<br />
</span><span style="color:green;">/* End Transation */</span></code>
</p>
<p style="text-align:justify;">Let us see the following result image and observe the behaviour we discussed above.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/tranandid.jpg" alt="" width="498" height="624" /></p>
<p style="text-align:justify;">To obtain same transaction ID, both the DMVs should be between BEGIN TRANSACTION and END TRANSACTION. Same transaction ID is preserved between BEGIN and END clause of transaction.</p>
<p style="text-align:justify;">Having said all that, now I am eager to receive answer to this question<strong> </strong>from my blog readers <strong>- In what circumstances do you think this behaviour can be useful?</strong></p>
<p style="text-align:justify;">If possible, please write an article on a real life scenario and send it to me.  I will be vary happy to publish it 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>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL DMV, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: SQL Transactions <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4285/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4285&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/11/sql-server-interesting-observation-of-dmv-of-active-transactions-and-dmv-of-current-transactions/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/tranandid.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Reseed Identity of Table &#8211; Table Missing Identity Values &#8211; Gap in Identity Column</title>
		<link>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/</link>
		<comments>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 01:30:04 +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 Server DBCC]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Identity]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4195</guid>
		<description><![CDATA[Some time ago I was helping one of my Junior Developers who presented me with an interesting situation. He had a table with Identity Column. Because of some reasons he was compelled to delete few rows from the table. On inserting new rows in the table he noticed that the rows started from the next [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4195&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Some time ago I was helping one of my Junior Developers who presented me with an interesting situation.  He had a table with Identity Column. Because of some reasons he was compelled to delete few rows from the table. On inserting new rows in the table he noticed that the rows started from the next identity value which created gap in the identity value. His application required all the identities to be in sequence, so this was certainly not a small issue for him.</p>
<p style="text-align:justify;">The solution to this issue regarding gap in identity column is very simple. Let us first take a look at his application’s situation wherein there is missing identity and then we will move on to the solution.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/identitymiss.jpg" alt="" width="300" height="281" /></p>
<p>Developers can easily deter the above issue by avoiding gap in sequence of identity column through two additional SQL Tricks of reseeding identity.</p>
<p>We will now see the same example with the solution to the above gap issue. On deleting records, table was reseeded with identity, which was deleted.<a href="http://www.pinaldave.com/bimg/identityreseed.zip" target="_blank"> Download complete SQL Script here</a>.</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;">/* Create a table with one identity column */<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">TableID </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT </span><span style="color:#434343;">IDENTITY</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">), </span><span style="color:black;">Col </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Insert 10 records with first value */<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">TableID </span><span style="color:gray;">(</span><span style="color:black;">Col</span><span style="color:gray;">)<br />
</span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">'First'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO 10<br />
</span><span style="color:green;">/* Check the records in table */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TableID<br />
GO<br />
</span><span style="color:green;">/* Delete last few records */<br />
</span><span style="color:blue;">DELETE<br />
FROM </span><span style="color:black;">TableID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:blue;">IN </span><span style="color:gray;">(</span><span style="color:black;">8</span><span style="color:gray;">,</span><span style="color:black;">9</span><span style="color:gray;">,</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Check the records in table */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TableID<br />
GO<br />
</span><span style="color:green;">/* Get current Max Value and reseed table */<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@MaxID </span><span style="color:blue;">INT<br />
SELECT </span><span style="color:#434343;">@MaxID </span><span style="color:blue;">= MAX</span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TableID<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">CHECKIDENT</span><span style="color:gray;">(</span><span style="color:red;">'TableID'</span><span style="color:gray;">, </span><span style="color:black;">RESEED</span><span style="color:gray;">, </span><span style="color:#434343;">@MaxID</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Insert 10 records with second value */<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">TableID </span><span style="color:gray;">(</span><span style="color:black;">Col</span><span style="color:gray;">)<br />
</span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">'Second'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO 5<br />
</span><span style="color:green;">/* Check the records in table */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">TableID<br />
GO<br />
</span><span style="color:green;">/* Clean Database */<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">TableID<br />
GO<br />
</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/identitymiss1.jpg" alt="" width="492" height="699" /></p>
<p style="text-align:justify;">I hope is solution is clear to all my readers and they will use it to avoid problems related to gap in identity column. Do send me your feedback on this article and let me know if you all need further explanation.</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>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: Identity <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=4195&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/feed/</wfw:commentRss>
		<slash:comments>31</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/identitymiss.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/identitymiss1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Optimize for Ad hoc Workloads &#8211; Advance Performance Optimization</title>
		<link>http://blog.sqlauthority.com/2009/03/21/sql-server-2008-optimize-for-ad-hoc-workloads-advance-performance-optimization/</link>
		<comments>http://blog.sqlauthority.com/2009/03/21/sql-server-2008-optimize-for-ad-hoc-workloads-advance-performance-optimization/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 01:30:44 +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 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 Stored Procedure]]></category>
		<category><![CDATA[SQL System Table]]></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=3819</guid>
		<description><![CDATA[Every batch (T-SQL, SP etc) when ran creates execution plan which is stored in system for re-use. Due to this reason large number of query plans are stored in system. However, there are plenty of plans which are only used once and have never re-used again. One time ran batch plans wastes memory and resources. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=3819&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Every batch (T-SQL, SP etc) when ran creates execution plan which is stored in system for re-use. Due to this reason large number of query plans are stored in system. However, there are plenty of plans which are only used once and have never re-used again. One time ran batch plans wastes memory and resources.</p>
<p style="text-align:justify;">SQL Server 2008 has feature of optimizing ad hoc workloads. Before we move to it, let us understand the behavior of SQL Server without optimizing ad hoc workload.</p>
<p style="text-align:justify;">Please run following script for testing. Make sure to not to run whole batch together. Just run each command separately to really see the effect of subject of article.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/bimg/CachePlan.zip" target="_blank"><strong>Download complete script of this article here.</strong></a></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Test 0 */<br />
/* Clean Cache and Buffers */<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">FREEPROCCACHE<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">DROPCLEANBUFFERS<br />
GO<br />
</span><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">/* Run Adhoc Query First Time */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Shift<br />
GO<br />
</span><span style="color:green;">/* Check if Adhoc query is cached.<br />
It will return one result */<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">usecounts</span><span style="color:gray;">, </span><span style="color:black;">cacheobjtype</span><span style="color:gray;">, </span><span style="color:black;">objtype</span><span style="color:gray;">, </span><span style="color:blue;">TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_cached_plans<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">plan_handle</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">usecounts </span><span style="color:gray;">&gt; </span><span style="color:black;">0 </span><span style="color:gray;">AND<br />
</span><span style="color:blue;">TEXT </span><span style="color:gray;">LIKE </span><span style="color:red;">'%SELECT * FROM HumanResources.Shift%'<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">usecounts </span><span style="color:blue;">DESC</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">Now let us check result of this script. It is clear from result that when we ran query once it cached its plan in memory. If we never run this again in future or if we have just ran as part of building longer query the cache plan of this query is just waste of memory.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/cachetest0.jpg" alt="" width="553" height="516" /></p>
<p style="text-align:justify;">Let us now enable the option of optimizing ad hoc workload. This feature is available in all the versions of SQL Server 2008.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:black;"> </span><span style="color:darkred;">sp_CONFIGURE </span><span style="color:red;">'show advanced options'</span><span style="color:gray;">,</span><span style="color:black;">1<br />
</span><span style="color:blue;">RECONFIGURE<br />
</span><span style="color:black;">GO</span></code></p>
<p><span style="color:darkred;">sp_CONFIGURE </span><span style="color:red;">&#8216;optimize for ad hoc workloads&#8217;</span><span style="color:gray;">,</span><span style="color:black;">1<br />
</span><span style="color:blue;">RECONFIGURE<br />
</span><span style="color:black;">GO</span>
</p>
<p style="text-align:justify;">We will now run the code for Test 1 which is almost same as Test 0. Make sure to clean the cache and buffer before running the query to create real life scenario of live case.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Test 1 */<br />
/* Clean Cache and Buffers */<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">FREEPROCCACHE<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">DROPCLEANBUFFERS<br />
GO<br />
</span><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">/* Run Adhoc Query First Time */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Shift<br />
GO<br />
</span><span style="color:green;">/* Check if Adhoc query is cached.<br />
It will not return any result */<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">usecounts</span><span style="color:gray;">, </span><span style="color:black;">cacheobjtype</span><span style="color:gray;">, </span><span style="color:black;">objtype</span><span style="color:gray;">, </span><span style="color:blue;">TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_cached_plans<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">plan_handle</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">usecounts </span><span style="color:gray;">&gt; </span><span style="color:black;">0 </span><span style="color:gray;">AND<br />
</span><span style="color:blue;">TEXT </span><span style="color:gray;">LIKE </span><span style="color:red;">'SELECT * FROM HumanResources.Shift%'<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">usecounts </span><span style="color:blue;">DESC</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO </span></code>
</p>
<p style="text-align:justify;">We can clear see now as we have advance option enabled we do not have query cache planed stored in database.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/cachetest1.jpg" alt="" width="556" height="485" /></p>
<p style="text-align:justify;">We are interested to know now that if we run the batch more than 1 time it will cache its execution plan.  With advance option of optimizing ad hoc workload.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Test 2 */<br />
/* Clean Cache and Buffers */<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">FREEPROCCACHE<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">DROPCLEANBUFFERS<br />
GO<br />
</span><span style="color:green;">/* Run Adhoc Query two  Time */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Shift<br />
GO 5<br />
</span><span style="color:green;">/* Check if Adhoc query is cached.<br />
It will return result with Adhoc Query ran two times*/<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">usecounts</span><span style="color:gray;">, </span><span style="color:black;">cacheobjtype</span><span style="color:gray;">, </span><span style="color:black;">objtype</span><span style="color:gray;">, </span><span style="color:blue;">TEXT<br />
FROM </span><span style="color:black;">sys.dm_exec_cached_plans<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">plan_handle</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">usecounts </span><span style="color:gray;">&gt; </span><span style="color:black;">0 </span><span style="color:gray;">AND<br />
</span><span style="color:blue;">TEXT </span><span style="color:gray;">LIKE </span><span style="color:red;">'%SELECT * FROM HumanResources.Shift%'<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">usecounts </span><span style="color:blue;">DESC</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">From our image it is quite clear that when the batch is ran for more than 1 time it caches its execution plan. This is generic behavior with or without turning on advance option.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/cachetest2.jpg" alt="" width="561" height="859" /></p>
<p style="text-align:justify;">This may be very simple to see from the top but if you are using SQL Server 2008 and have millions of ad hoc query running every day you wil realize how important this feature is. This feature improves performance by relieving memory pressure by not storing the single time used compiled plans.</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>
<br />Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Stored Procedure, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/3819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/3819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/3819/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=3819&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/03/21/sql-server-2008-optimize-for-ad-hoc-workloads-advance-performance-optimization/feed/</wfw:commentRss>
		<slash:comments>21</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/cachetest0.jpg" medium="image" />

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

		<media:content url="http://www.pinaldave.com/bimg/cachetest2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Find Current Location of Data and Log File of All the Database</title>
		<link>http://blog.sqlauthority.com/2009/02/17/sql-server-find-current-location-of-data-and-log-file-of-all-the-database/</link>
		<comments>http://blog.sqlauthority.com/2009/02/17/sql-server-find-current-location-of-data-and-log-file-of-all-the-database/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 01:30:45 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=2593</guid>
		<description><![CDATA[As I am doing lots of experiments on my SQL Server test box, I sometime gets too many files in SQL Server data installation folder &#8211; the place where I have all the .mdf and .ldf files are stored. I often go to that folder and clean up all unnecessary files I have left there [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2593&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">As I am doing lots of experiments on my SQL Server test box, I sometime gets too many files in SQL Server data installation folder &#8211; the place where I have all the .mdf and .ldf files are stored. I often go to that folder and clean up all unnecessary files I have left there taking up my hard drive space. I run following query to find out which .mdf and .ldf files are used and delete all other files. If your SQL Server is up and running OS will not let you delete .mdf and .ldf files any way giving you error that file already in use. This list also helps sometime to do documentation of which files are in being used by which database.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">name</span><span style="color:gray;">, </span><span style="color:black;">physical_name </span><span style="color:blue;">AS </span><span style="color:black;">current_file_location<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.master_files</span></code>
</p>
<p style="text-align:justify;">Following is the output of files used by my SQL Server instance.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/mastefiles.jpg" alt="" width="500" height="394" /></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;">
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Backup and Restore, SQL Documentation, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2593/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2593&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/02/17/sql-server-find-current-location-of-data-and-log-file-of-all-the-database/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/mastefiles.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; List All Server Wide Configurations Values</title>
		<link>http://blog.sqlauthority.com/2009/02/16/sql-server-list-all-server-wide-configurations-values/</link>
		<comments>http://blog.sqlauthority.com/2009/02/16/sql-server-list-all-server-wide-configurations-values/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 01:30:34 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></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=2589</guid>
		<description><![CDATA[Just a day ago, while working on one of the project, I needed to see what is the two digit year cutoff of my current SQL Server. I did not remember what was the exact syntax to search for the same so I ran following query to list all server wide configurations. While looking at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2589&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Just a day ago, while working on one of the project, I needed to see what is the two digit year cutoff of my current SQL Server. I did not remember what was the exact syntax to search for the same so I ran following query to list all server wide configurations. While looking at quickly I found out value of two digit year cutoff on line 19th. A small but very important script to save for getting server information.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.configurations</span><span style="color:gray;">;</span></code>
</p>
<p style="text-align:justify;">I have ran this command on SQL Server 2008 and few of the information may be different than SQL Server 2005. When I ran this script I got 68 rows in result set.</p>
<p style="text-align:justify;">I would like to know how many rows SQL Server 2005 returns.</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>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2589/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2589/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2589/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2589&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/02/16/sql-server-list-all-server-wide-configurations-values/feed/</wfw:commentRss>
		<slash:comments>8</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; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/</link>
		<comments>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/#comments</comments>
		<pubDate>Fri, 23 Jan 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 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 Server DBCC]]></category>
		<category><![CDATA[SQL System Table]]></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=2105</guid>
		<description><![CDATA[Just another day I was playing with my query which I posted earlier SQL SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL and I found that I got error devide by zero. I have fixed this error in following query as well I have updated query to return time in millisecond [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2105&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">Just another day I was playing with my query which I posted earlier <strong><a href="http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/" target="_blank">SQL SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL</a></strong> and I found that I got error devide by zero. I have fixed this error in following query as well I have updated query to return time in millisecond instead of microsecond. <a href="http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/#comment-45471" target="_blank">Jerry Hung</a> has also posted similar solution in comments of original article.</p>
<p style="text-align:justify;">I strongly suggest to read <a href="http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql" target="_blank">original article</a> to now more about introduction and learn about DBCC command which clears cache.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT DISTINCT TOP </span><span style="color:black;">10<br />
t.</span><span style="color:blue;">TEXT </span><span style="color:black;">QueryName</span><span style="color:gray;">,<br />
</span><span style="color:black;">s.execution_count </span><span style="color:blue;">AS </span><span style="color:black;">ExecutionCount</span><span style="color:gray;">,<br />
</span><span style="color:black;">s.max_elapsed_time </span><span style="color:blue;">AS </span><span style="color:black;">MaxElapsedTime</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:black;">s.total_elapsed_time </span><span style="color:gray;">/ </span><span style="color:black;">1000 </span><span style="color:gray;">/ </span><span style="color:magenta;">NULLIF</span><span style="color:gray;">(</span><span style="color:black;">s.execution_count</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">), </span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">AvgElapsedTime</span><span style="color:gray;">,<br />
</span><span style="color:black;">s.creation_time </span><span style="color:blue;">AS </span><span style="color:black;">LogCreatedOn</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:black;">s.execution_count </span><span style="color:gray;">/ </span><span style="color:black;">1000 </span><span style="color:gray;">/ </span><span style="color:magenta;">NULLIF</span><span style="color:gray;">(</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">s</span><span style="color:gray;">, </span><span style="color:black;">s.creation_time</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()), </span><span style="color:black;">0</span><span style="color:gray;">), </span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">FrequencyPerSec<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_query_stats s<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">( </span><span style="color:black;">s.sql_handle </span><span style="color:gray;">) </span><span style="color:black;">t<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">s.max_elapsed_time </span><span style="color:blue;">DESC</span><span style="color:gray;">, </span><span style="color:black;">ExecutionCount </span><span style="color:blue;">DESC</span><span style="color:gray;">,<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
<br />Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2105&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/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; Find Row Count in Table &#8211; Find Largest Table in Database &#8211; T-SQL</title>
		<link>http://blog.sqlauthority.com/2009/01/13/sql-server-find-row-count-in-table-find-largest-table-in-database-t-sql/</link>
		<comments>http://blog.sqlauthority.com/2009/01/13/sql-server-find-row-count-in-table-find-largest-table-in-database-t-sql/#comments</comments>
		<pubDate>Tue, 13 Jan 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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2013</guid>
		<description><![CDATA[I have written following script every time when I am asked by our team leaders or managers that how many rows are there in any particular table or sometime I am even asked which table has highest number of rows. Being Sr. Project Manager, sometime I just write down following script myself rather than asking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2013&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;">I have written following script every time when I am asked by our team leaders or managers that how many rows are there in any particular table or sometime I am even asked which table has highest number of rows. Being Sr. Project Manager, sometime I just write down following script myself rather than asking my developers.</p>
<p style="text-align:justify;">This script will gives row number for every table in database.</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:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) </span><span style="color:black;">TableName</span><span style="color:gray;">, </span><span style="color:black;">st.row_count<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_db_partition_stats st<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">index_id </span><span style="color:gray;">&lt; </span><span style="color:black;">2<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">st.row_count </span><span style="color:blue;">DESC<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/rowcount.jpg" alt="" width="462" height="650" /></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>
<br />Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, SQL Utility, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2013/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&amp;blog=668536&amp;post=2013&amp;subd=sqlauthority&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/13/sql-server-find-row-count-in-table-find-largest-table-in-database-t-sql/feed/</wfw:commentRss>
		<slash:comments>27</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/rowcount.jpg" medium="image" />
	</item>
	</channel>
</rss>
