<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8619066</id><updated>2011-11-27T15:21:23.583-08:00</updated><category term='index'/><category term='What&apos;s New'/><category term='Performance'/><category term='defrag'/><category term='RowCount Count'/><category term='Database'/><category term='reindex'/><title type='text'>SQL This!</title><subtitle type='html'>The blog...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8619066.post-8571865447222876954</id><published>2011-01-17T11:48:00.001-08:00</published><updated>2011-01-31T10:53:09.671-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RowCount Count'/><title type='text'>Lighting Quick Table RowCounts for your Tables</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://t3.gstatic.com/images?q=tbn:ANd9GcR6m_WRlPF6tgxaxJPl7zzVVsPF8my4DCzJpE1S0SyfMnv7tPsz"&gt;&lt;img style="float: left; margin: 0pt 10px 10px 0pt; cursor: pointer; width: 200px; height: 150px;" src="http://t3.gstatic.com/images?q=tbn:ANd9GcR6m_WRlPF6tgxaxJPl7zzVVsPF8my4DCzJpE1S0SyfMnv7tPsz" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you are familiar with TSQL and want to get a row count from your tables you might be tempted to run a simple&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Select count(*) from myTable&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;This however can be a lengthy wait if you have millions and millions of records.  Not to mention the potential impact on a production system.  Instead consider selecting your rowcounts from your system tables&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT  OBJECT_NAME(id), ROWS, indid&lt;br /&gt;FROM sysindexes &lt;br /&gt;WHERE indid &lt; 2&lt;br /&gt;AND OBJECT_NAME(id) IN ('myTableName')&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Looking forward beyond Sql Server 2005 and beyond the following select should be used and will provide you with the needed information as system tables access may be depracated&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT DISTINCT OBJECT_NAME(P.object_id) AS [Name], ROWS FROM sys.indexes I&lt;br /&gt;INNER JOIN sys.partitions P ON P.object_id = I.object_id AND P.index_id = I.index_id&lt;br /&gt;WHERE I.index_id &lt; 2&lt;br /&gt;AND OBJECT_NAME(P.object_id) IN ('myTableName')&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;So why am I searching for index smaller than 2?  In short from the article below you'll find that pure data pages have indid=0, and clustered index pages and the data pages have indid=1, so searching for this information as &lt; 2 covers us.  I also took the liberty of adding a distinct.  I've not currently read why sometimes there may be duplicate rows, but the objectid of the table may be different and doing a Distinct helps to narrow the results to data you care about.&lt;br /&gt;&lt;br /&gt;http://support.microsoft.com/kb/75191&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-8571865447222876954?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/8571865447222876954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2011/01/lighting-quick-table-rowcounts-for-your.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8571865447222876954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8571865447222876954'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2011/01/lighting-quick-table-rowcounts-for-your.html' title='Lighting Quick Table RowCounts for your Tables'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-8428662663024245549</id><published>2010-08-23T10:44:00.000-07:00</published><updated>2010-08-24T16:00:28.699-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='What&apos;s New'/><title type='text'>New Look... New Stuff</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://t0.gstatic.com/images?q=tbn:ANd9GcRB2t24eoxSJOjbSYsHBXXVZh4M7d3yMtywqgJMcBHGR66japo&amp;t=1&amp;usg=__sl-wgtj7fCZNlVQPI-yR83Szwj8="&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 221px; height: 228px;" src="http://t0.gstatic.com/images?q=tbn:ANd9GcRB2t24eoxSJOjbSYsHBXXVZh4M7d3yMtywqgJMcBHGR66japo&amp;t=1&amp;usg=__sl-wgtj7fCZNlVQPI-yR83Szwj8=" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;Hi everyone... So some new things are going to be happening with my blog... I'm going to pick some helpful hints that help me and my fellow DBA's with what we do on a Daily or weekly basis.  These should be helpful for all but you are more than welcomed to share your experiences on what Tips help you the most.  One thing that is comming is an article on Wait times... I had the pleasure of trying out Confio's Ignite software.  And while it does some really great things, such as pointing out where the bottle necks are for performance on your server.  It can be pretty pricey and really does not introduce anything you can't already do.&lt;br /&gt;&lt;br /&gt;I'm planning on rolling out a short but continuous list of I/O wait times what they are and how to use them to boost performance on your SQL Server within the coming weeks,  I will not concentrate on Sql Server 2005/2008 alone, I know that is the trend in the tech community but there are still many organizations that use Sql Server 2000, I mean... why upgrade Legacy systems and pay more money when those systems are perfectly fine, and fine tunned?  Sometimes all that is needed is a little tunning :)&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-8428662663024245549?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/8428662663024245549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2010/08/new-look-new-stuff.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8428662663024245549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8428662663024245549'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2010/08/new-look-new-stuff.html' title='New Look... New Stuff'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-6723208782132059303</id><published>2010-04-26T08:32:00.001-07:00</published><updated>2010-04-27T14:58:34.727-07:00</updated><title type='text'>iPad Wifi Networking Issues</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.zatznotfunny.com/wordpress/wp-content/uploads/2010/01/ipad-with-keyboard-dock-420x408.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 100px; height: 100px;" src="http://www.zatznotfunny.com/wordpress/wp-content/uploads/2010/01/ipad-with-keyboard-dock-420x408.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;I had recently been reading a lot about the the wifi issues surrounding the iPad, and though this post is not SQL related, it kinda is for me.  You see I was using a Remote Desktop app on my iPad when the connection started to drop out on me.  Something new that I had started to experience.  I determined that it had to do with bluetooth being enabled.  I tried disabling it and the iPad returned to it's normal bandwidth loving behavior... the thing was that I was using a bluetooth keyboard with it to type up my sql... so I had to find an alternate solution... &lt;br /&gt;&lt;br /&gt;Solution one... you can actually just turn up the brightness on your iPad and it will keep the wifi from going into sleep mode.. wierd right?&lt;br /&gt;&lt;br /&gt;or in my case so I didn't need to fumble around I decided to changes some wifi settings of my TrendNet Router, I found the settings at the macrumors forum,&lt;br /&gt;&lt;br /&gt;http://forums.macrumors.com/showthread.php?t=889348&amp;page=6&lt;br /&gt;&lt;br /&gt;the settings on my wireless that fixed my problem (apparently permanently) &lt;br /&gt;&lt;clip&gt;&lt;br /&gt;Under the Advanced Wireless Settings...&lt;br /&gt;Change the Beacon Interval to 75&lt;br /&gt;Fragmentation Threshold to 2304&lt;br /&gt;RTS Threshold to 2307&lt;br /&gt;&lt;/end clip&gt;&lt;br /&gt;&lt;br /&gt;To this I say to the original poster (WesleyB).. great find! Oh sure I could just use the virtual keyboard and not mess with my router, and sure I could just turn up the brightness on my device... but I love just picking up the iPad and quickly logging in to my Sql Server and pick up right where I left off. no fuss, no muss...&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-6723208782132059303?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/6723208782132059303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2010/04/ipad-wifi-networking-issues.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6723208782132059303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6723208782132059303'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2010/04/ipad-wifi-networking-issues.html' title='iPad Wifi Networking Issues'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-6061481133230761958</id><published>2010-02-17T07:25:00.000-08:00</published><updated>2010-02-17T08:04:10.082-08:00</updated><title type='text'>New Ranking tutorial</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://aboutblog.net/Images/Wordpress/increase_ranking.png"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 100px; height: 100px;" src="http://aboutblog.net/Images/Wordpress/increase_ranking.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;This is kinda cool.  I currently do not have a need for it as my job does not require me to write new tsql code on a daily basis anymore.  However, when I used to write ranking code it was always a LONG and TEDIOUS process not really because of the Ranking code, but mostly because of what it takes to get to the ranking code.  ARG!  My Ranking routine believe it or not consisted of a small segment of code with a CURSOR!&lt;br /&gt;&lt;br /&gt;This is an snippet of code from what I used to use and is actually still in production today&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;declare tstcur CURSOR FOR SELECT id FROM @temp&lt;br /&gt;declare @rank as integer&lt;br /&gt;declare @tID as integer&lt;br /&gt;OPEN tstcur&lt;br /&gt;FETCH NEXT FROM tstcur &lt;br /&gt;INTO @tID&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt; &lt;br /&gt; select @rank = count(*)+1  FROM @temp WHERE final_score &gt; (select final_score from @temp where id = @tID)&lt;br /&gt; insert into @temp (id, Division, responses, max_points, total_points, final_score, rank)&lt;br /&gt; select id, Division, 0, max_points, total_points, final_score, 0 from @temp where id = @tID&lt;br /&gt; update  @temp set rank = @rank  where id = @tID&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM tstcur INTO @tID&lt;br /&gt;END&lt;br /&gt;CLOSE tstcur&lt;br /&gt;DEALLOCATE tstcur&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;as you can see it's not really elegant but it DID get the job done.  IF you need this type of code you may certainly reproduce it for your own Sql Server 2000 needs.  &lt;br /&gt;&lt;br /&gt;I do prefer the new method of Ranking using Sql Server 2005 (or 2008).  That is the Ranking function built right into the TSQL language so the above code would look like this:&lt;br /&gt;&lt;blockquote&gt;SELECT RANK()  OVER ( &lt;br /&gt;   ORDER BY final_score) AS [Rank],&lt;br /&gt;id, Division, responses, max_points, total_points, final_score&lt;br /&gt;FROM @temp &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I quite like the non-cursor solution, and if you've read other articles by me you'll know that I'm not at all a fan of cursors (they're just plain evil!) :)&lt;br /&gt;&lt;br /&gt;For a full tutorial on how to use the new Ranking feature... check out&lt;br /&gt;&lt;a href="http://www.mssqltips.com/tip.asp?tip=1944&amp;ctc"&gt;Ranking Functions in Sql Server 2005 and 2008&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-6061481133230761958?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/6061481133230761958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2010/02/new-ranking-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6061481133230761958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6061481133230761958'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2010/02/new-ranking-tutorial.html' title='New Ranking tutorial'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-4164506632672500773</id><published>2009-12-02T07:22:00.000-08:00</published><updated>2010-02-23T08:37:36.418-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Rename a Sql Server Database</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_eVyQk0gZWrQ/S4QEFYKfntI/AAAAAAAAArc/Z5igQ53RTPA/s1600-h/hello-my-name-is.jpg"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 120px; height: 70px;" src="http://3.bp.blogspot.com/_eVyQk0gZWrQ/S4QEFYKfntI/AAAAAAAAArc/Z5igQ53RTPA/s320/hello-my-name-is.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5441478740202725074" /&gt;&lt;/a&gt;&lt;br /&gt;Often when a database needs to be renamed a common tool that I've used in the past was always to use the sp_renamedb procedure.  And that's one of the reasons I love the internet,  there is always a better way to do something.  Take the tips on how to rename your database without the use of this procedure.  What is neat about the following article is that it also changes the logical and physical names of the database.  &lt;br /&gt;see more at this link...&lt;br /&gt;http://www.mssqltips.com/tip.asp?tip=1891&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-4164506632672500773?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/4164506632672500773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/12/rename-sql-server-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4164506632672500773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4164506632672500773'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/12/rename-sql-server-database.html' title='Rename a Sql Server Database'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_eVyQk0gZWrQ/S4QEFYKfntI/AAAAAAAAArc/Z5igQ53RTPA/s72-c/hello-my-name-is.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-4643879834537014503</id><published>2009-08-11T22:13:00.000-07:00</published><updated>2009-08-12T15:03:41.709-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Boosting Performance</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM8N-jb7pI/AAAAAAAAApo/qKL_Em0vSV4/s1600-h/performance.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 120px; height: 90px;" src="http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM8N-jb7pI/AAAAAAAAApo/qKL_Em0vSV4/s320/performance.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5369201391583358610" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;F&lt;/span&gt;ixing smallish databases which are less than 1-2 gb may be just annoying when you are dealing with multiple indexes, but try managing some of those larger ERP databases with literally thousands of tables!  Talk about a database from hell, having to sift through 10 of thousands of indexes can be a real chore if you're searching for performance bottle necks.  There are some great solutions out there that all cost money per instance or per site license and can get quite pricey.  But just about all of those products are charging you for something you can do on your own.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;T&lt;/span&gt;he article below is an extension of my previous blog on &lt;a href="http://sqlthis.blogspot.com/2005/04/defrag-those-indexes-maintenance.html"&gt;maintaining those indexes&lt;/a&gt; It's the script that has evolved from some very basic loops and DMV ( dm_db_index_physical_stats ).  In my script (follow the link below) You'll find that I chose to stick to a SAMPLED stats, which essentially looks at the number of compressed pages.  If you're talking millions of row of data and a very short maintenance window, you're going to want to stick to SAMPLED, otherwise, you'll opt for the full DETAILED search if&lt;br /&gt;&lt;br /&gt;A) your maintenance window is greater than the amount of time it takes for a DETAIL report to be returned&lt;br /&gt;B) your database is small enough&lt;br /&gt;&lt;br /&gt;One of the problems that I've ran into with my production databases that use a FULL recovery model is the maintaining the size of the transaction logs.  The problem is that I COULD switch them over to be SIMPLE recovery models, and then the transaction log would not grow out of control during the rebuild / reorganization (Defrag) of the indexes, but I've found this not to be an ideal situation, since in my organization even though I have a maintenance window on the weekends, the business comes first, so if they require access to their data, I must make it available.  Having good backups that allow the company to return up to the minute before failure using the FULL recovery model is important to us.  So in the script (see link below)&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.devx.com/dbzone/Article/42447"&gt; &lt;br /&gt;Keep Your SQL Server Indexes Fragmentation Free&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;My DevX article was all about Sql Server 2005 and Sql Server 2008, but what about Sql Server 2000?  surely you don't want to be stuck just running a performance monitor on your all your 2000 servers right?  Here is the updated 2000 script to find all fragmented tables in 2000 along with the DBCC DBREINDEX wich will rebuild them for you.  &lt;br /&gt;&lt;br /&gt;Catch-22: if the table has less than 1000 rows, a rebuild will not change anything and you may be left with having to drop and recreate the index manually anyways.&lt;br /&gt;&lt;br /&gt;The Code:&lt;br /&gt;...I created a temp table manually to capture the results of SHOWCONTIG which I pipe to a grid result using the WITH TABLERESULTS hint, next this is joined against the information schema tables table.  In the Where clause I specified that we are interested in 'Base Table's only so that we don't get a lot of system table specific stuff.  I also added the cirteria that we want to see only fragmented tables of 5% and that have over 1000 rows.  In my case my legacy databases are all well under 50gb and thus this query makes sense.  This example use a cursor, as it's an old script, but I'll post up a cursor-less version as I prefer cursor-less solutions.&lt;br /&gt;&lt;br /&gt;As always watch those log files when you are defragging indexes!&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;USE YourDatabaseName--Enter the name of the database you want to reindex&lt;br /&gt;&lt;br /&gt;CREATE TABLE #db_defrag &lt;br /&gt;( ObjectName VARCHAR(255), &lt;br /&gt;ObjectID INT, &lt;br /&gt;IndexName VARCHAR(255),&lt;br /&gt; IndexID INT, &lt;br /&gt; [LEVEL] INT, &lt;br /&gt; Pages INT, &lt;br /&gt; [ROWS] BIGINT, &lt;br /&gt; MinRecordSize INT, &lt;br /&gt; MaximumRecordSize INT, &lt;br /&gt; AverageRecordSize INT, &lt;br /&gt; ForwardedRecords INT, &lt;br /&gt; Extents INT, &lt;br /&gt; ExtentSwitches INT,&lt;br /&gt; AverageFreeBytes DECIMAL(20,2), &lt;br /&gt; AveragePageDensity DECIMAL(20,2), &lt;br /&gt; ScanDensity DECIMAL(20,2), &lt;br /&gt; BestCount INT, &lt;br /&gt; ActualCount INT, &lt;br /&gt; LogicalFragmentation DECIMAL(20,2), &lt;br /&gt; ExtentFragmentation DECIMAL(20,2))&lt;br /&gt;  &lt;br /&gt;DECLARE @sql AS VARCHAR(100)  &lt;br /&gt;&lt;br /&gt;SET @sql ='DBCC SHOWCONTIG WITH TABLERESULTS'&lt;br /&gt;&lt;br /&gt;  INSERT INTO #db_defrag   &lt;br /&gt;  EXEC (@sql)&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;DECLARE @TableName varchar(255)&lt;br /&gt;&lt;br /&gt;DECLARE TableCursor CURSOR FOR&lt;br /&gt;SELECT table_name  FROM information_schema.tables tbl&lt;br /&gt;INNER JOIN #db_defrag dfrg ON tbl.table_name = dfrg.ObjectName &lt;br /&gt;WHERE table_type = 'base table' AND dfrg.LogicalFragmentation &gt;= 5 AND [ROWS] &gt; 1000&lt;br /&gt;ORDER BY  LogicalFragmentation DESC &lt;br /&gt;&lt;br /&gt;OPEN TableCursor&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM TableCursor INTO @TableName&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;DBCC DBREINDEX(@TableName,' ',90)&lt;br /&gt;SET @sql = 'UPDATE STATISTICS ' + @TableName &lt;br /&gt;EXEC (@Sql)&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM TableCursor INTO @TableName&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;CLOSE TableCursor&lt;br /&gt;&lt;br /&gt;DEALLOCATE TableCursor&lt;br /&gt;  &lt;br /&gt;DROP TABLE #db_defrag&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-4643879834537014503?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/4643879834537014503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/08/boosting-performance.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4643879834537014503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4643879834537014503'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/08/boosting-performance.html' title='Boosting Performance'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM8N-jb7pI/AAAAAAAAApo/qKL_Em0vSV4/s72-c/performance.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-7649544826807839583</id><published>2009-07-21T09:47:00.000-07:00</published><updated>2009-08-12T14:58:34.171-07:00</updated><title type='text'>UTO! Unidentified Table Object</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM7BENuWII/AAAAAAAAApY/WwCHa31lRHA/s1600-h/UFO.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 150px; height: 66px;" src="http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM7BENuWII/AAAAAAAAApY/WwCHa31lRHA/s200/UFO.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5369200070252976258" /&gt;&lt;/a&gt;&lt;br /&gt;It's been a while since I've updated the blog, but I Did want to mention that I am working on a neat article, which focuses on my passion for performance.  Stay tuned for the latest details...&lt;br /&gt;&lt;br /&gt;in the mean time, have you ever been stuck with someone else's database?  Or how'bout a vendor database where someone needs you to extend a task.  Well finding the stored procedures is relatively simple.  Remember just go through profiler, run the process and you can monitor which stored procedures are called sometimes this also provides you some feedback on which tables are being accessed.  Other times you may need to report on some of this information, so you may need to search the database on where they decided to store such information.  I extended my own version of Narayana's searchalltables procedure, in this new version you'll notice that you get to also search text (and ntext) fields along with only a single while loop.  &lt;br /&gt;&lt;br /&gt;Check out the latest script and article here:&lt;br /&gt;&lt;a href="http://www.devx.com/dbzone/Article/42340/0"&gt;Searching Unidentified Tables and Columns for Specific Content&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-7649544826807839583?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/7649544826807839583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/07/uto-unidentified-table-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7649544826807839583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7649544826807839583'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/07/uto-unidentified-table-object.html' title='UTO! Unidentified Table Object'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_eVyQk0gZWrQ/SoM7BENuWII/AAAAAAAAApY/WwCHa31lRHA/s72-c/UFO.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-7175484039407481567</id><published>2009-06-23T11:10:00.000-07:00</published><updated>2009-08-12T15:01:07.971-07:00</updated><title type='text'>Mail Call!</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_eVyQk0gZWrQ/SoM7nb9SrhI/AAAAAAAAApg/YUmABPT-Oe0/s1600-h/Mail.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 129px; height: 88px;" src="http://1.bp.blogspot.com/_eVyQk0gZWrQ/SoM7nb9SrhI/AAAAAAAAApg/YUmABPT-Oe0/s320/Mail.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5369200729461534226" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;E&lt;/span&gt;mail,  You use it, your colleges use it, even your systems use it.  It's a part of everyday business.  If you are a Sql Developer you have probably figured out how to implement email already, Often times I've seen many DBA's and Developers implement it from outside of SQL Server in rather ingenious ways...&lt;br /&gt;&lt;br /&gt;This article outlines how to setup Sql Server Mail in Sql Server 2000 and 2005 (2008 is the same as Sql Server 2005).  By bringing mail inside of your server you can now send reports, alerts and other needed information based on the triggers and alerts that matter to you most.  Making execution calls to xp_cmdshell to an opensource program (Blat) and sp_send_dbmail calls for Sql Server 2005 help leverage reporting from Sql Server.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.devx.com/dbzone/Article/42178"&gt;Sending E-mail from SQL Server 200X&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-7175484039407481567?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/7175484039407481567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/06/mail-call.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7175484039407481567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7175484039407481567'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/06/mail-call.html' title='Mail Call!'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_eVyQk0gZWrQ/SoM7nb9SrhI/AAAAAAAAApg/YUmABPT-Oe0/s72-c/Mail.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-1824227527263761474</id><published>2009-05-21T21:23:00.000-07:00</published><updated>2009-05-21T21:28:42.693-07:00</updated><title type='text'>Limit your responses , please.</title><content type='html'>When you are faced with request from users who will ask things like... i want to know the top 2 machines of every model type that have active leads, you may find yourself baffled and stunned to find that the Select TOP n does very little to help you out.  The following article address the issue completely whether  you're a sql developer or NOT.  For myself it was a new look at existing solutions that we had employed all which were cumbersome and tedious to maintain, the solutions in the article describe the best approach which is easily extensible and flexible.&lt;br /&gt;&lt;a href="http://www.devx.com/dbzone/Article/41808"&gt;&lt;span style="font-size:100%;"&gt;Limit Groups by Number Using Transact-SQL or MS Access&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-1824227527263761474?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/1824227527263761474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/05/limit-your-responses-please.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/1824227527263761474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/1824227527263761474'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/05/limit-your-responses-please.html' title='Limit your responses , please.'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-2566820505402453690</id><published>2009-04-09T11:37:00.000-07:00</published><updated>2009-04-09T11:48:50.940-07:00</updated><title type='text'>MSDE enable TCP/IP or Named Pipes</title><content type='html'>&lt;span style="font-size: 10pt; font-family: arial;"&gt;&lt;o:p&gt;&lt;span class="titles1"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;p style="margin: 0in 0in 0pt;"&gt;&lt;strong&gt;&lt;span style="font-weight: normal;"&gt;When you inherit a new server sometimes you find that you can't connect to the server, to fix that you may need to simply enable the protocol via Sql Server Network Utility (svrnetcn) that is listening For MSDE.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;In Windows, click &lt;strong&gt;Start&lt;/strong&gt; and &lt;strong&gt;Run&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Enter &lt;strong&gt;svrnetcn&lt;/strong&gt; and click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Under the &lt;strong&gt;General tab&lt;/strong&gt;, verify that the correct instance for the server is displayed in the &lt;strong&gt;Instance(s) on this server&lt;/strong&gt; box.&lt;/span&gt;&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Highlight your desired protocol and click &lt;strong&gt;Enable&lt;/strong&gt; (double clicking the name also moves the protocol to the enabled protocols box).&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Restart the Sql Server Instance&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;In Windows, click &lt;strong&gt;Start&lt;/strong&gt; and &lt;strong&gt;Run&lt;/strong&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;enter services.msc&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Locate the MSSQLSERVER instance you modified in the Sql Server Network Utility and Restart the service.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;You may wish to ensure that your users are not logged on or at least notified of this change as it will kick them out of the application&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-2566820505402453690?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/2566820505402453690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/04/msde-enable-tcpip-or-named-pipes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/2566820505402453690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/2566820505402453690'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/04/msde-enable-tcpip-or-named-pipes.html' title='MSDE enable TCP/IP or Named Pipes'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-7195020770808715340</id><published>2009-03-17T22:04:00.000-07:00</published><updated>2009-03-17T22:10:09.382-07:00</updated><title type='text'>SSIS SOS!</title><content type='html'>If you have been regretting making the move from Sql Server 2000 to Sql Server 2005, you will be in complete shock and awe when you find that you no longer have DTS to move your data around.  The good news is that in Sql Server 2005 you get Sql Server Integration Services (SSIS) a full feature ETL product for Sql Server 2005.  If you want to move things moving quickly take a look at the &lt;a href="http://www.databasejournal.com/features/mssql/article.php/3580216/SQL-Server-2005-Import--Export-Wizard.htm"&gt;Sql Server 2005 Import / Export Wizard&lt;/a&gt; short article which outlines just how easy shuffling your data around can really be.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-7195020770808715340?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/7195020770808715340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/03/ssis-sos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7195020770808715340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/7195020770808715340'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/03/ssis-sos.html' title='SSIS SOS!'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-4386378971608173682</id><published>2009-03-17T11:56:00.000-07:00</published><updated>2009-03-17T11:58:12.411-07:00</updated><title type='text'>Comma delimited Lists</title><content type='html'>Take the post about finding columns and incorporate it with this post from a college of mine. &lt;br /&gt;&lt;a href="http://www.artfulsoftware.com/infotree/tip.php?id=753"&gt;http://www.artfulsoftware.com/infotree/tip.php?id=753&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now you're off and running turning lists to comma lists, in corporate that with the list table function I posted sometime back, and you can go backwards and forwards!&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-4386378971608173682?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/4386378971608173682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/03/comma-delimited-lists.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4386378971608173682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/4386378971608173682'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/03/comma-delimited-lists.html' title='Comma delimited Lists'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-758574419879744132</id><published>2009-03-17T11:43:00.000-07:00</published><updated>2009-03-17T11:47:56.596-07:00</updated><title type='text'>Find me a column...</title><content type='html'>Forgive the fact that the following SQL is not &lt;span style="font-style: italic;"&gt;formatted&lt;/span&gt;, but this topic came up today on a list that I frequent, which was how to get all the fieldnames of a view (or table etc).  this dandy little select statement will gather just that and all you need to really parse it for is your table name or column name... maybe you want to know how many times you named something "EntryTime" this is an easy way to find all that information at a glance.&lt;br /&gt;&lt;br /&gt;This is a Sql Server 2005 version  &lt;span style="font-size:78%;"&gt;(If you need it I can post a Sql Server 2000 version as well.)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SELECT t.name AS TableName,&lt;br /&gt;sc.name AS SchemaName,&lt;br /&gt;c.name AS ColumnName,&lt;br /&gt;c.column_id AS ColumnID,&lt;br /&gt;c.precision AS [Precision],&lt;br /&gt;types.name AS TypeName,&lt;br /&gt;basetypes.name AS BaseTypeName,&lt;br /&gt;st.name AS TypeSchemaName,&lt;br /&gt;CASE WHEN c.max_length&gt;=0 AND basetypes.name IN (N'nchar', N'nvarchar') THEN c.max_length/2 ELSE c.max_length END AS Length,&lt;br /&gt;c.scale AS Scale,&lt;br /&gt;CONVERT(bit, c.is_identity) AS [Identity],&lt;br /&gt;CONVERT(bit, c.is_computed) AS [IsComputed],&lt;br /&gt;CONVERT(bit, ISNULL(ic.is_not_for_replication,0)) AS NotForReplication,&lt;br /&gt;CAST(ISNULL(ic.seed_value,0) AS DECIMAL(38)) AS IdentitySeed,&lt;br /&gt;CAST(ISNULL(ic.last_value,0) AS DECIMAL(38)) AS IdentityCurrent,&lt;br /&gt;ISNULL(ic.increment_value,0) AS IdentityIncrement,&lt;br /&gt;CONVERT(bit, c.is_nullable) AS AllowNulls,&lt;br /&gt;c.default_object_id AS DefaultTextID,&lt;br /&gt;ds.name AS DefaultName,&lt;br /&gt;c.default_object_id AS defaultid,&lt;br /&gt;dsc.name AS DefaultSchemaName,&lt;br /&gt;CONVERT(bit, CASE ds.parent_object_id WHEN 0 THEN 1 ELSE 0 END) AS IsBoundDefault,&lt;br /&gt;rs.name AS RuleName,&lt;br /&gt;rsc.name AS RuleSchemaName,&lt;br /&gt;CONVERT(bit, CASE WHEN fi.language_id IS NULL THEN 0 ELSE 1 END) AS FullTextIndexed,&lt;br /&gt;cc.definition AS ComputedText,&lt;br /&gt;c.is_rowguidcol AS IsRowGuidCol,&lt;br /&gt;c.collation_name AS Collation,&lt;br /&gt;fi.language_id AS FullTextLanguage,&lt;br /&gt;fisc.name AS FullTextTypeColumn,&lt;br /&gt;c.is_xml_document AS XMLDocument,&lt;br /&gt;xscs.name AS XMLCollection,&lt;br /&gt;xsc.name AS XMLCollectionSchemaName,&lt;br /&gt;t.type AS type,&lt;br /&gt;CONVERT(bit, ISNULL(cc.is_persisted, 0)) AS [IsPersisted]&lt;br /&gt;FROM sys.all_columns c INNER JOIN sys.all_objects t WITH (NOLOCK) ON c.object_id=t.object_id&lt;br /&gt;LEFT JOIN sys.schemas sc WITH (NOLOCK) ON t.schema_id=sc.schema_id&lt;br /&gt;LEFT JOIN sys.types basetypes WITH (NOLOCK) ON c.system_type_id=basetypes.system_type_id AND basetypes.system_type_id=basetypes.user_type_id&lt;br /&gt;LEFT JOIN sys.types types WITH (NOLOCK) ON c.user_type_id=types.user_type_id&lt;br /&gt;LEFT JOIN sys.schemas st WITH (NOLOCK) ON st.schema_id=types.schema_id&lt;br /&gt;LEFT JOIN sys.identity_columns ic WITH (NOLOCK) ON ic.object_id=c.object_id AND ic.column_id=c.column_id&lt;br /&gt;LEFT JOIN sys.all_objects ds WITH (NOLOCK) ON ds.object_id=c.default_object_id&lt;br /&gt;LEFT JOIN sys.all_objects rs WITH (NOLOCK) ON rs.object_id=c.rule_object_id&lt;br /&gt;LEFT JOIN sys.fulltext_index_columns fi WITH (NOLOCK) ON fi.object_id=c.object_id AND fi.column_id=c.column_id&lt;br /&gt;LEFT JOIN sys.all_columns fisc WITH (NOLOCK) ON fi.type_column_id = fisc.column_id AND fisc.object_id=c.object_id&lt;br /&gt;LEFT JOIN sys.computed_columns cc WITH (NOLOCK) ON cc.object_id=c.object_id AND cc.column_id=c.column_id&lt;br /&gt;LEFT JOIN sys.schemas dsc WITH (NOLOCK) ON dsc.schema_id=ds.schema_id&lt;br /&gt;LEFT JOIN sys.schemas rsc WITH (NOLOCK) ON rsc.schema_id=rs.schema_id&lt;br /&gt;LEFT JOIN sys.xml_schema_collections xscs WITH (NOLOCK) ON xscs.xml_collection_id=c.xml_collection_id&lt;br /&gt;LEFT JOIN sys.schemas xsc WITH (NOLOCK) ON xsc.schema_id=xscs.schema_id&lt;br /&gt;WHERE t.type IN ('U', 'FT', 'TF', 'IF', 'S', 'TT', 'V')&lt;br /&gt;ORDER BY c.object_id, c.column_id&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-758574419879744132?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/758574419879744132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/03/find-me-column.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/758574419879744132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/758574419879744132'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/03/find-me-column.html' title='Find me a column...'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-465930863025279138</id><published>2009-02-13T08:17:00.001-08:00</published><updated>2009-02-13T08:30:40.700-08:00</updated><title type='text'>Turbo Charge Your SSMS</title><content type='html'>The other day a co-worker mentioned one of his biggest pet peeves about Sql's new IDE.  Of course he likes the old IDE, but what he detested the most was the slow bloat time it took to get his SSMS loaded on the screen.  When we timed the boot time for his Enterprise Manager to load it took nearly 7 seconds.  Not bad, but then proceeded to tell me how much longer SSMS (Sql Server Management Studio) took to load.  I guessed that it could possibly be about 10 seconds (only 3 more seconds) but I was shocked to see it load in nearly 25 seconds.  it was nearly 3x less productive just loading the thing before you could connect to do anything.  I couldn't believe that it was nearly that slow on his computer, I had never timed it on my pc.  So when I returned I had to try it.  Again the load time was nearly 20 seconds on my machine (about 18 seconds to be exact).  I was not entirely pleased with my results but thankfully Google provided the answer, one quick search for "Turbo charge my SSMS" yielded the following result which brings that load time to that of Enterprise Manager about 6-7 when you are prompted with the server you want to connect to.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.sql-server-performance.com/faq/sql_server_management_studio_load_time_p1.aspx"&gt;Speed up your Sql Server Management studio &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The solution is rather simple.  First get rid of the splash screen (unless you really like it.) by adding the /nosplash parameter to your shortcut.&lt;br /&gt;&lt;br /&gt;next the real jewel,  Go into Internet Explorer's Tools&gt;Options&gt;Advance Tab and look for the Security section, uncheck the following two settings:&lt;br /&gt;&lt;br /&gt;o  Check for publisher's certificate revocation&lt;br /&gt;o  Check for server certificate revocation*&lt;br /&gt;&lt;br /&gt;once you have completed these tasks you will notice what appears to be a TurboCharged SSMS!&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-465930863025279138?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/465930863025279138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2009/02/turbo-charge-your-ssms.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/465930863025279138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/465930863025279138'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2009/02/turbo-charge-your-ssms.html' title='Turbo Charge Your SSMS'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-5289567330350497535</id><published>2008-12-03T14:05:00.000-08:00</published><updated>2008-12-03T15:35:27.820-08:00</updated><title type='text'>One sandwich short of a picnic</title><content type='html'>I had an issue at work the other day, something that seems kind of odd to me.  You see in Sql Server 2000 you could setup a view with an order by.  Of course this required a TOP 100 PERCENT to be specified at the top of the query.  You could then take that view and base new views off of it and all results would be ordered by the original view.  In Sql Server 2005 (SP1 or even SP2) everything changed, now you could no longer get the correct order by if you coupled it w/ the TOP 100 PERCENT in your view, but then again, if you do not use a the TOP keyword you can't save your view.  The solution to how to get around the issue is in the following blog article.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://executioniseverything.blogspot.com/2007/01/order-by-in-views-sql-server-2005.html"&gt;http://executioniseverything.blogspot.com/2007/01/order-by-in-views-sql-server-2005.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A proposed solution has been placed on the MSDN site so you can vote on it.  It seems the proposal is to do away with the ability to create ordered by views which technically go against the rules of rational theory....&lt;br /&gt;&lt;br /&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=249248"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=249248&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-5289567330350497535?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/5289567330350497535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2008/12/one-sandwich-short-of-picnic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5289567330350497535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5289567330350497535'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2008/12/one-sandwich-short-of-picnic.html' title='One sandwich short of a picnic'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-8654574614966223061</id><published>2008-06-06T10:55:00.000-07:00</published><updated>2008-06-06T11:02:46.668-07:00</updated><title type='text'>Watch those servers</title><content type='html'>If you're an active DBA, you'll find that your mornings are spent reviewing failed jobs and checking to see what else needs watching.  At my company we were fortunate to purchase Idera's Diagnostic Manager.  It is a good tool for reviewing your databases at a quick glance and identify any areas that need attention, ie. Space constratins, failed jobs and other critical processes. &lt;br /&gt;&lt;br /&gt;Not everyone has the ability to go out and spend thousands of dollars on a monitoring solution.  That's why I really liked the following article by David Bird over at Sql Server Central (one of my favorite Sql Sites) titled &lt;a href="http://www.sqlservercentral.com/articles/Administration/63042/"&gt;&lt;span style="font-size:100%;"&gt;SQL Overview IV - DBA's Morning Review&lt;/span&gt;&lt;/a&gt; (http://www.sqlservercentral.com/articles/Administration/63042/).  In it he describes a set of reports that you can use to review your servers quickly during the morning and spend more time fixing problems than reviewing things.  I Plan to implement many of these solutions in my own environment and see how well it stacks up to our paid solution.  I will report back and let you all know!&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-8654574614966223061?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/8654574614966223061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2008/06/watch-those-servers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8654574614966223061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/8654574614966223061'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2008/06/watch-those-servers.html' title='Watch those servers'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-1026515696301430735</id><published>2008-06-06T10:34:00.000-07:00</published><updated>2008-06-10T10:45:25.178-07:00</updated><title type='text'>Change your Recovery Model</title><content type='html'>On occassion you may be tasked with switching your recovery model for a database.  This task is very trivial and you may already know how to do this via Sql Server Enterprise Manager or even Management Studio.  But you can do this via Tsql as well (as with all things sql server related)&lt;br /&gt;&lt;br /&gt;The syntax is basically&lt;br /&gt;ALTER DATABASE Northwinds SET RECOVERY SIMPLE&lt;br /&gt;&lt;br /&gt;The recovery Models available are, Simple, BulkLogged and Full.&lt;br /&gt;&lt;br /&gt;The Simple Recovery model is as you guessed the basic recovery model which pretty much allows you to recover your database from a full backup.  The simple recovery model is ideal for test and development databases where data loss is not generally a concern.  You may wish never to use this model in a production environment unless the business is willing to loose up all data changes since the last Full or Differential backup.  In this model you do not have to maintain the Transaction log as nothing is generally written to it.&lt;br /&gt;&lt;br /&gt;The BulkLogged Recovery model will log every event except those that are Bulk transactons.  This has almost the same recoverability as a Full Recovery model.  With this recovery model you can do full, differential and log backups, you are also capable of restoring up to the minute so long as your last change was not a bulk logged operation, in which case those changes will remain lost.  You will need to schedule a regular backup for your transaction log for those operations that are not Bulk transactions.&lt;br /&gt;&lt;br /&gt;The Full Recovery model offers the highest amount of protection against data loss.  This model allows you to recover any piece of data up to the minute (prividing you have the last backup).  You can do full, differential and log backups.  You can restore any of the backups for returning to your point in time. Such as a FULL backup followed by a Differential and finally your set of Log backups until the point in time when the failure occurred.  In this recovery model you will want to schedule a regular log backup for your transaction, otherwise your database log files will grow and grow.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-1026515696301430735?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/1026515696301430735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2008/06/change-your-recovery-model.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/1026515696301430735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/1026515696301430735'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2008/06/change-your-recovery-model.html' title='Change your Recovery Model'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-554502003436817343</id><published>2008-03-07T13:08:00.000-08:00</published><updated>2008-03-07T13:15:41.836-08:00</updated><title type='text'>Defrag or don't defrag that is the question!</title><content type='html'>Back in 2005 I wrote a quick 'n' dirty post (really) about how to maintain indexes. That applied to Sql Server 2000 well enough but did not even touch what was happening with Sql Server 2005.  Instead of writing a separate article on 2005, which now come to think about it, I may want to.  I instead opted to update my older post, and it now reads more like an article.  I've included the link below so that it's quick / easier to find.  In this article I also posted up my own defrag monitor script, which should be helpful in locating defraged indexes and that way you can easily defragment only the ones that matter.&lt;br /&gt;&lt;br /&gt;Good Luck!&lt;br /&gt;&lt;a href="http://sqlthis.blogspot.com/2005/04/defrag-those-indexes-maintenance.html"&gt;http://sqlthis.blogspot.com/2005/04/defrag-those-indexes-maintenance.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-554502003436817343?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/554502003436817343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2008/03/defrag-or-dont-defrag-that-is-question.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/554502003436817343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/554502003436817343'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2008/03/defrag-or-dont-defrag-that-is-question.html' title='Defrag or don&apos;t defrag that is the question!'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-5818253210735078681</id><published>2007-12-27T10:17:00.000-08:00</published><updated>2007-12-27T10:22:16.337-08:00</updated><title type='text'>How many rows are there?</title><content type='html'>This question comes up quite a bit when DBAs are faced with space issues... the simple solution most people say is to do a quick SELECT COUNT(*) FROM &lt;tablename&gt;, but that ends up being such a costly solution and heavy I/O cost if you have a lot of tables or a lot of data.&lt;br /&gt;&lt;br /&gt;Fortunately you can obtain the number of rows without having to run such a heave I/O intensive operation.&lt;br /&gt;&lt;br /&gt;In Sql Server 2000 the command looks like this:&lt;br /&gt;Select OBJECT_NAME(ID), rows From sysindexes Where id = OBJECT_ID(&lt;tablename&gt;&lt;tablename&gt;TableName) AND indid &lt; 2&lt;br /&gt;&lt;br /&gt;While I found that the number of rows will differ slightly it is close enough to make needed judgment calls based on row count. (I.E. defragging, partitioning, archiving, etc.)&lt;br /&gt;&lt;br /&gt;In Sql Server 2005 the command looks like this: SELECT OBJECT_NAME(object_id) TableName, rows FROM sys.partitions WHERE OBJECT_NAME(object_id) = &lt;tablename&gt;&lt;tablename&gt;TableName&lt;br /&gt;&lt;br /&gt;note, be sure to replace TableName with your name in order to locate the rowcount for the individual table.  You can alternatively modify the Where clause to be by Rows &gt; x so you can find tables over a specified number of rows.  Also, if there are more than one index you may end up yielding several responses as the entries in both the partition table and the sysindexes table count the rows in ... you guessed it the index.&lt;br /&gt;&lt;/tablename&gt;&lt;/tablename&gt;&lt;/tablename&gt;&lt;/tablename&gt;&lt;/tablename&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-5818253210735078681?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/5818253210735078681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/12/how-many-rows-are-there.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5818253210735078681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5818253210735078681'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/12/how-many-rows-are-there.html' title='How many rows are there?'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-2144615199802775890</id><published>2007-12-21T12:09:00.000-08:00</published><updated>2007-12-21T12:09:01.421-08:00</updated><title type='text'>We don't care about no stinking buffers</title><content type='html'>While you work on your newest indexes / table design it is often necessary to clean up the cache on Sql Server to ensure that your changes are actually making a difference. &lt;br /&gt;&lt;br /&gt;Typically to clear the cache you'll want to run, DBCC DROPCLEANBUFFERS.&lt;br /&gt;&lt;br /&gt;If you are also executing your test via sprocs you'll want to clear that cache as well to do that just run, DBCC FREEPROCCACHE.&lt;br /&gt;&lt;br /&gt;This ensures that you are always starting from the same point at each run.  If you do not clear the cache between tests you can't be sure that your time results are accurate.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-2144615199802775890?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/2144615199802775890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/12/we-dont-care-about-no-stinking-buffers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/2144615199802775890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/2144615199802775890'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/12/we-dont-care-about-no-stinking-buffers.html' title='We don&apos;t care about no stinking buffers'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-3748466625471037926</id><published>2007-04-24T09:13:00.000-07:00</published><updated>2008-06-11T13:52:42.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='defrag'/><category scheme='http://www.blogger.com/atom/ns#' term='reindex'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Managing Table Fragmentation - Sql Server 2000</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold;"&gt;P&lt;/span&gt;&lt;/span&gt;erformance.... it's an intangible and it seems that no matter how fast and how optimized you set your system up, it seems that there is always new information telling you what you should be doing as well.  It seems that there really is no end on to what you can do with software, and when you think you've reached the end of that intangible, then there are all the sorts of things you can do in the hardware world to further push the performance limits.  Don't get me wrong, I dig being able to find these tidbits... these jewels of information.  It just seems sometimes that you've completed implementing something when now new information, could have helped you out before you started planning.  So, What do you do when you continue to manage more and more Sql Servers in your environment?  I started out with 8 unhealthy servers.  I kept on them and have been able to kick the developers square in the butt!*  Part of the butt kicking allowed me to set new rules in place.  I've managed to get my developers to work their ideas on their own TEST servers, well server is a very liberal term, we have Sql Server Dev edition running on a separate desktop system under their desk, and does allow them to perform similar performing queries against similar data, if they require more data, I simply restore a copy of the db to their test environment.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;*disclaimer: no actual butts were kicked in the actual story, the emphasis on kicking is written to enhance the fictional portion of the story.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;/*&lt;br /&gt;Object: Stored Procedure dbo.sp_dba_DBREINDEX version 1&lt;br /&gt;Script Author: Francisco Tapia,&lt;br /&gt;Purpose: REINDEX all indexes in a given table or database.&lt;br /&gt;&lt;br /&gt;Based off the work from Robert Davis &lt;a href="http://www.databasejournal.com/img/sp_dba_DefragIndexes.sql"&gt;http://www.databasejournal.com/img/sp_dba_DefragIndexes.sql&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;USE MASTER&lt;br /&gt;if exists (select * from sysobjects where id =&lt;br /&gt;object_id('dbo.sp_dba_DBREINDEX') and sysstat &amp;amp; 0xf = 4)&lt;br /&gt;drop procedure dbo.sp_dba_DBREINDEX&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;CREATE PROCEDURE sp_dba_DBREINDEX&lt;br /&gt;   (&lt;br /&gt;   @Table sysname = Null, -- Table in which to defrag the indexes&lt;br /&gt;   @ShowDetail bit = 0&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;AS&lt;br /&gt;If (Not Exists (Select 1 From sysobjects with(nolock) where id = object_id(@Table) And xtype = 'U') And @Table Is Not Null) Or @Table = '?'&lt;br /&gt;    Begin&lt;br /&gt;   Print '''' + @Table + ''' is not a valid table object in this database.' + char(10)&lt;br /&gt;   Print 'Proper syntax:'&lt;br /&gt;   Print 'Exec dbo.sp_dba_DBREINDEX ' + char(10) + space(5) + '@Table = { [table_name] | ''?'' }' + char(10)&lt;br /&gt;   Print 'table_name'&lt;br /&gt;   Print space(5) + 'Is the table for which to defragment an index. Table names must conform to the rules for identifiers.'&lt;br /&gt;   Print space(5) + 'Table_name is optional, procedure will run for all tables in database if parameter not specified.'&lt;br /&gt;   Print '''?'''&lt;br /&gt;   Print space(5) + 'This help message will be displayed.'&lt;br /&gt;    End&lt;br /&gt;Else&lt;br /&gt;    Begin&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;       If @ShowDetail = 0&lt;br /&gt;           BEGIN&lt;br /&gt;                 IF @Table IS NULL&lt;br /&gt;                       BEGIN&lt;br /&gt;                        EXEC sp_MSforeachtable  'DBCC DBREINDEX (''?'', '''', 0) WITH NO_INFOMSGS'&lt;br /&gt;                       END&lt;br /&gt;                   ELSE&lt;br /&gt;                       BEGIN&lt;br /&gt;                        DBCC DBREINDEX (@Table, '', 0) WITH NO_INFOMSGS&lt;br /&gt;                       END&lt;br /&gt;           END&lt;br /&gt;       Else&lt;br /&gt;           BEGIN&lt;br /&gt;                 IF @Table IS NULL&lt;br /&gt;                       BEGIN&lt;br /&gt;                           PRINT 'Initiating DBReIndex for All Tables'&lt;br /&gt;                           EXEC sp_MSforeachtable  'DBCC DBREINDEX (''?'', '''', 0) '&lt;br /&gt;                       END&lt;br /&gt;                   ELSE&lt;br /&gt;                       BEGIN&lt;br /&gt;                         PRINT 'Initiating DBReIndex for ' +  @Table&lt;br /&gt;                        DBCC DBREINDEX (@Table, '', 0)&lt;br /&gt;                       END&lt;br /&gt;           END&lt;br /&gt;     &lt;br /&gt;    END&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-3748466625471037926?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/3748466625471037926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/04/managing-table-fragmentation-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/3748466625471037926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/3748466625471037926'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/04/managing-table-fragmentation-sql-server.html' title='Managing Table Fragmentation - Sql Server 2000'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-6785137458900317066</id><published>2007-02-23T08:49:00.000-08:00</published><updated>2007-04-24T09:29:59.731-07:00</updated><title type='text'>How should I store an IP address in SQL Server?</title><content type='html'>I had the mis-fortune of working with a database where the developers decided to store the IP address as an integer.  I believe they did this in order to help improve the performance of their database, or storage, or possibly both.  The front end dealt with all the conversion of IP to INT and vice versa.  When I needed to make a little bit of enhancements because the front end was just literally timing out at the amount of data that it needed.   I decided to change how I retrieved some of my reports, and thus run into the following link, in where the author shares two functions to aid in the conversion of IP to INT and INT to IP.  The article is quite good and even has a few numbers on what the performance is on each style of how one might choose to store the IP address information.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://sqlserver2000.databases.aspfaq.com/how-should-i-store-an-ip-address-in-sql-server.html"&gt;How should I store an IP address in SQL Server?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I know my new years resolution was going to be broken the moment I published the first article of the year :D HA!.  I do have an article on working with indexes and hopefully it should be quite good.  Stay tuned!&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-6785137458900317066?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/6785137458900317066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/02/how-should-i-store-ip-address-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6785137458900317066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/6785137458900317066'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/02/how-should-i-store-ip-address-in-sql.html' title='How should I store an IP address in SQL Server?'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-5965026515734827384</id><published>2007-01-02T15:14:00.001-08:00</published><updated>2007-01-02T15:15:41.051-08:00</updated><title type='text'>Calculating Days of the Week and Accounting Months 5-4-4</title><content type='html'>Ever needed a quick Date formula? In my world I do not need such funky date formulas all the time, only during the occasional Report week of the year. With that said though, I know others run into this need frequently. I found this while perusing one of my favorite sites, enjoy as there is very good detail and sample code on how to achieve just what you need.&lt;br /&gt;&lt;br /&gt;(Link to Database Journal)&lt;br /&gt;&lt;a href="http://www.databasejournal.com/features/mssql/article.php/3650031"&gt;Calculating Days of the Week and Accounting Months 5-4-4&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-5965026515734827384?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/5965026515734827384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/01/calculating-days-of-week-and-accounting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5965026515734827384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/5965026515734827384'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/01/calculating-days-of-week-and-accounting.html' title='Calculating Days of the Week and Accounting Months 5-4-4'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-116777691621927174</id><published>2007-01-02T14:28:00.000-08:00</published><updated>2007-01-02T15:28:51.346-08:00</updated><title type='text'>Happy New Year!</title><content type='html'>If this is your first time visiting my blog, welcome!   For those who are returning, welcome back!  SqlThis is aimed at being a quick "Reference" site.   In general I do not write a whole lot of fluff about the topics at hand, just the absolute necessary to help understand the script/example and that's it, in some ways SqlThis is a repository of Tsql Links, but often times when I've run into unique solutions or solutions that I want to revisit, I will post them here too, so it's sort of a mesh of links and articles.   I also get tips and tricks from fellow DBAs in the community that will provide me w/ Articles or Links.   I hope this year to get a new tip/trick at least once a month.  I've been posting to this blog for almost 2 years now.  Next month will actually be my 2 year anniversary.  And while other sites give away Ipods and Laptops (google microsoft laptop giveaway). I will be providing something much more coveted...&lt;br /&gt;&lt;br /&gt;... more tsql code :)&lt;br /&gt;&lt;a href="http://www.databasejournal.com/features/mssql/article.php/3650031"&gt;&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-116777691621927174?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/116777691621927174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2007/01/calculating-days-of-week-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116777691621927174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116777691621927174'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2007/01/calculating-days-of-week-and.html' title='Happy New Year!'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-116371340795450034</id><published>2006-11-16T13:43:00.000-08:00</published><updated>2006-11-16T13:43:28.196-08:00</updated><title type='text'>10 mistakes to avoid</title><content type='html'>A very good read for even the most veteran of developers, the following top 10 mistakes list is not necessarily the top 10 mistakes of all time, but it is a good guideline...&lt;br /&gt;&lt;a href="http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1229788,00.html?track=NL-417&amp;amp;ad=570713USCA&amp;amp;asrc=EM_NLT_745644&amp;amp;uid=734052"&gt;SQL Server query design: 10 mistakes to avoid&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-116371340795450034?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/116371340795450034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/11/10-mistakes-to-avoid.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116371340795450034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116371340795450034'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/11/10-mistakes-to-avoid.html' title='10 mistakes to avoid'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-116365127811176978</id><published>2006-11-15T20:27:00.000-08:00</published><updated>2006-11-15T20:27:58.306-08:00</updated><title type='text'>Vadivel's blog: Avoid using sp_rename ...</title><content type='html'>&lt;a href="http://vadivel.blogspot.com/2004/08/avoid-using-sprename.html"&gt;Vadivel's blog: Avoid using sp_rename ...&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-116365127811176978?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/116365127811176978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/11/vadivels-blog-avoid-using-sprename.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116365127811176978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116365127811176978'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/11/vadivels-blog-avoid-using-sprename.html' title='Vadivel&apos;s blog: Avoid using sp_rename ...'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-116346414528793657</id><published>2006-11-13T16:29:00.000-08:00</published><updated>2007-03-21T14:40:55.044-07:00</updated><title type='text'>Finding your group(file)</title><content type='html'>Managing tables into filegroups can be a very daunting task when you start to look at huge database systems.  The following script always helps me to locate what table is in which filegroup.&lt;br /&gt;&lt;br /&gt;It helps to keep things neat and tidy.&lt;br /&gt;&lt;br /&gt;SELECT o.name, s.groupname, f.name&lt;br /&gt;FROM dbo.sysfilegroups s&lt;br /&gt;INNER JOIN dbo.sysindexes i&lt;br /&gt;ON i.groupid = s.groupid&lt;br /&gt;INNER JOIN dbo.sysfiles f&lt;br /&gt;ON f.groupid = s.groupid&lt;br /&gt;INNER JOIN dbo.sysobjects o&lt;br /&gt;ON i.id = object_id(o.name)&lt;br /&gt;AND i.indid in (0, 1)&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-116346414528793657?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/116346414528793657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/11/finding-your-groupfile.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116346414528793657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116346414528793657'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/11/finding-your-groupfile.html' title='Finding your group(file)'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-116199432616079134</id><published>2006-10-27T17:12:00.000-07:00</published><updated>2006-11-02T15:44:04.000-08:00</updated><title type='text'>How to spot a big table</title><content type='html'>There are plenty of tools out in the wonderful world of the web to provide you with this very detail of information.  Do you need it?  Well Gui's can be fun and down right useful when in the right environment.  In my world I use software to help keep track of my LIVE/Production systems but, what about those other systems that are not really live, but are development and test.  Sometimes you start to run out of room, and you wonder why... sometimes you want a quick count of the tables that either consume the most space in terms of disk, or rows...  How can you do it quickly?&lt;br /&gt;&lt;br /&gt;The following snippet is not groundbreaking, but it does provide a valuable service.  More importantly it answer the questions of... which table is bigger... which tables are unused. etc, etc.  You can even take this to the next level and keep track of which tables grow the most by surveying all your databases.  And if you really like GUIs you can graph a trend on which tables grow the most.. stuff that is already available by vendors for thousands a month.. not groundbreaking like I said earlier but certainly useful and a good exercise to practice.  Once you have it you can save a ton of Money on the GUIs out there...&lt;br /&gt;&lt;br /&gt;Below I took advantage of using the undocumented stored procedure sp_msforeachtable, and the global variable '?'.  Essentially for each table in the database run this sproc (stored procedure).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; --By: Francisco&lt;br /&gt; --Date: 10/27/2006&lt;br /&gt; --Purpose: Find Out wich Tables Yield the most space.&lt;br /&gt; IF EXISTS (select * from TEMPDB.dbo.sysobjects WITH(NOLOCK) where id = object_id(N'TEMPDB.dbo.#SpaceUsed')) BEGIN&lt;br /&gt;  DROP TABLE #SpaceUsed&lt;br /&gt; END&lt;br /&gt;  CREATE TABLE #SpaceUsed (TableName VARCHAR(255),Rows INT, Reserved Varchar(255), Data VarChar(255), Index_Size VarChar(255), Unused VarChar(255))&lt;br /&gt;  INSERT INTO #SpaceUsed (TableName, Rows, Reserved, Data, Index_Size, UnUsed)&lt;br /&gt;   EXEC sp_msforeachtable 'EXEC sp_spaceused ''?'''&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;  SELECT TableName, Rows, Reserved, Data, Index_Size, Unused FROM #SpaceUsed&lt;br /&gt;  ORDER BY CAST(REPLACE (DATA, 'KB', '') AS INT) DESC&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-116199432616079134?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/116199432616079134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/10/how-to-spot-big-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116199432616079134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/116199432616079134'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/10/how-to-spot-big-table.html' title='How to spot a big table'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-115697126235388940</id><published>2006-08-30T13:54:00.000-07:00</published><updated>2006-11-02T15:43:31.680-08:00</updated><title type='text'>How Safe are your passwords?</title><content type='html'>Let's Face it, when working with Sql Server it does pose many security threats when unsecured, even while secure you have an ultimate login to try and crack. That of course is the "SA".  Unless you set up your Sql Server to NT Authentication only, but sometimes you don't have much of a choice.  The following article has some interesting methods to try and upgrade your passwords to be MORE secure.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.sqlservercentral.com/columnists/jgama/sqlserverpasswordauditing_printversion.asp"&gt;Find SA Password (Brute Force) Find Passwords (Dictionary) Analysis of Password Security Password Generator ASCII Table&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-115697126235388940?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/115697126235388940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/08/how-safe-are-your-passwords.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/115697126235388940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/115697126235388940'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/08/how-safe-are-your-passwords.html' title='How Safe are your passwords?'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-115688466765371188</id><published>2006-08-29T13:51:00.000-07:00</published><updated>2006-08-29T13:51:07.663-07:00</updated><title type='text'>Going against the Trend</title><content type='html'>Sql Server 2000 Reporting Services is an awesome reporting tool, but what they forgot to pack in is something simple like a 2nd Y axis (wich I still haven't figured out how to do), and a stinking Trendline.  I mean, c'mon, even EXCEL does trendlines! So my quickie solution is the following script, All you have to do is populate the @TrendTable and you're on your way!!!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DECLARE @TrendTable TABLE (PID INT IDENTITY (1,1),&lt;br /&gt;   XColumn smalldatetime,&lt;br /&gt;   YColumn1 REAL,&lt;br /&gt;   YColumn2 INT,&lt;br /&gt;   Trend REAL)&lt;br /&gt;&lt;br /&gt;---------&lt;br /&gt;/*&lt;br /&gt;  At this point populate the @TrendTable with your data, the Xcolumn is of course plotted data on the x axis,  On this example I've put in a Y column and a 2nd Y column for your charting needs, YColumn1 is the column that will be trended.&lt;br /&gt;*/&lt;br /&gt;--------&lt;br /&gt;&lt;br /&gt;DECLARE @n REAL&lt;br /&gt;DECLARE @sumX REAL&lt;br /&gt;DECLARE @sumY REAL&lt;br /&gt;DECLARE @sumXY REAL&lt;br /&gt;DECLARE @sumX2 REAL&lt;br /&gt;DECLARE @sumY2 REAL&lt;br /&gt;DECLARE @sumX_2 REAL&lt;br /&gt;DECLARE @sumY_2 REAL&lt;br /&gt;&lt;br /&gt;DECLARE @m REAL&lt;br /&gt;DECLARE @b REAL&lt;br /&gt;DECLARE @r REAL&lt;br /&gt;&lt;br /&gt;SELECT @n = COUNT(*),  @sumX=SUM(PID),&lt;br /&gt;   @sumY=SUM(YColumn1),&lt;br /&gt;   @sumXY=SUM(PID*YColumn1),&lt;br /&gt;         @sumX2=SUM(POWER(PID,2)),&lt;br /&gt;         @sumY2=SUM(POWER(YColumn1,2)) &lt;br /&gt;  FROM @TrendTable&lt;br /&gt;&lt;br /&gt;SELECT @sumX_2 = POWER(@sumX,2), @sumY_2 = POWER(@sumY,2)&lt;br /&gt;&lt;br /&gt;--slope&lt;br /&gt;SELECT @m = (@n*@sumXY-@sumX*@sumY)/(@n*@sumX2-@sumX_2) &lt;br /&gt;--y intercept&lt;br /&gt;SELECT @b = (@sumY-@m*@sumX)/@n&lt;br /&gt;--r&lt;br /&gt;SELECT @r = (@n*@sumXY-@sumX*@sumY)/SQRT((@n*@sumX2-@sumX_2)*(@n*@sumY2-@sumY_2))&lt;br /&gt;&lt;br /&gt;UPDATE @TrendTable&lt;br /&gt; SET Trend = @m * PID + @b&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT * FROM @TrendTable&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-115688466765371188?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/115688466765371188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/08/going-against-trend.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/115688466765371188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/115688466765371188'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/08/going-against-trend.html' title='Going against the Trend'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-114926451676718509</id><published>2006-06-02T09:08:00.000-07:00</published><updated>2006-08-29T11:44:23.543-07:00</updated><title type='text'>The myths and legends of the holy land of the database | The Register</title><content type='html'>Don't end up in urban legend hell!,   The following articles really do bring to light the urban legends of database engines.   Read along and get de-mystified.  These all List to the Register's site.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.regdeveloper.co.uk/2006/05/26/myth_legends_database/"&gt;The myths and legends of the holy land of the database&lt;br /&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.regdeveloper.co.uk/2006/08/15/beer_diapers/"&gt;The parable of the beer and diapers&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.regdeveloper.co.uk/2006/08/01/apache_undead/"&gt;Tackling Apache zombies&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.regdeveloper.co.uk/2006/06/13/myth_legend_part2/"&gt;Microsoft was caught stealing secrets from Borland&lt;/a&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-114926451676718509?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/114926451676718509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/06/myths-and-legends-of-holy-land-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114926451676718509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114926451676718509'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/06/myths-and-legends-of-holy-land-of.html' title='The myths and legends of the holy land of the database | The Register'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-114850751073721875</id><published>2006-05-24T14:51:00.000-07:00</published><updated>2006-08-29T11:51:21.040-07:00</updated><title type='text'>Intellisense for SQL Server</title><content type='html'>I dunno if you've heard of Red-Gate.  but so far they've created some very top notch software to help out with both webservices and Sql Server.  I've personally tried both their Sql Data Compare and Sql Compare wich helps match both schema and data accross diffrent databases and servers.  This has many benefits as you can easily work in a test environment and have the ability to work with some close to live data.  and after you've completed your work you can propagate the changes to your test environment with out a hassle not to mention you can minimize the time it takes to roll changes to your live environment.&lt;br /&gt;&lt;br /&gt;But really what I wanted to talk about today was Sql Prompt.  It's Intellisense for Sql Server.  That's it.  Well that's not just it.  It loads a systray app in your system and hooks directly to your Query Analyzer.  Off the cuff I found it to be extreamly effective.  I started to write my Select statement and it was able to appropriately give me back names of tables to complete and even name of stored procedures that were available to me.  One of the options that I liked the best, was the join feature, in which it helps you complete a join statement super quick by giving you a small list of all available joinable fields. you can type at your desire or pick from the list... ultra cool.&lt;br /&gt;Well now for the hook and sinker... It's Free :).  Unlike the other products that help make them money.  Probably the most useful app they have on their site is completely free.  Of course after using this little proggy you're gonna probably want to return and see what other cool apps they have.  To get your copy click on the following link:&lt;br /&gt;&lt;a href="http://www.red-gate.com/products/SQL_Prompt/index.htm?gclid=CM2LmejFkYUCFRWaIgodJnbtIQ"&gt;SQL Intellisense, Intellisense for SQL Server - SQL Prompt&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After using it for a few minutes I was able to get the hang of it.  Extra niceties are things such as auto-completion for your parameter names for a sproc (stored procedure).  nice touch guys!&lt;br /&gt;&lt;br /&gt;btw, nope I do not work for Red-Gate, I just happend to have really liked a few of their Software Titles. :)&lt;br /&gt;&lt;br /&gt;---*update*---&lt;br /&gt;SQLprompt will only be free until Sept 1st.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-114850751073721875?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/114850751073721875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/05/intellisense-for-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114850751073721875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114850751073721875'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/05/intellisense-for-sql-server.html' title='Intellisense for SQL Server'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-114650962306303920</id><published>2006-05-01T11:53:00.000-07:00</published><updated>2006-05-01T13:37:04.046-07:00</updated><title type='text'>Find and Replace</title><content type='html'>I cruised the net last week looking for a simle "Find and Replace" script.  sorta like a split for VB only that I need the replace to occur at every &lt;span style="font-weight: bold;"&gt;n&lt;/span&gt;th character.  Not finding what I wanted I ended up writing my own, the idea was that I'd start at the lenght that my string needs to be then crawl backwards until I find a space (or breakpoint) then replace it with my Replace string.  There may be a better way.. if you have one feel free to comment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;CREATE FUNCTION &lt;span style="color: rgb(0, 0, 0);"&gt;dbo.SplitAndReplace&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; (&lt;span style="color: rgb(0, 0, 0);"&gt;@String &lt;/span&gt;AS VARCHAR(8000), &lt;span style="color: rgb(0, 0, 0);"&gt;@SplitString&lt;/span&gt; CHAR(1),&lt;span style="color: rgb(0, 0, 0);"&gt; @ReplaceString&lt;/span&gt; VARCHAR(255), &lt;span style="color: rgb(0, 0, 0);"&gt;@BreakInterval&lt;/span&gt; AS INT&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt; ) &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;RETURNS VARCHAR(8000)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;AS &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;/*&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;SET @String = 'This is as very simple text that needs to be broken down for processing in the external system, the process should auto insert an exclamation-pound sign in lew of a space that is at 60 characters'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;SET @BreakInterval = 60&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;SET @ReplaceString = '!#'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;SET @SplitString = ' '&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;DECLARE @X AS INT&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;DECLARE @Y AS INT&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;SELECT @X = 0, @Y = 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;WHILE (&lt;span style="color: rgb(255, 153, 255);"&gt;LEN&lt;/span&gt;(&lt;span style="color: rgb(255, 153, 255);"&gt;RTRIM&lt;/span&gt;(&lt;span style="color: rgb(255, 153, 255);"&gt;LTRIM&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 0);"&gt;@String&lt;/span&gt;))) - &lt;span style="color: rgb(0, 0, 0);"&gt;@Y)&lt;/span&gt; / &lt;span style="color: rgb(0, 0, 0);"&gt;@BreakInterval&lt;/span&gt; &gt; 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    WHILE @SplitString &lt;&gt; &lt;span style="color: rgb(255, 153, 255);"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 0);"&gt;@String&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 0);"&gt;@Y&lt;/span&gt; + (&lt;span style="color: rgb(0, 0, 0);"&gt;@BreakInterval&lt;/span&gt; - &lt;span style="color: rgb(0, 0, 0);"&gt;@X&lt;/span&gt;), 1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;       BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        SET &lt;span style="color: rgb(0, 0, 0);"&gt;@X&lt;/span&gt; = &lt;span style="color: rgb(0, 0, 0);"&gt;@X&lt;/span&gt; + 1 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;         END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        SET &lt;span style="color: rgb(0, 0, 0);"&gt;@String&lt;/span&gt; = &lt;span style="color: rgb(255, 153, 255);"&gt;STUFF&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 0);"&gt;@String&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 0);"&gt;@Y &lt;/span&gt;+ (&lt;span style="color: rgb(0, 0, 0);"&gt;@BreakInterval&lt;/span&gt; - (&lt;span style="color: rgb(0, 0, 0);"&gt;@X&lt;/span&gt; ))  , 1, &lt;span style="color: rgb(0, 0, 0);"&gt;@ReplaceString&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;            SET &lt;span style="color: rgb(0, 0, 0);"&gt;@Y&lt;/span&gt; = &lt;span style="color: rgb(0, 0, 0);"&gt;@Y&lt;/span&gt; + (&lt;span style="color: rgb(0, 0, 0);"&gt;@BreakInterval &lt;/span&gt;- &lt;span style="color: rgb(0, 0, 0);"&gt;@X&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;   END&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;RETURN &lt;span style="color: rgb(0, 0, 0);"&gt;@String&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;END&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-114650962306303920?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/114650962306303920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/05/find-and-replace.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114650962306303920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/114650962306303920'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/05/find-and-replace.html' title='Find and Replace'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-113771664583580851</id><published>2006-01-19T16:24:00.000-08:00</published><updated>2006-01-19T16:24:05.876-08:00</updated><title type='text'>How to Set Up a SQL Server Stress Test Environment in 8 Steps: Lessons From the Field</title><content type='html'>Sometimes you just have to know &lt;a href="http://www.sql-server-performance.com/gv_stress_test_lessons_3.asp"&gt;How to Set Up a SQL Server Stress Test&lt;/a&gt;.  &lt;a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;231619"&gt;SQLIOstress &lt;/a&gt;is a bit diffrent than &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=9A8B005B-84E4-4F24-8D65-CB53442D9E19&amp;amp;displaylang=en"&gt;SQLIO &lt;/a&gt;wich actually gives you back only IO resutls, whereas SQLIOstress will yeild results in the manner that SQL maintains files.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-113771664583580851?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/113771664583580851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/01/how-to-set-up-sql-server-stress-test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/113771664583580851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/113771664583580851'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/01/how-to-set-up-sql-server-stress-test.html' title='How to Set Up a SQL Server Stress Test Environment in 8 Steps: Lessons From the Field'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-113760412748705481</id><published>2006-01-18T09:08:00.000-08:00</published><updated>2011-11-11T10:05:43.528-08:00</updated><title type='text'>Migrating Logins from One SQL Server to Another</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-m8fjVMa8LmU/Tr0_vhCbnPI/AAAAAAAAA0U/rFijrJRQGgo/s1600/social-networking-package.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-m8fjVMa8LmU/Tr0_vhCbnPI/AAAAAAAAA0U/rFijrJRQGgo/s200/social-networking-package.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;UPDATED! 11/11/11&lt;/b&gt;&lt;br /&gt;Every DBA runs into the following topic from time to time in their career, How Do you go about &lt;a href="http://www.databasejournal.com/features/mssql/article.php/2228611"&gt;Migrating Logins from One SQL Server to Another&lt;/a&gt;? From time to time you'll want to move actual sql login users to another server be it an upgrade, or if you have a good development - test - production cycle, you might be more used to this.  Or maybe just maybe you're starting this cycle out, initially just run the Sproc provided by Microsoft called sp_help_revlogin There are two methods posted on the Microsoft site:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Method 1 is for Sql Server 2000 to 2000&amp;nbsp; &lt;a href="http://support.microsoft.com/kb/246133" target="_blank"&gt;KB 246133&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Method 2 is for Sql Server 2000 to 2005&amp;nbsp; &lt;a href="http://support.microsoft.com/kb/246133" target="_blank"&gt;KB 246133&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Method 3 is for Sql Server 2005/2008 &lt;a href="http://support.microsoft.com/kb/918992" target="_blank"&gt;KB 918992&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;You will need to use Query Analyzer for Sql Server 2000 or Management Studio for 2005/2008&amp;nbsp;&lt;/ol&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-P7chQA5AtMI/Tr1isSdpXcI/AAAAAAAAA0c/tUC5pxSfnIo/s1600/11-11-2011+9-58-25+AM.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-P7chQA5AtMI/Tr1isSdpXcI/AAAAAAAAA0c/tUC5pxSfnIo/s1600/11-11-2011+9-58-25+AM.png" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Copy the results and paste them to the new query window&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;ol&gt;&lt;li&gt;Go to the source server and open up a new query window and be sure you are pointing to your source database&lt;/li&gt;&lt;li&gt;check that your Management studio is set to return your results as text&lt;/li&gt;&lt;li&gt;you can do this by right clicking within the query window then choosing results to text&lt;/li&gt;&lt;li&gt;Paste your script into the query window and execute the script by clicking the run button or F5.&lt;/li&gt;&lt;li&gt; &lt;/li&gt;&lt;li&gt;copy the results and open up a new Management Studio Query window that is connected to your Destination Server and be sure you've selected the destination database.&lt;/li&gt;&lt;li&gt;Paste the result text, and edit out any users you don't want to re-create&lt;/li&gt;&lt;/ol&gt;Now that you've migrated the users you can simply backup your database as you normally do and restore it to the new environment.&lt;br /&gt;&lt;br /&gt;These steps are only necessary if you need to &lt;b&gt;migrate&lt;/b&gt; users from one physical server to another.  You won't need to run these steps if you are on the same server and you've simply created your test database in the same environment, the users already exist in the database from your backup and restore, and they already exist in the server system database as well.  This is only necessary when you have two completely separate servers/instances.&lt;br /&gt;&lt;br /&gt;Good luck and happy TSQLing&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-113760412748705481?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/113760412748705481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2006/01/migrating-logins-from-one-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/113760412748705481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/113760412748705481'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2006/01/migrating-logins-from-one-sql-server.html' title='Migrating Logins from One SQL Server to Another'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-m8fjVMa8LmU/Tr0_vhCbnPI/AAAAAAAAA0U/rFijrJRQGgo/s72-c/social-networking-package.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-112567433697584570</id><published>2005-09-02T08:18:00.000-07:00</published><updated>2005-09-02T08:18:56.993-07:00</updated><title type='text'>Access/SQL:How to satisfy the underlying record</title><content type='html'>Even tho this is a Sql Blog, the following actually is related...&lt;br /&gt;&lt;br /&gt;Many developers will often use Microsoft Access as a viable Front End to Sql Server instead of using VB or even VB dotNet.  This is often a quick way to leverage rapid development.  However if you've ever used Access you'll quickly find that it's not the friendly little IDE that it claims to be.  When you attempt to leverage it's power as bound data application, you'll often find yourself wrestling within the clutches of it's Before Update, Current and After Update Events.  I can say you haven't known how to really hate, until you've battled it out with these events.  In a simple application it all works fine, in a typical Access MDB format, binding data to forms is common and relatively easy and painless.  Try it with an ADP (Access Data Project).  &lt;br /&gt;&lt;br /&gt;The Before Update event can easily be avoided and replaced with a database trigger.  Trigger's to Sql Server are what Before Update events are to Access.  If your changes can be made server side, it's often the best plan of attack.  But what if in your trigger you update other tables?  if you do you'll most certainly be faced with the dreaded "The data was added to the database but the data won't be displayed in the form because it doesn't satisfy the criteria in the underlying record source." followed by quickly seeing the data you just keyed into your Access Form disappear.  Seems like it'd be easier to wrestle w/ the Before Update and Current Events.  The practicallity of doing a trigger is that you don't need to make another round trip to the database.  For Access the above error occurs because Access uses Sql's @@Identity to synchronize with the Front end. It's best outlined in KB article:&lt;a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;275090"&gt;KB275090&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;My workaround?  I created a temp table and filled it with the target table's PKID&lt;br /&gt;&lt;br /&gt;CREATE TABLE #reIdentify (JUNKID int IDENTITY (1, 1) NOT NULL)&lt;br /&gt;		SET IDENTITY_INSERT #reIdentify ON &lt;br /&gt;			INSERT INTO #reIdentify(JunkID)&lt;br /&gt;				SELECT MyTablePKID FROM INSERTED&lt;br /&gt;		SET IDENTITY_INSERT #reIdentify OFF &lt;br /&gt;&lt;br /&gt;Now I can have my Before_Update event occuring at the server level saving me client processing and battling yet another Access Bound Event.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-112567433697584570?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/112567433697584570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/09/accesssqlhow-to-satisfy-underlying.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112567433697584570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112567433697584570'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/09/accesssqlhow-to-satisfy-underlying.html' title='Access/SQL:How to satisfy the underlying record'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-112304966177956091</id><published>2005-08-02T23:14:00.000-07:00</published><updated>2005-08-02T23:14:21.796-07:00</updated><title type='text'>How to setup xp_cmdshell</title><content type='html'>Setting up xp_cmdshell securely can be a challenge.  Generally only sysadmins can execute the xp_cmdshell.  It is actually a very huge security hole if you choose to program your website w/ the sa account as you lay your database in the path for SQL injections.  This can be typical if the originating server or application is one that you are taking over.&lt;br /&gt;&lt;br /&gt;However, there will be instances where you will need to grant mere mortal users access to the xp_cmdshell, this can be done via the sql agent proxy, this gives you the ability to assing a generic nt user the ability to execute a limited range of file object manipulation.  The following Microsoft article goes into the details for setting up your SQL Server agent proxy.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;890775"&gt;How to configure a SQL Server Agent proxy account to enable non-system administrators to execute the xp_cmdshell extended stored procedure in SQL Server 2000&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-112304966177956091?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/112304966177956091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/08/how-to-setup-xpcmdshell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112304966177956091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112304966177956091'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/08/how-to-setup-xpcmdshell.html' title='How to setup xp_cmdshell'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-112267688352552274</id><published>2005-07-29T15:41:00.000-07:00</published><updated>2005-07-29T15:41:23.560-07:00</updated><title type='text'>Table Compare</title><content type='html'>When you need to quickly find out diffrences of data/fields between two tables, there is nothing easier than this script:&lt;br /&gt;&lt;a href="http://www.databasejournal.com/scripts/article.php/1579951"&gt;Table Compare&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-112267688352552274?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/112267688352552274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/07/table-compare.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112267688352552274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112267688352552274'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/07/table-compare.html' title='Table Compare'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-112187985507826785</id><published>2005-07-20T10:17:00.000-07:00</published><updated>2005-07-20T10:17:35.083-07:00</updated><title type='text'>may the CODE be with you....</title><content type='html'>Here is an excellent collection of code snippets and useful libraries for just about any task you're likely to encounter.  I've included the link below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://vyaskn.tripod.com/code.htm"&gt;My code library (SQL Server T-SQL code samples, snippets, examples, tips, tricks, stored procedures, user defined functions, VB programs): Narayana Vyas Kondreddi's home page&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-112187985507826785?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/112187985507826785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/07/may-code-be-with-you.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112187985507826785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/112187985507826785'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/07/may-code-be-with-you.html' title='may the CODE be with you....'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111784000198616673</id><published>2005-06-03T16:06:00.000-07:00</published><updated>2005-06-03T16:06:42.016-07:00</updated><title type='text'>What's up doc?</title><content type='html'>The following SELECT statement displays how long a sql server instance was&lt;br /&gt;up for; SQL Server refreshes the tempdb every time it restarts.  To&lt;br /&gt;determine how long a SQL Server instance has been running, we use the&lt;br /&gt;created date of the tempdb.&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;CAST(DATEDIFF(ss,crdate,GETDATE())/60/60/24 AS VARCHAR(4))  + 'd '&lt;br /&gt;+ CAST(DATEDIFF(ss,crdate,GETDATE())/60/60 % 24 AS VARCHAR(4))  + 'hr '&lt;br /&gt;+ CAST(DATEDIFF(ss,crdate,GETDATE())/60 % 60 AS VARCHAR(4))  + 'min '&lt;br /&gt;+ CAST(DATEDIFF(ss,crdate,GETDATE()) % 60 AS VARCHAR(4))  + 'sec' AS&lt;br /&gt;SQL_Server_HAS_BEEN_UP_FOR&lt;br /&gt;FROM MASTER.dbo.SYSDATABASES&lt;br /&gt;WHERE name = 'TempDB';&lt;br /&gt;&lt;br /&gt;-By Billy Pang&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111784000198616673?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111784000198616673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/06/whats-up-doc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111784000198616673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111784000198616673'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/06/whats-up-doc.html' title='What&apos;s up doc?'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111758072654340531</id><published>2005-05-31T16:05:00.000-07:00</published><updated>2005-05-31T16:05:26.593-07:00</updated><title type='text'>Searching Stored Procedures Source Code</title><content type='html'>I found this article while searching for some "text" in my own stored procedures, (the article link is available at the bottom.)&lt;br /&gt;---------------&lt;br /&gt;October 6, 2000&lt;br /&gt;Searching Stored Procedures Source Code&lt;br /&gt;By Alan Enderby&lt;br /&gt;&lt;br /&gt;Want to find that stored procedure that deletes those stock items.&lt;br /&gt;&lt;br /&gt;This simple (&amp; crude) script will scan syscomments for a given string&lt;br /&gt;and display the stored procedure and the section of code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if exists (select * from sysobjects where id =&lt;br /&gt;object_id('dbo.sp_findsp') and sysstat &amp; 0xf = 4)&lt;br /&gt;drop procedure dbo.sp_findsp&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;create proc sp_findsp @s varchar(255) as&lt;br /&gt;DECLARE @msg varchar(255) ,@ul varchar(255)&lt;br /&gt;select @s='%' + @s + '%'&lt;br /&gt;select 'SP Name'=upper(o.name), Seq=colid ,'SP&lt;br /&gt;Line'=substring(text,patindex(@s,text)-5, 30)&lt;br /&gt;from syscomments c , sysobjects o&lt;br /&gt;where o.id=c.id&lt;br /&gt;and patindex(@s,text) &gt; 0&lt;br /&gt;order by name&lt;br /&gt;SELECT @msg='* Stored procedures containing string "' + @s + '=' +&lt;br /&gt;convert(varchar(8),@@rowcount) + ' *'&lt;br /&gt;SELECT @ul=replicate('*',datalength(@msg))&lt;br /&gt;Print ' '&lt;br /&gt;PRINT @ul&lt;br /&gt;PRINT @msg&lt;br /&gt;Print @ul&lt;br /&gt;&lt;br /&gt;GO &lt;br /&gt;-----------&lt;br /&gt;&lt;a href="http://www.databasejournal.com/features/mssql/article.php/1458871"&gt;Searching Stored Procedures Source Code&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111758072654340531?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111758072654340531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/05/searching-stored-procedures-source.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111758072654340531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111758072654340531'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/05/searching-stored-procedures-source.html' title='Searching Stored Procedures Source Code'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111591329759250072</id><published>2005-05-12T08:54:00.000-07:00</published><updated>2005-05-12T08:57:44.516-07:00</updated><title type='text'>the Doppelganger</title><content type='html'>Data scrubbing is a fact of database life.  Whenever you import and normalize data you do run the risk of duplicate data imports as well.  This can be especially true if your source database had few restrictions on preventing duplicate data entry.  In one particular table I had many rows with duplicate data down to the entrytime field; everything was identical except for the PKID.  I tried the typical Cursor script found in various websites, but that would Yield an estimate of 14hrs while the test server processed all 16k rows!  I could not very well do that to the production server, on my quest I tried several while loops and eventually came up with this select statement which for my situation (2 duplicate rows for 1 real row of data) First thing I did was dump out all the duplicate rows PK's and FK's into a temp table called #Dup, I hit upon this select statment and I sucessfully narrowed down 16k rows down to 8k of unique data, and was able to delete the duplicate FK's based on the PKid.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     SELECT  A.PKID&lt;br /&gt;        FROM #Dup AS A&lt;br /&gt;        INNER JOIN (SELECT FKID FROM #Dup GROUP BY FKID) B&lt;br /&gt;                ON A.FKID = B.FKID&lt;br /&gt;                AND A.PKID IN (SELECT TOP 1 PKID FROM #DUP C WHERE A.FKID = C.FKID) &lt;br /&gt;&lt;br /&gt;The Select Statement finds one of the Duplicate tables, you can use this statement to delete only these rows leaving a unique record behind.&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111591329759250072?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111591329759250072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/05/doppelganger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111591329759250072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111591329759250072'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/05/doppelganger.html' title='the Doppelganger'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111386032108941608</id><published>2005-04-18T14:38:00.000-07:00</published><updated>2006-11-09T15:45:56.113-08:00</updated><title type='text'>Month Variable Table</title><content type='html'>Every once in a while you need a quick Table w/ a range of dates, that's what this is for...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Declare @iLoop AS INT&lt;br /&gt;SET @iLoop = 0&lt;br /&gt;  DECLARE @rptMonths TABLE(rptMonth DateTime)&lt;br /&gt; WHILE @iLoop &lt;= DateDiff(mm, @StartDate, @EndDate)&lt;br /&gt; BEGIN&lt;br /&gt;  INSERT INTO @rptMonths(rptMonth) VALUES(DATEADD(mm, @iLoop, @StartDate))&lt;br /&gt;  SET @iLoop = @iLoop + 1&lt;br /&gt; END&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111386032108941608?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111386032108941608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/04/month-variable-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111386032108941608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111386032108941608'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/04/month-variable-table.html' title='Month Variable Table'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111342823049299869</id><published>2005-04-13T14:37:00.000-07:00</published><updated>2005-04-13T14:37:10.493-07:00</updated><title type='text'>Get Workday count with out weekends</title><content type='html'>This has come up before in my line of work, to get a total workday count but with out the weekends.&lt;br /&gt;&lt;br /&gt;(DATEDIFF(dd, StartDate, EndDate) + 1)&lt;br /&gt;	  -(DATEDIFF(wk, StartDate, EndDate) * 2)&lt;br /&gt;	  -(CASE WHEN DATENAME(dw, StartDate) = 'Sunday' THEN 1 ELSE 0 END)&lt;br /&gt;	  -(CASE WHEN DATENAME(dw, EndDate) = 'Saturday' THEN 1 ELSE 0 END) AS TotalWorkDays&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111342823049299869?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111342823049299869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/04/get-workday-count-with-out-weekends.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111342823049299869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111342823049299869'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/04/get-workday-count-with-out-weekends.html' title='Get Workday count with out weekends'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-111291284680527871</id><published>2005-04-07T15:27:00.000-07:00</published><updated>2008-03-07T13:06:55.060-08:00</updated><title type='text'>Defrag Those Indexes - Maintenance</title><content type='html'>&lt;span style="font-size:180%;"&gt;&lt;span style="font-weight: bold;"&gt;T&lt;/span&gt;&lt;/span&gt;his article was written back before I was looking into Sql Server 2005.  The underlying idea is the same, in order to keep your database running healthy you will need to maintain and administer the underlying architecture.  In this short but subtle refresh I've separated the 2000 concepts and implementations from those used today in Sql Server 2005.  If you have comments or corrections do feel free to email me or leave a comment.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SQL Server 2000&lt;/span&gt; =====================================================&lt;br /&gt;It is imperative you maintenance your Database.  One way to check up on the indexes per table is to run the DBCC SHOWCONTIG command as DBCC SHOWCONTIG  ('tbl_YourTableName') with fast,ALL_INDEXES&lt;br /&gt;&lt;br /&gt;You'll end up with a very similar display like the following...&lt;br /&gt;&lt;br /&gt;DBCC SHOWCONTIG scanning 'tbl_YourTableName' table...&lt;br /&gt;Table: 'tbl_YourTableName' (1113627606); index ID: 1, database ID: 8&lt;br /&gt;TABLE level scan performed.&lt;br /&gt;- Pages Scanned................................: 1680&lt;br /&gt;- Extent Switches..............................: 217&lt;br /&gt;- Scan Density [Best Count:Actual Count].......: 96.33% [210:218]&lt;br /&gt;- Logical Scan Fragmentation ..................: 0.18%&lt;br /&gt;DBCC SHOWCONTIG scanning 'tbl_YourTableName' table...&lt;br /&gt;Table: 'tbl_YourTableName' (1113627606); index ID: 2, database ID: 8&lt;br /&gt;LEAF level scan performed.&lt;br /&gt;- Pages Scanned................................: 480&lt;br /&gt;- Extent Switches..............................: 64&lt;br /&gt;- Scan Density [Best Count:Actual Count].......: 92.31% [60:65]&lt;br /&gt;- Logical Scan Fragmentation ..................: 0.83%&lt;br /&gt;DBCC SHOWCONTIG scanning 'tbl_YourTableName' table...&lt;br /&gt;Table: 'tbl_YourTableName' (1113627606); index ID: 5, database ID: 8&lt;br /&gt;LEAF level scan performed.&lt;br /&gt;- Pages Scanned................................: 696&lt;br /&gt;- Extent Switches..............................: 95&lt;br /&gt;- Scan Density [Best Count:Actual Count].......: 90.63% [87:96]&lt;br /&gt;- Logical Scan Fragmentation ..................: 0.72%&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;br /&gt;&lt;br /&gt;What you're really looking for is the Scan fragmentation to be as low as possible.  I've also read on other sites that you want the Scan Desity to be as close to each other as possible like for example 87:96 is fairly close and gives you a density over 90%.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;From that you can easily run a defrag on each index as follows&lt;br /&gt;&lt;br /&gt;DBCC INDEXDEFRAG (8, 1113627606, 5)&lt;br /&gt;DBCC INDEXDEFRAG (8, 1113627606, 2)&lt;br /&gt;DBCC INDEXDEFRAG (8, 1113627606, 1)&lt;br /&gt;&lt;br /&gt;More Information can be obtained via: &lt;a href="http://www.sql-server-performance.com/dbcc_commands.asp"&gt;Sql Server Performance\dbcc commands&lt;/a&gt;&lt;br /&gt;And &lt;a href="http://www.sql-server-performance.com/rebuilding_indexes.asp"&gt;sql-server-performance.com/rebuilding_indexes&lt;/a&gt;&lt;br /&gt;and here, &lt;span class="pageTitle"&gt; &lt;a href="http://www.sql-server-performance.com/rd_index_fragmentation.asp"&gt;SQL Server Index Fragmentation and Its Resolution&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you just wish to defrangment the entire database this little script will put you on your way: (from the link above sql server performance site)&lt;br /&gt;&lt;span class="textCode"&gt;SET DatabaseName --Enter the name of the database you want to reindex&lt;br /&gt;&lt;br /&gt;DECLARE @TableName varchar(255)&lt;br /&gt;&lt;br /&gt;DECLARE TableCursor CURSOR FOR&lt;br /&gt;SELECT table_name FROM information_schema.tables&lt;br /&gt;WHERE table_type = 'base table'&lt;br /&gt;&lt;br /&gt;OPEN TableCursor&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM TableCursor INTO @TableName&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;DBCC DBREINDEX(@TableName,' ',90)&lt;br /&gt;FETCH NEXT FROM TableCursor INTO @TableName&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;CLOSE TableCursor&lt;br /&gt;&lt;br /&gt;DEALLOCATE TableCursor&lt;br /&gt;&lt;br /&gt;------END SCRIPT&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:georgia;"&gt;SQL Server 2005 ===================================================&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="textCode"&gt;Fastforward to today,&lt;br /&gt;IndexDefrag still works in 2005, but if you read around the 'net you'll find many more references to choose to rebuild your indexes via the ALTER INDEX command, which is new for SQL Server 2005.&lt;br /&gt;&lt;br /&gt;Before you go out and begin de-fragmenting tables like crazy, it's best to have a plan, finding out how much fragmentation is in your table in 2005 is easier too with the newer function that provides this information. below I've expanded on what you can find around the internet, the below script will allow you to identify rows over 100k and with more than 10% fragmentation,  I also handled the commonly seen error for databases that are of the standard dictionary order (80), and the common "Error near '(' ".&lt;br /&gt;&lt;br /&gt;/script/&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;DECLARE @db_id SMALLINT&lt;br /&gt;SET @db_id = DB_ID()&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;OBJECT_NAME(i.object_id) AS TableName,&lt;br /&gt;i.name AS TableIndexName,&lt;br /&gt;phystat.avg_fragmentation_in_percent, rows&lt;br /&gt;FROM sys.dm_db_index_physical_stats(@db_id, NULL, NULL, NULL, 'DETAILED') phystat&lt;br /&gt;inner JOIN sys.indexes i WITH(NOLOCK)&lt;br /&gt;ON i.object_id = phystat.object_id&lt;br /&gt;AND i.index_id = phystat.index_id&lt;br /&gt;INNER JOIN sys.partitions  p WITH(NOLOCK)&lt;br /&gt;ON p.OBJECT_ID = i.object_id&lt;br /&gt;WHERE phystat.avg_fragmentation_in_percent &gt; 10 AND ROWS &gt; 100000&lt;br /&gt;/end script/&lt;br /&gt;&lt;br /&gt;More information on this system function is availble here:&lt;br /&gt;&lt;a href="http://technet.microsoft.com/en-us/library/ms188917.aspx"&gt;http://technet.microsoft.com/en-us/library/ms188917.aspx&lt;/a&gt;&lt;br /&gt;This link will even give you a cool little script you can use to find out what tables in your database are fragmented over 40%, which is very useful if you are planning a weekend of maintenance.&lt;br /&gt;&lt;a href="http://www.sql-server-performance.com/articles/per/detect_fragmentation_sql2000_sql2005_p1.aspx"&gt;http://www.sql-server-performance.com/articles/per/detect_fragmentation_sql2000_sql2005_p1.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that you have the needed information on how fragmented the indexes are you can begin defragmenting using the Alter Index command&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;ALTER INDEX ALL ON TableName REBUILD&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;What is especially cool about 2005 is that you can choose to throttle the amount of CPUs you use for the defragging process, with the MAXDOP option note, with the following command you can restrict the number of processors down to 2 CPUs:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="textCode"&gt;&lt;span style="font-weight: bold;"&gt;ALTER INDEX ALL ON TableName REBUILD WITH(MAXDOP=2)&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="textCode"&gt;&lt;br /&gt;You can also choose to rebuild your INDEX and continue to make it available for your users as it defrags, I suspect this has performance implications but none the less the command would be:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="textCode"&gt;&lt;span style="font-weight: bold;"&gt;ALTER INDEX ALL ON TableName REBUILD WITH(MAXDOP=2, ONLINE=ON) &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="textCode"&gt;&lt;br /&gt;More information on the ALTER INDEX command is available on the MSDN here:&lt;br /&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms188388.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms188388.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Happy Defragging!&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-111291284680527871?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/111291284680527871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/04/defrag-those-indexes-maintenance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111291284680527871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/111291284680527871'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/04/defrag-those-indexes-maintenance.html' title='Defrag Those Indexes - Maintenance'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-110857309187043926</id><published>2005-02-16T08:58:00.000-08:00</published><updated>2005-02-16T08:58:11.870-08:00</updated><title type='text'>How is your Server Configured</title><content type='html'>The following script works well on Sql Server 2000 (I have not tested it w/ any other versions).  The purpose is to gain as much information back on how your sql server is configured (general settings memory etc.)&lt;br /&gt;&lt;br /&gt;print 'Free Space'&lt;br /&gt;print '----------'&lt;br /&gt;exec master.dbo.xp_fixeddrives&lt;br /&gt;&lt;br /&gt;print 'Memory'&lt;br /&gt;print '------'&lt;br /&gt;exec master.dbo.xp_msver&lt;br /&gt;&lt;br /&gt;print 'Database Configuration'&lt;br /&gt;print '----------------------'&lt;br /&gt;exec master.dbo.sp_configure&lt;br /&gt;&lt;br /&gt;print'DB Size'&lt;br /&gt;print'-------'&lt;br /&gt;exec master.dbo.sp_databases&lt;br /&gt;&lt;br /&gt;print 'Linked Servers'&lt;br /&gt;print '--------------'&lt;br /&gt;exec master.dbo.sp_helplinkedsrvlogin&lt;br /&gt;&lt;br /&gt;print 'Windows info'&lt;br /&gt;print '------------'&lt;br /&gt;exec master.dbo.sp_server_info&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-110857309187043926?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/110857309187043926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/02/how-is-your-server-configured.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/110857309187043926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/110857309187043926'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/02/how-is-your-server-configured.html' title='How is your Server Configured'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-110780431187720790</id><published>2005-02-07T11:21:00.000-08:00</published><updated>2005-02-07T11:25:11.876-08:00</updated><title type='text'>Join against Lists in a Column</title><content type='html'>Now how about you want to select against that Table you now get when you push a list of values through it?&lt;br /&gt;&lt;br /&gt;this Second part is very usefull tho you will have to edit the table name within when you change source tables... possibly a sproc????&lt;br /&gt; &lt;br /&gt; &lt;span style="font-family: courier new;"&gt;Declare @CursorLess Table (PkID INT, ItemList INT)&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; &lt;span style="font-family: courier new; color: rgb(51, 204, 0);"&gt;--Non Cursor solution&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;DECLARE @NC Table  (PkID INT, ItemList VARCHAR(2000)) &lt;span style="color: rgb(51, 204, 0);"&gt;--Cursor like holding bin&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;DECLARE @PkID AS INT, @ListOfItems As VARCHAR(2000) &lt;span style="color: rgb(51, 204, 0);"&gt;-- IDs pointing back to original table&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;INSERT INTO @NC (PkID, ListOfItems) &lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new; color: rgb(51, 204, 0);"&gt;--Change the below select to the actual PKID and List of Items, and Table&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;&lt;span style="font-style: italic; color: rgb(255, 0, 0);"&gt;Select PkID, ListOfItems From UserTable&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;--Populate Holding bin&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;----------------------------------------------------&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;WHILE EXISTS(SELECT * FROM @NC)&lt;span style="color: rgb(51, 204, 0);"&gt; --Check that data exists&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    BEGIN&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    SELECT TOP 1 @PkID = PkID, @ListOfItems = ListOfItems FROM @NC &lt;span style="color: rgb(51, 204, 0);"&gt;--Set Variables&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    INSERT INTO @Cursorless (PkID, ListOfItems) SELECT @PkID, Field1 FROM dbo.udfListToTable(@ListOfItems, ';') &lt;span style="color: rgb(51, 204, 0);"&gt;-- Populate Temp Table&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    DELETE From @NC where PkID = @PkID &lt;span style="color: rgb(51, 204, 0);"&gt;--Clear Variables&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    END&lt;/span&gt;&lt;br /&gt; &lt;br /&gt; &lt;span style="font-family: courier new;"&gt;SELECT * FROM @Cursorless &lt;span style="color: rgb(51, 204, 0);"&gt;-- Use the final Variable table to join approriately....&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-110780431187720790?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/110780431187720790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/02/join-against-lists-in-column.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/110780431187720790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/110780431187720790'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/02/join-against-lists-in-column.html' title='Join against Lists in a Column'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8619066.post-109712010641104938</id><published>2005-02-06T23:00:00.000-08:00</published><updated>2005-02-16T13:22:09.706-08:00</updated><title type='text'>List to Table</title><content type='html'>&lt;span style="font-size:180%;"&gt;E&lt;/span&gt;very now and again, a developer will be faced with the task of referincing a List of id's. It's typically irresistable to want to push all these IDs into a single field. If you're searching then you may end up considering a cursor... for that I decided to write the following function... it's like other Tsql functions that push a list to a table, but this is my take on it... I release the code here with out warranty.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;CREATE FUNCTION udfListToTable (@HList VarChar(2000), @Delimiter CHAR(1))&lt;br /&gt;RETURNS @ListTable TABLE (Field1 VARCHAR(6))&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;   --By: Francisco Tapia&lt;br /&gt;   --Date: 2/1/2005&lt;br /&gt;   --Purpose: To convert a Comma delimited text to a Temp Variable table To help avoid dynamic sql&lt;br /&gt;   --         Instead you can join the temp table or use it in your where clause if a field is IN the subquery&lt;br /&gt;   DECLARE @FieldText as VarChar(6)&lt;br /&gt;&lt;br /&gt;   IF RIGHT(RTRIM(@HLIST),1) &lt;&gt;@Delimiter&lt;br /&gt;       SET @HList = @HList + @Delimiter&lt;br /&gt; &lt;br /&gt;   WHILE CHARINDEX(@Delimiter, @HList) &gt; 0&lt;br /&gt;   BEGIN&lt;br /&gt;       IF CHARINDEX(@Delimiter, @HList) &gt; 0&lt;br /&gt;          BEGIN&lt;br /&gt;           SELECT @FieldText =LEFT(@HList, CHARINDEX(@Delimiter, @HList)-1)&lt;br /&gt;          END&lt;br /&gt;       ELSE  &lt;br /&gt;          BEGIN&lt;br /&gt;            SELECT @FieldText = RTRIM(LTRIM(@HList))&lt;br /&gt;          END&lt;br /&gt;       --Insert into Variable Table&lt;br /&gt;       INSERT INTO @ListTable(Field1)&lt;br /&gt;              SELECT RTRIM(LTRIM(@FieldText))&lt;br /&gt;       --Remove Item from list&lt;br /&gt;       SELECT @HList = RIGHT(RTRIM(@HList), LEN(RTRIM(@HList)) - CHARINDEX(@Delimiter, @HList))&lt;br /&gt;   END  &lt;br /&gt;   RETURN&lt;br /&gt;END&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;TSQL scripts and more...&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8619066-109712010641104938?l=sqlthis.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlthis.blogspot.com/feeds/109712010641104938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlthis.blogspot.com/2005/02/list-to-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/109712010641104938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8619066/posts/default/109712010641104938'/><link rel='alternate' type='text/html' href='http://sqlthis.blogspot.com/2005/02/list-to-table.html' title='List to Table'/><author><name>Francisco</name><uri>http://www.blogger.com/profile/07407021734922699043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://www.rogerjcarlson.com/images/mr_xsmall.gif'/></author><thr:total>0</thr:total></entry></feed>
