<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Journey to SQL Authority with Pinal Dave &#187; SQL Server DBCC</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-server-dbcc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 01:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Journey to SQL Authority with Pinal Dave &#187; SQL Server DBCC</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<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:
SELECT @@SPID
GO

In [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5934&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
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/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&blog=668536&post=5934&subd=sqlauthority&ref=&feed=1" /></div>]]></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>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/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; 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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4195&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
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/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&blog=668536&post=4195&subd=sqlauthority&ref=&feed=1" /></div>]]></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>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

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

		<media:content url="http://www.pinaldave.com/bimg/identitymiss1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Shrinking NDF and MDF Files &#8211; A Safe Operation</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/</link>
		<comments>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 01:30:56 +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 Data Storage]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></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=2118</guid>
		<description><![CDATA[Just a day ago I have received following email from Siddhi and I found it interesting so I am sharing with all of you.
Hello Pinal,


I have seen many blogs from you on SQL server and i have always found them useful and easy to understand. Thanks for all the information you provide.


I have one query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2118&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Just a day ago I have received following email from <strong>Siddhi </strong>and I found it interesting so I am sharing with all of you.</p>
<div style="padding-left:30px;text-align:justify;"><em>Hello Pinal,</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>I have seen many blogs from you on SQL server and i have always found them useful and easy to understand. Thanks for all the information you provide.</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>I have one query about shrinking NDF and MDF files.</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em><strong>Can we shrink NDF and MDF</strong> <strong>files?? If you do so is there any data loss?</strong></em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>I have been shrinking the .LDF files every now and then but I am not too sure about NDF and MDF files.</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>Can you please answer my query.</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>Waiting for your early response.</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="padding-left:30px;text-align:justify;"><em>Regards,</em></div>
<div style="padding-left:30px;text-align:justify;"><em>Siddhi</em></div>
<div style="padding-left:30px;text-align:justify;"><em><br />
</em></div>
<div style="text-align:justify;"><strong>Answer:</strong></div>
<div style="text-align:justify;"><strong>Shrinking MDF and NDF file is possible and there is no chance of data loss.</strong></div>
<div style="text-align:justify;"><strong><br />
</strong></div>
<div style="text-align:justify;">It is not always advisable to shrink those file as those files are usually growing. There are cases when one database is separated in multiple database of any large table is dropped from database MDF and NDF can contain large empty space. This is the time they should be shrank. Shrinking database can be many hours process but it there are very slim chances of data lose.</div>
<div style="text-align:justify;">Following is the script to shrink whole database.</div>
<div style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">SHRINKDATABASE </span><span style="color:gray;">(</span><span style="color:black;">dbName</span><span style="color:gray;">)</span></code></div>
<div style="text-align:justify;"><span style="color:gray;"><br />
</span></div>
<div style="text-align:justify;">Following is the script to shrink single file.</div>
<div style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">SHRINKFILE </span><span style="color:gray;">(</span><span style="color:black;">logicalLogFileName</span><span style="color:gray;">)</span></code></div>
<div style="text-align:justify;"><span style="color:gray;"><br />
</span></div>
<div style="text-align:justify;">To find logicalLogFileName following command has to be ran.</div>
<div style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">dbName<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_helpfile</span></code></div>
<div style="text-align:justify;"><span style="color:darkred;"><br />
</span></div>
<div style="text-align:justify;">Let us understand this using database AdventureWorks.</div>
<div style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">/* Shrink Whole AdventureWorks Database */<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">SHRINKDATABASE </span><span style="color:gray;">(</span><span style="color:black;">AdventureWorks</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Get the Logical File Name */<br />
</span><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
</span><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_helpfile<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* Shrink MDF File of AdventureWorks Database */<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">SHRINKFILE </span><span style="color:gray;">(</span><span style="color:black;">AdventureWorks_Data</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></div>
<div style="text-align:justify;">Following image of the same process show when whole process is done there will be resultset with information about the new states of the database files.</div>
<div style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/shrinkdb.gif" alt="" width="445" height="384" /></div>
<div style="text-align:justify;"><span style="color:black;"><br />
</span></div>
<div style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong></div>
Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Data Storage, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Server DBCC, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2118&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/shrinkdb.gif" medium="image" />
	</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&blog=668536&post=2105&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
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/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&blog=668536&post=2105&subd=sqlauthority&ref=&feed=1" /></div>]]></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>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>
	</item>
		<item>
		<title>SQL SERVER &#8211; Find Number of Rows and Disk Space Reserved &#8211; Using sp_spaceused Interesting Observation</title>
		<link>http://blog.sqlauthority.com/2009/01/14/sql-server-find-number-of-rows-and-disk-space-reserved-using-sp_spaceused-interesting-observation/</link>
		<comments>http://blog.sqlauthority.com/2009/01/14/sql-server-find-number-of-rows-and-disk-space-reserved-using-sp_spaceused-interesting-observation/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 01:30:24 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Data Storage]]></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 Stored Procedure]]></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=2016</guid>
		<description><![CDATA[Previously I posted SQL SERVER &#8211; Find Row Count in Table &#8211; Find Largest Table in Database &#8211; T-SQL. Today we will look into the same issue but with some additional interesting detail.
We can find the row count using another system SP sp_spaceused. This SP gives additional information regarding disk space reserved on database as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2016&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Previously I posted <strong><a href="http://blog.sqlauthority.com/2008/12/09/sql-server-find-table-rowcount-without-using-t-sql-and-without-opening-table/" target="_blank">SQL SERVER &#8211; Find Row Count in Table &#8211; Find Largest Table in Database &#8211; T-SQL</a></strong>. Today we will look into the same issue but with some additional interesting detail.<br />
We can find the row count using another system SP sp_spaceused. This SP gives additional information regarding disk space reserved on database as well. Well, when I ran the SP on AdventureWorks first time, I suspected that database SP is not providing me correct results.
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/spaceused.jpg" alt="" width="330" height="257" /></p>
<p style="text-align:justify;">After a bit investigating I found that it may be possible that due to any reason may be the usage on AdventureWorks database might not be updated. I ran same SP with additional param as shown below and it provided me updated information for the same. Once I ran the SP with @updateusage param, it updated the status of the database. When I ran it again next time without param it gave the same results.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/spaceused1.jpg" alt="" width="367" height="244" /></p>
<p style="text-align:justify;">The reason for above behavior is when dellocation of space happened in database (e.g. dropping table or truncating table) it does not release the used space right away. However, when @updateusage param is used database engine scans whole database and update the sapce usage in respective tables.<br />
Let me know if you guys have any interesting observation like this.
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Data Storage, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, SQL Utility, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/2016/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/2016/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/2016/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/2016/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/2016/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/2016/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/2016/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/2016/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/2016/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/2016/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=2016&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/14/sql-server-find-number-of-rows-and-disk-space-reserved-using-sp_spaceused-interesting-observation/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/spaceused.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/spaceused1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL</title>
		<link>http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/</link>
		<comments>http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 01:30:53 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL 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 Stored Procedure]]></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=1941</guid>
		<description><![CDATA[UPDATE : Updated this query with bug fixed with one more enhancement SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL &#8211; Part 2.
Recently my company owner asked me to find which query is running longest. It was very interesting that I was not able to find any T-SQL script online which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1941&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><em><strong>UPDATE : </strong></em>Updated this query with bug fixed with one more enhancement <strong><a href="http://blog.sqlauthority.com/2009/01/23/sql-server-2008-2005-find-longest-running-query-tsql-part-2/" target="_blank">SERVER &#8211; 2008 &#8211; 2005 &#8211; Find Longest Running Query &#8211; TSQL &#8211; Part 2</a></strong>.</p>
<p style="text-align:justify;">Recently my company owner asked me to find which query is running longest. It was very interesting that I was not able to find any T-SQL script online which can give me this data directly. Finally, I wrote down very quick script which gives me T-SQL which has ran on server along with average time and maximum time of that T-SQL execution. As I keep on writing I needed to know when exactly logging was started for the same T-SQL so I had added Logging start time in the query as well.</p>
<p style="text-align:justify;">The reason I started to use this script to find out longest running query as if query is changed a bit it will display it as new row and new log start time. This way when I am improving T-SQL query or Stored Procedure I can check their progress in the query and does not have to get bothered with previous data.</p>
<p style="text-align:justify;">I always run following DBCC command before I started to use my query. Following DBCC commands clears the cache of the server and starts fresh logging of the query running time.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">FREEPROCCACHE</span></code></p>
<p style="text-align:justify;">Run following query to find longest running query using T-SQL.</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;">s.execution_count</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: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: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<br />
</span><span style="color:black;">s.max_elapsed_time </span><span style="color:blue;">DESC<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;">You can also add WHERE clause to above T-SQL query and filter additionally.</p>
<p style="text-align:justify;">If you have not ran query like this previously on your server I strongly recommend to run this. I bet you will find surprising results.</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;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1941/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1941/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1941/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1941&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/02/sql-server-2008-2005-find-longest-running-query-tsql/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; Check Database Integrity for All Databases of Server</title>
		<link>http://blog.sqlauthority.com/2008/11/10/sql-server-check-database-integrity-for-all-databases-of-server/</link>
		<comments>http://blog.sqlauthority.com/2008/11/10/sql-server-check-database-integrity-for-all-databases-of-server/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 01:30:51 +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 Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1489</guid>
		<description><![CDATA[Today we will see quick script which will check integrity of all the database of SQL Server.
EXEC sp_msforeachdb 'DBCC CHECKDB(''?'')' 
Above script will return you lots of messages in resultset. If there are any errors in resultset they will be displayed in red text. If everything is black text there is no error. Typical output of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1489&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today we will see quick script which will check integrity of all the database of SQL Server.</p>
<p><code style="font-size:12px;"><span style="color:blue;">EXEC </span><span style="color:darkred;">sp_msforeachdb </span><span style="color:red;">'DBCC CHECKDB(''?'')' </span></code></p>
<p>Above script will return you lots of messages in resultset. If there are any errors in resultset they will be displayed in red text. If everything is black text there is no error. Typical output of above script will be like image included in the article.</p>
<p><img class="alignnone" src="http://www.pinaldave.com/bimg/dbcccheckdb.jpg" alt="" width="500" height="321" /></p>
<p>Image displayed above is only partial image.</p>
<p>Reference : <strong>Pinal Dave (<a href="http://www.SQLAuthority.com" target="_blank">http://www.SQLAuthority.com</a>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1489/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1489&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/11/10/sql-server-check-database-integrity-for-all-databases-of-server/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/dbcccheckdb.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Refresh Database Using T-SQL</title>
		<link>http://blog.sqlauthority.com/2008/11/07/sql-server-refresh-database-using-t-sql/</link>
		<comments>http://blog.sqlauthority.com/2008/11/07/sql-server-refresh-database-using-t-sql/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 01:30:13 +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 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 Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1480</guid>
		<description><![CDATA[Yesterday I received following questions on blog. Ashish Agarwal asked following question.
Hi Pinal,
Can we refresh a database (like we do by right clicking database node in object explorer and clicking on refresh) thru SQL Query?
If yes, can you please tell me the query?
Thanks,
Ashish Agarwal
Answer to above question is NO. It is not possible to do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1480&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday I received following questions on blog. <a href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/#comment-44079" target="_blank">Ashish Agarwal</a> asked following question.</p>
<p style="padding-left:30px;"><em>Hi Pinal,</em></p>
<p style="padding-left:30px;"><em>Can we refresh a database (like we do by right clicking database node in object explorer and clicking on refresh) thru SQL Query?<br />
If yes, can you please tell me the query?</em></p>
<p style="padding-left:30px;"><em>Thanks,<br />
Ashish Agarwal</em></p>
<p>Answer to above question is <strong>NO</strong>. It is not possible to do the same task using SQL Query.</p>
<p>However, if you have changed some SP or any other object and if they are cached in the database, database can be refreshed using DBCC commands.</p>
<p>Read my previous article about <strong><a href="http://blog.sqlauthority.com/2008/07/22/sql-server-clear-sql-server-memory-caches/" target="_blank">SQL SERVER &#8211; Clear SQL Server Memory Caches</a></strong>.</p>
<p>Reference: <strong>Pinal Dave (<a href="http://www.SQLAuthority.com" target="_blank">http://www.SQLAuthority.com</a>)</strong><em><br />
</em></p>
Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1480&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/11/07/sql-server-refresh-database-using-t-sql/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; 2008 &#8211; Interview Questions and Answers Complete List Download</title>
		<link>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/</link>
		<comments>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 01:30:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL XML]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1134</guid>
		<description><![CDATA[Download SQL Server 2008 Interview Questions and Answers Complete List
Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server is very large subject and not everything is usually asked in interview. In interview what matters the most is <strong>conceptual knowledge</strong> and <strong>learning attitude</strong>.</p>
<p style="text-align:justify;">I have listed all the series in this post so that it can be easily downloaded and used. All the questions are collected and listed in one PDF which is here to download. If you have any question or if you want to add to any of the question please send me mail or write a comment.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/12/sql-server-2008-interview-questions-and-answers-part-1/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 1</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 2</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/14/sql-server-2008-interview-questions-and-answers-part-3/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 3</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/15/sql-server-2008-interview-questions-and-answers-part-4/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 4</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/16/sql-server-2008-interview-questions-and-answers-part-5/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 5</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 6</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/18/sql-server-2008-interview-questions-and-answers-part-7/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 7</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 8</strong></a></p>
<h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Database, Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Cursor, SQL Data Storage, SQL DateTime, SQL Documentation, SQL Download, SQL Error Messages, SQL Function, SQL Index, SQL Interview Questions and Answers, SQL Joins, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, SQL Trigger, SQL Utility, SQLAuthority, T SQL, Technology Tagged: SQL XML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/feed/</wfw:commentRss>
		<slash:comments>55</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; Interview Questions and Answers &#8211; Part 8</title>
		<link>http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/</link>
		<comments>http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 01:30:07 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></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 Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1012</guid>
		<description><![CDATA[SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download
What is Data Compression?
In SQL SERVE 2008 Data Compression comes in two flavors:

 Row Compression
 Page Compression

Row Compression
Row compression changes the format of physical storage of data. It minimize the metadata (column information, length, offsets etc) associated with each record. Numeric data types and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1012&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" target="_blank">SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download</a></strong></h2>
<p style="text-align:justify;"><strong>What is Data Compression?</strong></p>
<p style="text-align:justify;">In SQL SERVE 2008 Data Compression comes in two flavors:<strong></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Row Compression</li>
<li> Page Compression</li>
</ul>
<p style="text-align:justify;"><strong>Row Compression</strong></p>
<p style="text-align:justify;">Row compression changes the format of physical storage of data. It minimize the metadata (column information, length, offsets etc) associated with each record. Numeric data types and fixed length strings are stored in variable-length storage format, just like Varchar.  (<a href="http://blog.sqlauthority.com/2008/07/06/sql-server-2008-introduction-to-row-compression/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>Page Compression</strong></p>
<p style="text-align:justify;">Page compression allows common data to be shared between rows for a given page. Its uses the following techniques to compress data:<strong></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Row compression.</li>
<li> Prefix Compression. For every column in a page duplicate prefixes are identified. These prefixes are saved in compression information headers (CI) which resides after page header. A reference number is assigned to these prefixes and that reference number is replaced where ever those prefixes are being used.</li>
</ul>
<p style="text-align:justify;"><strong>Dictionary Compression</strong>.</p>
<p style="text-align:justify;">Dictionary compression searches for duplicate values throughout the page and stores them in CI. The main difference between prefix and dictionary compression is that prefix is only restricted to one column while dictionary is applicable to the complete page.</p>
<p style="text-align:justify;"><strong>What is use of DBCC Commands?</strong></p>
<p style="text-align:justify;">The Transact-SQL programming language provides DBCC statements that act as Database Console Commands for SQL Server.  DBCC commands are used to perform following tasks.</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Maintenance tasks on database, index, or filegroup.</li>
<li> Tasks that gather and display various types of information.</li>
<li> Validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.</li>
<li> Miscellaneous tasks such as enabling trace flags or removing a DLL from memory.</li>
</ul>
<p style="text-align:justify;">(<a href="http://blog.sqlauthority.com/2007/05/15/sql-server-dbcc-commands-list-documented-and-undocumented/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>How to find tables without Indexes?</strong></p>
<p style="text-align:justify;">Run following query in Query Editor.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:gray;">&lt;</span><span style="color:black;">database_name</span><span style="color:gray;">&gt;;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">SCHEMA_NAME</span><span style="color:gray;">(</span><span style="color:black;">schema_id</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">schema_name<br />
</span><span style="color:gray;">,</span><span style="color:black;">name </span><span style="color:blue;">AS </span><span style="color:black;">table_name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.tables<br />
</span><span style="color:blue;">WHERE </span><span style="color:magenta;">OBJECTPROPERTY</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">,</span><span style="color:red;">'IsIndexed'</span><span style="color:gray;">) </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">schema_name</span><span style="color:gray;">, </span><span style="color:black;">table_name</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><strong>How to copy the tables, schema and views from one SQL Server to another?</strong></p>
<p style="text-align:justify;">There are multiple ways to do this.</p>
<ol style="text-align:justify;">
<li> &#8220;Detach Database&#8221; from one server and &#8220;Attach Database&#8221; to another server.</li>
<li> Manually script all the objects using SSMS and run the script on new server.</li>
<li> Use Wizard of SSMS. (<a href="http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/" target="_blank">Read More Here</a>)</li>
</ol>
<p style="text-align:justify;"><strong>How to copy data from one table to another table?</strong></p>
<p style="text-align:justify;">There are multiple ways to do this.</p>
<p style="text-align:justify;"><strong><em>1) </em></strong><strong><em>INSERT INTO SELECT</em></strong></p>
<p style="text-align:justify;">This method is used when table is already created in the database earlier and data is to be inserted into this table from another table. If columns listed in insert clause and select clause are same, they are not required to list them.</p>
<p style="text-align:justify;"><strong><em>2) SELECT INTO</em></strong></p>
<p style="text-align:justify;">This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.</p>
<p style="text-align:justify;">(<a href="http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is Catalog Views?</strong></p>
<p style="text-align:justify;">Catalog views return information that is used by the SQL Server Database Engine. Catalog Views are the most general interface to the catalog metadata and provide the most efficient way to obtain, transform, and present customized forms of this information. All user-available catalog metadata is exposed through catalog views.</p>
<p style="text-align:justify;"><strong>What is PIVOT and UNPIVOT?</strong></p>
<p style="text-align:justify;"><em>A Pivot Table</em> can automatically sort, count, and total the data stored in one table or spreadsheet and create a second table displaying the summarized data. The PIVOT operator turns the values of a specified column into column names, effectively rotating a table.</p>
<p style="text-align:justify;">UNPIVOT table is reverse of PIVOT Table. (<a href="http://blog.sqlauthority.com/2008/05/29/sql-server-unpivot-table-example/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is Filestream?</strong></p>
<p style="text-align:justify;">Filestream allows you to store large objects in the file system and have these files integrated within the database. It enables SQL Server based applications to store unstructured data such as documents, images, audios, videos etc. in the file system. FILESTREAM basically integrates the SQL Server Database Engine with New Technology File System (NTFS); it basically stores the data in varbinary (max) data type. Using this data type, the unstructured data is stored in the NTFS file system and the SQL Server Database Engine manages the link between the Filestream column and the actual file located in the NTFS. Using Transact SQL statements users can insert, update, delete and select the data stored in FILESTREAM enabled tables.</p>
<p style="text-align:justify;"><strong>What is Dirty Read ?</strong></p>
<p style="text-align:justify;">A dirty read occurs when two operations say, read and write occurs together giving the incorrect or unedited data. Suppose, A has changed a row, but has not committed the changes. B reads the uncommitted data but his view of the data may be wrong so that is Dirty Read.<strong> </strong></p>
<p style="text-align:justify;"><strong>What is SQLCMD?</strong></p>
<p style="text-align:justify;">sqlcmd is enhanced version of the isql and osql and it provides way more functionality than other two options. In other words sqlcmd is better replacement of isql (which will be deprecated eventually) and osql (not included in SQL Server 2005 RTM). sqlcmd can work two modes &#8211; i) BATCH and ii) interactive modes. (<a href="http://blog.sqlauthority.com/2007/09/06/sql-server-2005-introduction-and-explanation-to-sqlcmd/" target="_blank">Read More</a>)</p>
<p style="text-align:justify;"><strong>What is Aggregate Functions? </strong></p>
<p style="text-align:justify;">Aggregate functions perform a calculation on a set of values and return a single value. Aggregate functions ignore NULL values except COUNT function. HAVING clause is used, along with GROUP BY, for filtering query using aggregate values.</p>
<p style="text-align:justify;">Following functions are aggregate functions.</p>
<p style="text-align:justify;"><strong>AVG, MIN, CHECKSUM_AGG, SUM, COUNT, STDEV, COUNT_BIG, STDEVP, GROUPING, VAR, MAX, VARP </strong>(<a href="http://blog.sqlauthority.com/2008/01/19/sql-server-introduction-to-aggregate-functions/" target="_blank">Read More Here</a> )</p>
<p style="text-align:justify;"><strong>What do you mean by Table Sample?<br />
</strong>TABLESAMPLE allows you to extract a sampling of rows from a table in the FROM clause. The rows retrieved are random and they are not in any order. This sampling can be based on a percentage of number of rows. You can use TABLESAMPLE when only a sampling of rows is necessary for the application instead of a full result set. (<a href="http://blog.sqlauthority.com/2007/05/27/sql-server-2005-limiting-result-sets-by-using-tablesample-examples/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is Row_Number()?<br />
</strong>ROW_NUMBER() returns a column as an expression that contains the row&#8217;s number within the result set. This is only a number used in the context of the result set, if the result changes, the ROW_NUMBER() will change.
</p>
<p style="text-align:justify;"><strong>What are Ranking Functions?</strong></p>
<p style="text-align:justify;">Ranking functions return a ranking value for each row in a partition. All the ranking functions are non-deterministic. Different Ranking functions are:</p>
<p style="text-align:justify;"><strong><em>ROW_NUMBER () OVER ([&lt;partition_by_clause&gt;] &lt;order_by_clause&gt;)</em></strong><br />
Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.</p>
<p style="text-align:justify;"><strong><em>RANK () OVER ([&lt;partition_by_clause&gt;] &lt;order_by_clause&gt;)</em></strong><br />
Returns the rank of each row within the partition of a result set.</p>
<p style="text-align:justify;"><strong><em>DENSE_RANK () OVER ([&lt;partition_by_clause&gt;] &lt;order_by_clause&gt;)</em></strong><br />
Returns the rank of rows within the partition of a result set, without any gaps in the ranking. (<a href="http://blog.sqlauthority.com/2007/10/09/sql-server-2005-sample-example-of-ranking-functions-row_number-rank-dense_rank-ntile/" target="_blank">Read More Here</a> )
</p>
<p style="text-align:justify;"><strong>What is the difference between UNION and UNION ALL?</strong></p>
<p style="text-align:justify;"><strong><em>UNION</em></strong><em><br />
</em>The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.<strong></strong></p>
<p style="text-align:justify;"><strong><em>UNION ALL</em></strong><em><br />
</em>The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.
</p>
<p style="text-align:justify;">The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table. (<a href="http://blog.sqlauthority.com/2007/03/10/sql-server-union-vs-union-all-which-is-better-for-performance/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is B-Tree?</strong></p>
<p style="text-align:justify;">The database server uses a B-tree structure to organize index information. B-Tree generally has following types of index pages or nodes:</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> <em>root node:</em> A root node contains node pointers to branch nodes which can be only one.</li>
<li> <em>branch nodes:</em> A branch node contains pointers to leaf nodes or other branch nodes which can be two or more.</li>
<li> <em>leaf nodes</em>: A leaf node contains index items and horizontal pointers to other leaf nodes which can be many.</li>
</ul>
<p style="text-align:justify;">© Copyright 2000-2009<a title="Pinal Dave" href="http://www.pinaldave.com/" target="_blank"> Pinal Dave.</a> All Rights Reserved. <a href="http://blog.sqlauthority.com/" target="_blank">SQLAuthority.com</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Data Warehousing, Database, Pinal Dave, SQL, SQL Authority, SQL Data Storage, SQL Function, SQL Index, SQL Interview Questions and Answers, SQL Query, SQL Scripts, SQL Server, SQL Server DBCC, SQL Tips and Tricks, SQL Utility, SQLAuthority, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1012/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1012/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1012/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1012&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Behind the Scene of SQL Server Activity of &#8211; Transaction Log &#8211; Shrinking Log</title>
		<link>http://blog.sqlauthority.com/2008/08/21/sql-server-behind-the-scene-of-sql-server-activity-of-transaction-log-shrinking-log/</link>
		<comments>http://blog.sqlauthority.com/2008/08/21/sql-server-behind-the-scene-of-sql-server-activity-of-transaction-log-shrinking-log/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 01:30:57 +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 Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=864</guid>
		<description><![CDATA[Imran Mohammed continues to help community of SQL Server with his very enthusiastic writing and deep understanding of SQL Server architecture. Let us read what Imran has to say about how Transaction Log works and Shrinking of Log works.
Question from lauraV
Please help me understand. I am taking a full backup once a day, and transaction [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=864&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/#comment-41806" target="_blank">Imran Mohammed</a> continues to help community of SQL Server with his very enthusiastic writing and deep understanding of SQL Server architecture. Let us read what Imran has to say about how Transaction Log works and Shrinking of Log works.</p>
<p style="text-align:justify;"><strong>Question from <a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/#comment-41801" target="_blank">lauraV</a></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>Please help me understand. I am taking a full backup once a day, and transaction logs once every hour. Why is my LDF file not retaining a “normal” size? It continues to grow. I do not want to break the chain and use truncate only, though I have done this and it fixes the problem. I would very much like to understand the underlying problem.<br />
thank you in advance</em>
</p>
<p style="text-align:justify;">I suggest to all my readers to read the answer from Imran, this really explains what really goes on behind the scene of Transaction Log. I have highlighted some of the important keylines and keywords in his answer to lauraV.</p>
<p style="text-align:justify;"><strong>Answer from <a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/#comment-41806" target="_blank">Imran Mohammed</a></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>@LauraV.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>You did not mention which version of SQL Server you are using, Either 2000 or 2005, ( would be easy for us to narrow our answer to questions)</em></p>
<p style="padding-left:30px;text-align:justify;"><strong><em>When ever you take transactional log backup, no matter if you scheduled it or if you take it manually, SQL Server by default will empty transactional log. Meaning after the transactional backup ( Be Careful NOT FULL BACKUP) SQL Server will remove inactive transactions from logfile.</em></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>Which means your transaction file is empty after you take transactional log backup, Empty doesnot mean your logfile became small, NO. the size of the log file will still be the same but it will be empty, all you have to do is shrink logfile, run below command,</em></p>
<p style="padding-left:30px;text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">database_name<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">shrinkfile </span><span style="color:gray;">(</span><span style="color:black;">logfilename</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">)</span></code>
</p>
<p style="padding-left:30px;text-align:justify;"><em>and it will shrink the log file to its minimum size possible,</em></p>
<p style="padding-left:30px;text-align:justify;"><strong><em>In SQL Server 2000:</em></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>Right click database name -&gt; all task -&gt; backup -&gt; in the dialog box, select transactional backup, and click on options ( at the top left side of the box) you will see “remove inactive entries from Transactional log”.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>This means when you take transactional Log backup, SQL Server is removing all inactive entries from SQL Server log file. This is default setting.</em></p>
<p style="padding-left:30px;text-align:justify;"><strong><em>In SQL Server 2005:</em></strong></p>
<p style="padding-left:30px;text-align:justify;"><em>Right Click database name-&gt;task -&gt;Backup in the Dialog box, select backup type Transactional backup, and click options tab (at left side up) and under Transaction log section you will see “Truncate the Transaction log”.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Which mean when SQL Server 2005 performs transactional backup it truncates logfile. This is also default setting.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>NO matter if you use SQL Server 2000 or SQL Server 2005, SQL Server by default (can be changed) will truncate log after performing Transactional backup.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>So simple solution will be shrink log file after you take transactional log backup. You dont have to do it manually You can send this as a response to this transactional bacup job, when ever this job succeed, response to that would be run this script </em></p>
<p style="padding-left:30px;text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">databasename<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">shrinkfile </span><span style="color:gray;">( </span><span style="color:black;">logfile_name</span><span style="color:gray;">, </span><span style="color:black;">1</span><span style="color:gray;">)</span></code>
</p>
<p style="padding-left:30px;text-align:justify;"><em>That might work.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>I will take one more minute to explain what is this active and inactive transaction in the logfile . Please correct me if I am wrong.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>This is how SQL Server works,</em></p>
<p style="text-align:justify;"><strong>Note from Pinal &#8211; Following 4 paragraph is the most interesting part of whole discussion.</strong></p>
<p style="padding-left:30px;text-align:justify;"><em>When a transaction comes to SQL Server, it first comes to transactional log buffer, and then it is hardened to disk ( log file, .ldf ) and then it is written to data file ( .mdf). Then we say the transaction is committed or it is inactive, because the transaction performed all the actions that it should.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>On the other hand, when a transaction comes to SQL Server and it is entered into log buffer and also in transactional log, but not yet entered in data file, its still in the process, then we will say this transaction as active transaction.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>One important point to think is, all the inactive transactions in the log file ( transactions which completed their tasks and are entered in data file) are also present in data file, and SQL Server is smart enough to think, inactive transactions are already in data file and also, they have been backed up( by transactional log backup) hence it thinks, this is the time to get rid of this data and it removes all the inactive transactions.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>But for Active transactions, which are either incomplete or could not complete because of disaster ( sudden power failure….) will be stored in transactional log and will be called acive transactions untill they are entered in data file.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>This will be little bit confusing…</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Read more about this in books online.</em></p>
<p style="padding-left:30px;text-align:justify;"><em>Hope this helps.<br />
Imran.</em>
</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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/864/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/864/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/864/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/864/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/864/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/864/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/864/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/864/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/864/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/864/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/864/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/864/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=864&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/08/21/sql-server-behind-the-scene-of-sql-server-activity-of-transaction-log-shrinking-log/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>
	</item>
		<item>
		<title>SQL SERVER &#8211; DBCC SHRINKFILE Takes Long Time to Run</title>
		<link>http://blog.sqlauthority.com/2008/07/25/sql-server-dbcc-shrinkfile-takes-long-time-to-run/</link>
		<comments>http://blog.sqlauthority.com/2008/07/25/sql-server-dbcc-shrinkfile-takes-long-time-to-run/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 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 Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=736</guid>
		<description><![CDATA[If you are DBA who are involved with Database Maintenance and file group maintenance, you must have experience that many times DBCC SHRINKFILE operations takes long time but any other operations with Database are relative quicker. Rebuilding index is quite resource intensive task but that happens faster than DBCC SHRINKFILE.
Well, answer to this is very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=736&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">If you are DBA who are involved with Database Maintenance and file group maintenance, you must have experience that many times DBCC SHRINKFILE operations takes long time but any other operations with Database are relative quicker. Rebuilding index is quite resource intensive task but that happens faster than DBCC SHRINKFILE.</p>
<p style="text-align:justify;">Well, answer to this is very simple. DBCC SHRINKFILE is a single threaded operation. A single threaded operation does not take advantage of multiple CPUs and have no effect how many RAM are available. Hyperthreaded CPU even provides worst performance.</p>
<p style="text-align:justify;">If you rebuild indexes before you run DBCC SHRINKFILE operations, shrinking file operations will take relatively less time. Rebuilding Index operations takes advantage of multiple CPUs.</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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/736/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/736/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/736/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/736/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/736/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/736/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/736/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/736/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/736/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/736/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/736/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/736/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=736&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/07/25/sql-server-dbcc-shrinkfile-takes-long-time-to-run/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; Clear SQL Server Memory Caches</title>
		<link>http://blog.sqlauthority.com/2008/07/22/sql-server-clear-sql-server-memory-caches/</link>
		<comments>http://blog.sqlauthority.com/2008/07/22/sql-server-clear-sql-server-memory-caches/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 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 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 Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=720</guid>
		<description><![CDATA[If SQL Server is running slow and operations are throwing errors due to lack of memory, it is necessary to look into memory issue. If SQL Server is restarted all the cache memory is automatically cleaned up. In production server it is not possible to restart the server. In this scenario following three commands can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=720&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">If SQL Server is running slow and operations are throwing errors due to lack of memory, it is necessary to look into memory issue. If SQL Server is restarted all the cache memory is automatically cleaned up. In production server it is not possible to restart the server. In this scenario following three commands can be very useful.</p>
<p style="text-align:justify;">When executed following three commands will free up memory for SQL Server by cleaning up its cache.</p>
<p><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">FREESYSTEMCACHE<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">FREESESSIONCACHE<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">FREEPROCCACHE </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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/720/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/720/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/720/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/720/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/720/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=720&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/07/22/sql-server-clear-sql-server-memory-caches/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; Find Current Identity of Table</title>
		<link>http://blog.sqlauthority.com/2008/06/20/sql-server-find-current-identity-of-table/</link>
		<comments>http://blog.sqlauthority.com/2008/06/20/sql-server-find-current-identity-of-table/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 01:30:19 +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 Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=653</guid>
		<description><![CDATA[Many times we need to know what is the current identity of the column. I have found one of my developer using aggregated function MAX() to find the current identity.
USE AdventureWorks
GO
SELECT MAX(AddressID)
FROM Person.Address
GO

However, I prefer following DBCC command to figure out current identity.
USE AdventureWorks
GO
DBCC CHECKIDENT ('Person.Address')
GO 


Reference : Pinal Dave (http://blog.SQLAuthority.com)
      [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=653&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Many times we need to know what is the current identity of the column. I have found one of my developer using aggregated function MAX() to find the current identity.</p>
<p><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT MAX</span><span style="color:gray;">(</span><span style="color:black;">AddressID</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Person.Address<br />
GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/identity1.jpg" alt="" width="261" height="221" /></p>
<p style="text-align:justify;">However, I prefer following DBCC command to figure out current identity.</p>
<p><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">DBCC </span><span style="color:black;">CHECKIDENT </span><span style="color:gray;">(</span><span style="color:red;">'Person.Address'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO </span></code></p>
<p style="text-align:justify;">
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/identity2.jpg" alt="" width="498" height="140" /></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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/653/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/653/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/653/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=653&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/06/20/sql-server-find-current-identity-of-table/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

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

		<media:content url="http://www.pinaldave.com/blogfolder/identity2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 &#8211; A Simple Way To Defragment All Indexes In A Database That Is Fragmented Above A Declared Threshold</title>
		<link>http://blog.sqlauthority.com/2008/03/04/sql-server-2005-a-simple-way-to-defragment-all-indexes-in-a-database-that-is-fragmented-above-a-declared-threshold/</link>
		<comments>http://blog.sqlauthority.com/2008/03/04/sql-server-2005-a-simple-way-to-defragment-all-indexes-in-a-database-that-is-fragmented-above-a-declared-threshold/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 01:30:25 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Index]]></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 Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=526</guid>
		<description><![CDATA[Just a day ago, I received email from regular reader Rajiv Kayasthy about a script which demonstrates the A Simple Way To Defragment All Indexes In A Database That Is Fragmented Above A Declared Threshold. He found this script on TechNet BOL and was attempting to run on SQL Server but was getting continuous error
Msg [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=526&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Just a day ago, I received email from regular reader Rajiv Kayasthy about a script which demonstrates the A Simple Way To Defragment All Indexes In A Database That Is Fragmented Above A Declared Threshold. He found this script on <a href="http://technet.microsoft.com/en-us/library/ms175008.aspx" target="_blank">TechNet BOL</a> and was attempting to run on SQL Server but was getting continuous error</p>
<p><span style="color:#ff0000;"><em>Msg 2501, Level 16, State 45, Line 1<br />
Cannot find a table or object with the name &#8220;TableName&#8221;. Check the system catalog.</em></span></p>
<p style="text-align:justify;">After looking at the script provided on BOL I found that it has very small error. It was retrieving data without prefixing database schema. I have modified original script and corrected it to run on SQL Server 2005.</p>
<p style="text-align:justify;">Following corrected script demonstrates <strong>Simple Way To Defragment All Indexes In A Database That Is Fragmented Above A Declared Threshold.</strong></p>
<p><code style="font-size:12px;"><span style="color:green;">/* Originally created by Microsoft */<br />
/* Error corrected by Pinal Dave (http://www.SQLAuthority.com) */<br />
-- Specify your Database Name<br />
</span><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Declare variables<br />
</span><span style="color:blue;">SET </span><span style="color:black;">NOCOUNT </span><span style="color:blue;">ON</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@tablename </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">128</span><span style="color:gray;">);<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@execstr </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">);<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@objectid </span><span style="color:blue;">INT</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@indexid </span><span style="color:blue;">INT</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@frag </span><span style="color:black;">decimal</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@maxfrag </span><span style="color:black;">decimal</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Decide on the maximum fragmentation to allow for.<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@maxfrag </span><span style="color:blue;">= </span><span style="color:black;">30.0</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Declare a cursor.<br />
</span><span style="color:blue;">DECLARE </span><span style="color:black;">tables </span><span style="color:blue;">CURSOR FOR<br />
SELECT </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">TABLE_SCHEMA </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">))<br />
+</span><span style="color:red;">'.'</span><span style="color:gray;">+</span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:black;">TABLE_NAME </span><span style="color:blue;">AS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">))<br />
</span><span style="color:blue;">AS </span><span style="color:black;">Table_Name<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">INFORMATION_SCHEMA.TABLES<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">TABLE_TYPE </span><span style="color:blue;">= </span><span style="color:red;">'BASE TABLE'</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Create the table.<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">#fraglist </span><span style="color:gray;">(<br />
</span><span style="color:black;">ObjectName </span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">),<br />
</span><span style="color:black;">ObjectId </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">IndexName </span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">255</span><span style="color:gray;">),<br />
</span><span style="color:black;">IndexId </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">Lvl </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">CountPages </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">CountRows </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">MinRecSize </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">MaxRecSize </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">AvgRecSize </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">ForRecCount </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">Extents </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">ExtentSwitches </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">AvgFreeBytes </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">AvgPageDensity </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">ScanDensity decimal</span><span style="color:gray;">,<br />
</span><span style="color:black;">BestCount </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">ActualCount </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">LogicalFrag decimal</span><span style="color:gray;">,<br />
</span><span style="color:black;">ExtentFrag decimal</span><span style="color:gray;">);<br />
</span><span style="color:green;">-- Open the cursor.<br />
</span><span style="color:blue;">OPEN </span><span style="color:black;">tables</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Loop through all the tables in the database.<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">tables<br />
</span><span style="color:blue;">INTO </span><span style="color:#434343;">@tablename</span><span style="color:gray;">;<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Do the showcontig of all indexes of the table<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">#fraglist<br />
</span><span style="color:blue;">EXEC </span><span style="color:gray;">(</span><span style="color:red;">'DBCC SHOWCONTIG (''' </span><span style="color:gray;">+ </span><span style="color:#434343;">@tablename </span><span style="color:gray;">+ </span><span style="color:red;">''')<br />
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS'</span><span style="color:gray;">);<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">tables<br />
</span><span style="color:blue;">INTO </span><span style="color:#434343;">@tablename</span><span style="color:gray;">;<br />
</span><span style="color:blue;">END</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Close and deallocate the cursor.<br />
</span><span style="color:blue;">CLOSE </span><span style="color:black;">tables</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:black;">tables</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Declare the cursor for the list of indexes to be defragged.<br />
</span><span style="color:blue;">DECLARE </span><span style="color:black;">indexes </span><span style="color:blue;">CURSOR FOR<br />
SELECT </span><span style="color:black;">ObjectName</span><span style="color:gray;">, </span><span style="color:black;">ObjectId</span><span style="color:gray;">, </span><span style="color:black;">IndexId</span><span style="color:gray;">, </span><span style="color:black;">LogicalFrag<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">#fraglist<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">LogicalFrag </span><span style="color:gray;">&gt;= </span><span style="color:#434343;">@maxfrag<br />
</span><span style="color:gray;">AND </span><span style="color:magenta;">INDEXPROPERTY </span><span style="color:gray;">(</span><span style="color:black;">ObjectId</span><span style="color:gray;">, </span><span style="color:black;">IndexName</span><span style="color:gray;">, </span><span style="color:red;">'IndexDepth'</span><span style="color:gray;">) &gt; </span><span style="color:black;">0</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Open the cursor.<br />
</span><span style="color:blue;">OPEN </span><span style="color:black;">indexes</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Loop through the indexes.<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">indexes<br />
</span><span style="color:blue;">INTO </span><span style="color:#434343;">@tablename</span><span style="color:gray;">, </span><span style="color:#434343;">@objectid</span><span style="color:gray;">, </span><span style="color:#434343;">@indexid</span><span style="color:gray;">, </span><span style="color:#434343;">@frag</span><span style="color:gray;">;<br />
</span><span style="color:blue;">WHILE </span><span style="color:#434343;">@@FETCH_STATUS </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:blue;">BEGIN</span><span style="color:gray;">;<br />
</span><span style="color:blue;">PRINT </span><span style="color:red;">'Executing DBCC INDEXDEFRAG (0, ' </span><span style="color:gray;">+ </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@tablename</span><span style="color:gray;">) + </span><span style="color:red;">',<br />
' </span><span style="color:gray;">+ </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@indexid</span><span style="color:gray;">) + </span><span style="color:red;">') - fragmentation currently '<br />
</span><span style="color:gray;">+ </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">15</span><span style="color:gray;">),</span><span style="color:#434343;">@frag</span><span style="color:gray;">)) + </span><span style="color:red;">'%'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@execstr </span><span style="color:blue;">= </span><span style="color:red;">'DBCC INDEXDEFRAG (0, ' </span><span style="color:gray;">+ </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@objectid</span><span style="color:gray;">) + </span><span style="color:red;">',<br />
' </span><span style="color:gray;">+ </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:#434343;">@indexid</span><span style="color:gray;">) + </span><span style="color:red;">')'</span><span style="color:gray;">;<br />
</span><span style="color:blue;">EXEC </span><span style="color:gray;">(</span><span style="color:#434343;">@execstr</span><span style="color:gray;">);<br />
</span><span style="color:blue;">FETCH </span><span style="color:black;">NEXT<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">indexes<br />
</span><span style="color:blue;">INTO </span><span style="color:#434343;">@tablename</span><span style="color:gray;">, </span><span style="color:#434343;">@objectid</span><span style="color:gray;">, </span><span style="color:#434343;">@indexid</span><span style="color:gray;">, </span><span style="color:#434343;">@frag</span><span style="color:gray;">;<br />
</span><span style="color:blue;">END</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Close and deallocate the cursor.<br />
</span><span style="color:blue;">CLOSE </span><span style="color:black;">indexes</span><span style="color:gray;">;<br />
</span><span style="color:blue;">DEALLOCATE </span><span style="color:black;">indexes</span><span style="color:gray;">;<br />
</span><span style="color:green;">-- Delete the temporary table.<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:#434343;">#fraglist</span><span style="color:gray;">;<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>, <a href="http://technet.microsoft.com/en-us/library/ms175008.aspx" target="_blank">TechNet BOL</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/526/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/526/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/526/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=526&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/03/04/sql-server-2005-a-simple-way-to-defragment-all-indexes-in-a-database-that-is-fragmented-above-a-declared-threshold/feed/</wfw:commentRss>
		<slash:comments>12</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; Msg: 2593 : There are ROWCOUNT rows in PAGECOUNT pages for object &#8216;OBJECT&#8217;.</title>
		<link>http://blog.sqlauthority.com/2008/02/16/sql-server-msg-2593-there-are-rowcount-rows-in-pagecount-pages-for-object-object/</link>
		<comments>http://blog.sqlauthority.com/2008/02/16/sql-server-msg-2593-there-are-rowcount-rows-in-pagecount-pages-for-object-object/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 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 Error Messages]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=507</guid>
		<description><![CDATA[There are ROWCOUNT rows in PAGECOUNT pages for object &#8216;OBJECT&#8217;.
This message is displayed when DBCC command is ran for any database. It is harmless and displayed for information purpose only. For each database DBCC commands displays number of rows and number of pages it is using. DBCC CHECKALLOC is exception for this messages.

Reference : Pinal [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=507&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><em><strong>There are ROWCOUNT rows in PAGECOUNT pages for object &#8216;OBJECT&#8217;.</strong></em></p>
<p style="text-align:justify;">This message is displayed when DBCC command is ran for any database. It is harmless and displayed for information purpose only. For each database DBCC commands displays number of rows and number of pages it is using. DBCC CHECKALLOC is exception for this messages.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/dbccmsg.gif" alt="" width="470" height="354" /></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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/507/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/507/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/507/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=507&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/02/16/sql-server-msg-2593-there-are-rowcount-rows-in-pagecount-pages-for-object-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/dbccmsg.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Reclaim Space After Dropping Variable-Length Columns Using DBCC CLEANTABLE</title>
		<link>http://blog.sqlauthority.com/2008/01/11/sql-server-reclaim-space-after-dropping-variable-length-columns-using-dbcc-cleantable/</link>
		<comments>http://blog.sqlauthority.com/2008/01/11/sql-server-reclaim-space-after-dropping-variable-length-columns-using-dbcc-cleantable/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 01:30:40 +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 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/2008/01/11/sql-server-reclaim-space-after-dropping-variable-length-columns-using-dbcc-cleantable/</guid>
		<description><![CDATA[All DBA and Developers must have observed when any variable length column is dropped from table, it does not reduce the size of table. Table size stays the same till Indexes are reorganized or rebuild. There is also DBCC command DBCC CLEANTABLE, which can be used to reclaim any space previously occupied with variable length [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=471&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">All DBA and Developers must have observed when any variable length column is dropped from table, it does not reduce the size of table. Table size stays the same till Indexes are reorganized or rebuild. There is also DBCC command DBCC CLEANTABLE, which can be used to reclaim any space previously occupied with variable length columns. Variable length columns include varchar, nvarchar, varchar(max), nvarchar(max), varbinary, varbinary(max), text, ntext, image, sql_variant, and xml. Space can be reclaimed when variable length column is also modified to lesser length.</p>
<p style="text-align:justify;">DBCC command for reclaiming space is very simple. Following example is for AdventureWorks database and Person.Contact table.</p>
<p><code style="font-size:12px;"><span style="color:blue;">DBCC </span><span style="color:black;">CLEANTABLE </span><span style="color:gray;">(</span><span style="color:red;">'AdventureWorks'</span><span style="color:gray;">,</span><span style="color:red;">'Person.Contact'</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">)</span></code></p>
<p>The result of DBCC is displayed below.<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.<br />
DBCC is fully logged operation. It also does not affect temp tables and system tables.
</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>, <a href="http://technet.microsoft.com/en-us/library/ms174418.aspx" target="_blank">BOL &#8211; DBCC CLEANTABLE</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/471/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/471/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/471/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=471&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/01/11/sql-server-reclaim-space-after-dropping-variable-length-columns-using-dbcc-cleantable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 &#8211; Display Fragmentation Information of Data and Indexes of Database Table</title>
		<link>http://blog.sqlauthority.com/2008/01/10/sql-server-2005-display-fragmentation-information-of-data-and-indexes-of-database-table/</link>
		<comments>http://blog.sqlauthority.com/2008/01/10/sql-server-2005-display-fragmentation-information-of-data-and-indexes-of-database-table/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 01:30:16 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL 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>
		<category><![CDATA[SQL DMV]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2008/01/10/sql-server-2005-display-fragmentation-information-of-data-and-indexes-of-database-table/</guid>
		<description><![CDATA[One of my friend involved with large business of medical transcript invited me for SQL Server improvement talk last weekend. I had great time talking with group of DBA and developers. One of the topic which was discussed was how to find out Fragmentation Information for any table in one particular database. For SQL Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=470&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">One of my friend involved with large business of medical transcript invited me for SQL Server improvement talk last weekend. I had great time talking with group of DBA and developers. One of the topic which was discussed was how to find out Fragmentation Information for any table in one particular database. For SQL Server 2000 it was easy to find using DBCC SHOWCONTIG command. DBCC SHOWCONTIG has some limitation for SQL Server 2000.</p>
<p style="text-align:justify;">SQL Server 2005 has sys.dm_db_index_physical_stats dynamic view which returns size and fragmentation information for the data and indexes of the specified table or view. You can run following T-SQL for any database to know detailed information of the database.<br />
<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.dm_db_index_physical_stats</span><span style="color:gray;">(</span><span style="color:magenta;">DB_ID</span><span style="color:gray;">(), </span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'test_contig'</span><span style="color:gray;">), NULL, NULL , </span><span style="color:red;">'DETAILED'</span><span style="color:gray;">)</span></code></p>
<p>Above query returns lots of information, most of the time we only need to know Tablename, IndexName and Percentage of Fragmentation. Following query returns only three most important details mentioned earlier. I have added an extra condition where results are filtered where average fragmentation is greater than 20%.<br />
<code style="font-size:12px;"><span style="color:blue;"><br />
SELECT </span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:black;">i.</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">TableName</span><span style="color:gray;">,<br />
</span><span style="color:black;">i.name </span><span style="color:blue;">AS </span><span style="color:black;">IndexName</span><span style="color:gray;">,<br />
</span><span style="color:black;">indexstats.avg_fragmentation_in_percent<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_db_index_physical_stats</span><span style="color:gray;">(</span><span style="color:magenta;">DB_ID</span><span style="color:gray;">(), NULL, NULL, NULL, </span><span style="color:red;">'DETAILED'</span><span style="color:gray;">) </span><span style="color:black;">indexstats<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">sys.indexes i </span><span style="color:blue;">ON </span><span style="color:black;">i.</span><span style="color:magenta;">OBJECT_ID </span><span style="color:blue;">= </span><span style="color:black;">indexstats.</span><span style="color:magenta;">OBJECT_ID<br />
</span><span style="color:gray;">AND </span><span style="color:black;">i.index_id </span><span style="color:blue;">= </span><span style="color:black;">indexstats.index_id<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">indexstats.avg_fragmentation_in_percent </span><span style="color:gray;">&gt; </span><span style="color:black;">20</span></code></p>
<p>The results will help DBA to make necessary reports.
</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>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/470/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/470/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/470/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/470/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/470/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/470/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/470/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=470&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/01/10/sql-server-2005-display-fragmentation-information-of-data-and-indexes-of-database-table/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; DBCC CHECKDB Introduction and Explanation &#8211; DBCC CHECKDB Errors Solution</title>
		<link>http://blog.sqlauthority.com/2007/11/13/sql-server-dbcc-checkdb-introduction-and-explanation-dbcc-checkdb-errors-solution/</link>
		<comments>http://blog.sqlauthority.com/2007/11/13/sql-server-dbcc-checkdb-introduction-and-explanation-dbcc-checkdb-errors-solution/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 01:30:10 +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 Error Messages]]></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 Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/11/13/sql-server-dbcc-checkdb-introduction-and-explanation-dbcc-checkdb-errors-solution/</guid>
		<description><![CDATA[DBCC CHECKDB checks the logical and physical integrity of all the objects in the specified database. If DBCC CHECKDB ran on database user should not run DBCC CHECKALLOC, DBCC CHECKTABLE, and DBCC CHECKCATALOG on database as DBCC CHECKDB includes all the three command.  Usage of these included DBCC commands is listed below.
DBCC CHECKALLOC &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=406&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">DBCC CHECKDB checks the logical and physical integrity of all the objects in the specified database. If DBCC CHECKDB ran on database user should not run DBCC CHECKALLOC, DBCC CHECKTABLE, and DBCC CHECKCATALOG on database as DBCC CHECKDB includes all the three command.  Usage of these included DBCC commands is listed below.</p>
<p style="text-align:justify;">DBCC CHECKALLOC &#8211; Checks the consistency of disk space allocation structures for a specified database.</p>
<p style="text-align:justify;">DBCC CHECKTABLE &#8211; Checks the integrity of all the pages and structures that make up the table or indexed view.</p>
<p style="text-align:justify;">DBCC CHECKCATALOG &#8211; Checks for catalog consistency within the specified database. The database must be online.</p>
<p style="text-align:justify;">Along with above three DBCC commands it also runs following two tasks to check the validity database (physical as well logical) i.e. validates the contents of every indexed view in the database and Validates the Service Broker data in the database.</p>
<p style="text-align:justify;">If database DBCC check has returned any errors, the best solution is to <strong>RESTORE DATABASE from BACKUP</strong>. (Additional reading : <a href="http://blog.sqlauthority.com/category/sql-backup-and-restore/" target="_blank">SQL Backup and Restore</a>). There is additional keyword REPAIR with DBCC CHECKDB  which can be used to repair database but it is not recommended. I will write additional articles on this subject.</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> , <a href="http://msdn2.microsoft.com/en-us/library/ms176064.aspx" target="_blank">DBCC CHECKDB</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/406/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/406/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=406&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/11/13/sql-server-dbcc-checkdb-introduction-and-explanation-dbcc-checkdb-errors-solution/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>SQLAuthority News &#8211; Best Articles on SQLAuthority.com</title>
		<link>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</link>
		<comments>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 14:00:25 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Add-On]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Coding Standards]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Humor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</guid>
		<description><![CDATA[SQL SERVER &#8211; Cursor to Kill All Process in Database
SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure
SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full
SQL SERVER &#8211; Simple Example of Cursor
SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/01/sql-server-cursor-to-kill-all-process-in-database/">SQL SERVER &#8211; Cursor to Kill All Process in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/">SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/">SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/">SQL SERVER &#8211; Simple Example of Cursor</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/">SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/">SQL SERVER &#8211; Restore Database Backup using SQL Script (T-SQL)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/28/sql-server-t-sql-script-to-find-the-cd-key-from-registry/">SQL SERVER &#8211; T-SQL Script to find the CD key from Registry</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/">SQL SERVER &#8211; Delete Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/05/sql-server-quoted_identifier-onoff-and-ansi_null-onoff-explanation/">SQL SERVER &#8211; QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/10/sql-server-union-vs-union-all-which-is-better-for-performance/">SQL SERVER &#8211; Union vs. Union All &#8211; Which is better for performance?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/">SQL SERVER &#8211; DBCC RESEED Table Identity Value &#8211; Reset Table Identity</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/">SQL SERVER &#8211; @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT &#8211; Retrieve Last Inserted Identity of Record</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/29/sql-server-difference-between-distinct-and-group-by-distinct-vs-group-by/">SQL SERVER &#8211; Difference between DISTINCT and GROUP BY &#8211; Distinct vs Group By</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/">SQL SERVER &#8211; Index Seek Vs. Index Scan (Table Scan)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/01/sql-server-tempdb-is-full-move-tempdb-from-one-drive-to-another-drive/">SQL SERVER &#8211; TempDB is Full. Move TempDB from one drive to another drive</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/03/sql-server-t-sql-paging-query-technique-comparison-sql-2000-vs-sql-2005/">SQL SERVER &#8211; T-SQL Paging Query Technique Comparison &#8211; SQL 2000 vs SQL 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/05/sql-server-performance-optimization-of-sql-query-and-filegroups/">SQL SERVER &#8211; Performance Optimization of SQL Query and FileGroups</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/08/sql-server-search-text-field-charindex-vs-patindex/">SQL SERVER &#8211; Search Text Field &#8211; CHARINDEX vs PATINDEX</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/">SQL SERVER &#8211; 2005 Explanation of TRY…CATCH and ERROR Handling</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-script-to-find-sql-server-on-network/">SQL SERVER &#8211; Script to find SQL Server on Network</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-stored-procedures-advantages-and-best-advantage/">SQL SERVER &#8211; Stored Procedures Advantages and Best Advantage</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/">SQL SERVER &#8211; CASE Statement/Expression Examples and Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/22/sql-server-raid-configuration-raid-10/">SQL SERVER &#8211; Raid Configuration &#8211; RAID 10</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-understanding-new-index-type-of-sql-server-2005-included-column-index-along-with-clustered-index-and-non-clustered-index/">SQL SERVER &#8211; Understanding new Index Type of SQL Server 2005 Included Column Index along with Clustered Index and Non-clustered Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-query-to-find-seed-values-increment-values-and-current-identity-column-value-of-the-table/">SQL SERVER &#8211; Query to Find Seed Values, Increment Values and Current Identity Column value of the table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-six-properties-of-relational-tables/">SQL SERVER &#8211; Six Properties of Relational Tables</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/">SQL SERVER &#8211; TRIM() Function &#8211; UDF TRIM()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/">SQL SERVER &#8211; Difference between Unique Index vs Unique Constraint</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/">SQL SERVER &#8211; 2005 Locking Hints and Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/">SQL SERVER &#8211; Good, Better and Best Programming Techniques</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/">SQL SERVER &#8211; Random Number Generator Script &#8211; SQL Query</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/02/sql-server-2005-top-improvementsenhancements/">SQL SERVER &#8211; 2005 TOP Improvements/Enhancements</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/07/sql-server-20052000-examples-and-explanation-for-goto/">SQL SERVER &#8211; 2005/2000 Examples and Explanation for GOTO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/11/sql-server-explanation-sql-command-go/">SQL SERVER &#8211; Explanation SQL Commando GO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/12/sql-server-2005-list-all-the-database/">SQL SERVER &#8211; 2005 &#8211; List all the database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/">SQL SERVER &#8211; UDF &#8211; Function to Parse AlphaNumeric Characters from String</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/17/sql-server-disable-index-enable-index-alter-index/">SQL SERVER &#8211; Disable Index &#8211; Enable Index &#8211; ALTER Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/18/sql-server-2005-ssms-change-t-sql-batch-separator/">SQL SERVER &#8211; 2005 &#8211; SSMS Change T-SQL Batch Separator</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/20/sql-server-sql-code-formatter-tools/">SQL SERVER &#8211; SQL Code Formatter Tools</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/">SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/23/sql-server-2005-northwind-database-or-adventureworks-database-samples-databases/">SQL SERVER &#8211; 2005 NorthWind Database or AdventureWorks Database &#8211; Samples Databases</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/26/sql-server-2005-find-table-without-clustered-index-find-table-with-no-primary-key/">SQL SERVER &#8211; 2005 Find Table without Clustered Index &#8211; Find Table with no Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/27/sql-server-2005-limiting-result-sets-by-using-tablesample-examples/">SQL SERVER &#8211; 2005 Limiting Result Sets by Using TABLESAMPLE &#8211; Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/29/sql-server-2005-change-database-compatible-level-backward-compatibility/">SQL SERVER &#8211; 2005 Change Database Compatible Level &#8211; Backward Compatibility</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/">SQL SERVER &#8211; 2005 Constraint on VARCHAR(MAX) Field To Limit It Certain Length</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/06/sql-server-database-coding-standards-and-guidelines-complete-list-download/">SQL SERVER Database Coding Standards and Guidelines Complete List Download</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/">SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/">SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/11/sql-server-2005-t-sql-paging-query-technique-comparison-over-and-row_number-cte-vs-derived-table/">SQL SERVER &#8211; 2005 T-SQL Paging Query Technique Comparison (OVER and ROW_NUMBER()) &#8211; CTE vs. Derived Table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/14/sql-server-easy-sequence-of-select-from-join-where-group-by-having-order-by/">SQL SERVER &#8211; Easy Sequence of SELECT FROM JOIN WHERE GROUP BY HAVING ORDER BY</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/">SQL SERVER &#8211; 2005 &#8211; UDF &#8211; User Defined Function to Strip HTML &#8211; Parse HTML &#8211; No Regular Expression</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/">SQL SERVER &#8211; Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/22/sql-server-explanation-and-comparison-of-nullif-and-isnull/">SQL SERVER &#8211; Explanation and Comparison of NULLIF and ISNULL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/">SQL SERVER &#8211; 2005 Row Overflow Data Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/24/sql-server-comparison-index-fragmentation-index-de-fragmentation-index-rebuild-sql-server-2000-and-sql-server-2005/">SQL SERVER &#8211; Comparison Index Fragmentation, Index De-Fragmentation, Index Rebuild &#8211; SQL SERVER 2000 and SQL SERVER 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/03/sql-server-comparison-similarity-and-difference-temptable-vs-tempvariable/">SQL SERVER &#8211; Comparison : Similarity and Difference #TempTable vs @TempVariable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/04/sql-server-definition-comparison-and-difference-between-having-and-where-clause/">SQL SERVER &#8211; Definition, Comparison and Difference between HAVING and WHERE Clause</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/05/sql-server-2005-best-practices-analyzer-tutorial-sample-example/">SQL SERVER &#8211; 2005 Best Practices Analyzer Tutorial &#8211; Sample Example</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/10/sql-server-2005-list-all-stored-procedure-modified-in-last-n-days/">SQL SERVER &#8211; 2005 &#8211; List All Stored Procedure Modified in Last N Days</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/11/sql-server-count-duplicate-records-rows/">SQL SERVER &#8211; Count Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/">SQL SERVER &#8211; CASE Statement in ORDER BY Clause &#8211; ORDER BY using Variable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/18/sql-server-restore-database-without-or-with-backup-everything-about-restore-and-backup/">SQL SERVER &#8211; Restore Database Without or With Backup &#8211; Everything About Restore and Backup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-function-to-get-previous-and-next-work-day-exclude-saturday-and-sunday/">SQL SERVER &#8211; UDF &#8211; Function to Get Previous And Next Work Day &#8211; Exclude Saturday and Sunday</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/04/sql-server-one-thing-all-dba-must-know/">SQL SERVER &#8211; One Thing All DBA Must Know</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/07/sql-server-2005-list-tables-in-database-without-primary-key/">SQL SERVER &#8211; 2005 &#8211; List Tables in Database Without Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/10/sql-server-2005-find-stored-procedure-create-date-and-modified-date/">SQL SERVER &#8211; 2005 &#8211; Find Stored Procedure Create Date and Modified Date</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/11/sql-server-udf-validate-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/14/sql-server-what-is-sql-how-to-pronounce-sql/">SQL SERVER &#8211; What is SQL? How to pronounce SQL?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/16/sql-server-2005-difference-and-similarity-between-newsequentialid-and-newid/">SQL SERVER &#8211; 2005 &#8211; Difference and Similarity Between NEWSEQUENTIALID() and NEWID()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/17/sql-server-2005-explanation-and-script-for-online-index-operations-create-rebuild-drop/">SQL SERVER &#8211; 2005 &#8211; Explanation and Script for Online Index Operations &#8211; Create, Rebuild, Drop</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/">SQL SERVER &#8211; Find Last Day of Any Month &#8211; Current Previous Next</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/">SQL SERVER &#8211; T-SQL Script to Insert Carriage Return and New Line Feed in Code</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/24/sql-server-2005-t-sql-script-to-attach-and-detach-database/">SQL SERVER &#8211; 2005 &#8211; T-SQL Script to Attach and Detach Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/28/sql-server-actual-execution-plan-vs-estimated-execution-plan/">SQL SERVER &#8211; Actual Execution Plan vs. Estimated Execution Plan</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/">SQL SERVER &#8211; 2005 &#8211; Search Stored Procedure Code &#8211; Search Stored Procedure Text</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-primary-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Primary Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/06/sql-server-2005-introduction-and-explanation-to-sqlcmd/">SQL SERVER &#8211; 2005 &#8211; Introduction and Explanation to sqlcmd</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/">SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/09/sql-server-2005-start-stop-restart-sql-server-from-command-prompt/">SQL SERVER &#8211; 2005 &#8211; Start Stop Restart SQL Server From Command Prompt</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/16/sql-server-2005-list-all-the-constraint-of-database-find-primary-key-and-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; List All The Constraint of Database &#8211; Find Primary Key and Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/18/sql-server-udf-validate-positive-integer-function-validate-natural-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Positive Integer Function &#8211; Validate Natural Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/25/sql-server-effect-of-transaction-on-local-variable-after-rollback-and-after-commit/">SQL SERVER &#8211; Effect of TRANSACTION on Local Variable &#8211; After ROLLBACK and After COMMIT</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/01/sql-server-2005-output-clause-example-and-explanation-with-insert-update-delete/">SQL SERVER &#8211; 2005 &#8211; OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/09/sql-server-2005-sample-example-of-ranking-functions-row_number-rank-dense_rank-ntile/">SQL SERVER &#8211; 2005 &#8211; Sample Example of RANKING Functions &#8211; ROW_NUMBER, RANK, DENSE_RANK, NTILE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/16/sql-server-three-t-sql-script-to-create-primary-keys-on-table/">SQL SERVER &#8211; Three T-SQL Script to Create Primary Keys on Table</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/395/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/395/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/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>
	</channel>
</rss>