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

<channel>
	<title>dougzuck.com &#187; SQL</title>
	<atom:link href="http://dougzuck.com/category/technology/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://dougzuck.com</link>
	<description>A place to put some stuff...</description>
	<lastBuildDate>Sun, 25 Jul 2010 19:48:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>HTML Application &#8211; SQL Differential Backup Size Prediction</title>
		<link>http://dougzuck.com/html-application-sql-differential-backup-size-prediction</link>
		<comments>http://dougzuck.com/html-application-sql-differential-backup-size-prediction#comments</comments>
		<pubDate>Sun, 02 Aug 2009 20:50:01 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[HTML Applications]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[HTA]]></category>

		<guid isPermaLink="false">http://dougzuck.com/?p=645</guid>
		<description><![CDATA[You can find the full post here: http://dougzuck.com/hta]]></description>
			<content:encoded><![CDATA[<p>You can find the full post here: <a href="http://dougzuck.com/hta">http://dougzuck.com/hta</a></p>
<p style="text-align: center;"><a href="http://dougzuck.com/wp-content/uploads/2009/05/diffBackupPredictionHTA.png"><img class="aligncenter size-full wp-image-640" title="diffBackupPredictionHTA" src="http://dougzuck.com/wp-content/uploads/2009/05/diffBackupPredictionHTA.png" alt="diffBackupPredictionHTA" width="597" height="221" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/html-application-sql-differential-backup-size-prediction/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL &#8211; Differential Backup Size Prediction</title>
		<link>http://dougzuck.com/sql-differential-backup-size-prediction</link>
		<comments>http://dougzuck.com/sql-differential-backup-size-prediction#comments</comments>
		<pubDate>Sun, 02 Aug 2009 20:22:32 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://dougzuck.com/?p=625</guid>
		<description><![CDATA[SQL Differential Backup Size Prediction]]></description>
			<content:encoded><![CDATA[<p>One of the tasks I regularly have to perform at my job involves moving multi-terabyte databases from one server to another.  The goal is to make these database moves happen with as little downtime as possible, so I always make use of differential backups and restores to keep the move times to a minimum.  I&#8217;ll do a full backup of the source database, then I&#8217;ll perform a restore of that database to the new server, specifying &#8216;with norecovery&#8217; in the restore command.  For a 2 terabyte database, this process will take many hours, but that&#8217;s ok because I&#8217;ll make sure it&#8217;s complete prior to the actual maintenance window.  Then when the maintenance window begins, I&#8217;ll disable access to the database and perform a differential backup of the database on the source server.  Then I restore the differential backup &#8216;with recovery&#8217; to the new server.  The process of doing a differential backup and restore is <em>much</em> less time consuming than the full backup and restore, and this allows the actual maintenance window to be much smaller since the full backup and restore is completed at an earlier time.  However, when I&#8217;m dealing with such large databases, it becomes extremely helpful to know how big the differential backup is going to be before I actually execute it.  This way I&#8217;m able to estimate how long the whole process will take.  When you have a 2 terabyte database, it&#8217;s not uncommon to have a several hundred gigabyte differential backup.  You could see why it might help to know in advance whether the differential is going to be 10GB or 200GB.</p>
<p>Darwin Hatheway wrote a <a href="http://www.sqlservercentral.com/articles/Administration/differentialbackupprediction/2306/">really nice article</a> explaining how the differential backup size can be estimated.  He gets all the credit for teaching me how to do this.  I have two implementations below.  One is a straight T-SQL script, and the other is a HTML Application (HTA) that utilizes the T-SQL script with a bit of vbscript.  On a 2TB database it generally only takes a handful of seconds for the script to complete.</p>
<p>T-SQL Version: <a href="http://dougzuck.com/downloads/SQL-Differential-Backup-Size-Prediction-dz.sql">SQL Differential Backup Size Prediction</a><br />
HTML Application: <a href="http://dougzuck.com/hta">http://dougzuck.com/hta</a></p>
<p><a href="http://dougzuck.com/wp-content/uploads/2009/08/diffPredictionResults.png"><img class="aligncenter size-full wp-image-631" title="diffPredictionResults" src="http://dougzuck.com/wp-content/uploads/2009/08/diffPredictionResults.png" alt="diffPredictionResults" width="349" height="36" /></a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*SQL Differential Backup Size Prediction - Doug Zuckerman, 2009 - http://dougzuck.com */</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">IF</span> isNULL<span style="color: #66cc66;">&#40;</span>object_id<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'tempdb.dbo.##showFileStats'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">1</span>
	<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">##showFileStats</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">##showFileStats (</span>
	fileID INT<span style="color: #66cc66;">,</span>
	fileGroup INT<span style="color: #66cc66;">,</span>
	totalExtents BIGINT<span style="color: #66cc66;">,</span>
	usedExtents BIGINT<span style="color: #66cc66;">,</span>
	logicalFileName VARCHAR <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>	
	filePath VARCHAR <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">IF</span> isNULL<span style="color: #66cc66;">&#40;</span>object_id<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'tempdb.dbo.##DCM'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #cc66cc;">1</span>
	<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">##DCM</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">##DCM (</span>
	parentObject VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>object<span style="color: #66cc66;">&#93;</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FIELD</span> VARCHAR <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	value VARCHAR <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*we need to get a list of all the files in the database.  each file needs to be looked at*/</span>	
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #808080; font-style: italic;">##showFileStats EXEC('DBCC SHOWFILESTATS with tableresults')</span>
&nbsp;
DECLARE @currentFileID INT<span style="color: #66cc66;">,</span>
	@totalExtentsOfFile BIGINT<span style="color: #66cc66;">,</span>
	@dbname VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	@SQL VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	@currentDCM BIGINT<span style="color: #66cc66;">,</span>
	@step INT
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @dbname <span style="color: #66cc66;">=</span> db_name<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SET</span> @step <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">511232</span>
&nbsp;
DECLARE myCursor SCROLL CURSOR <span style="color: #993333; font-weight: bold;">FOR</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> fileID<span style="color: #66cc66;">,</span> totalExtents 
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">##showFileStats</span>
&nbsp;
OPEN myCursor
FETCH NEXT <span style="color: #993333; font-weight: bold;">FROM</span> myCursor <span style="color: #993333; font-weight: bold;">INTO</span> @currentFileID<span style="color: #66cc66;">,</span> @totalExtentsOfFile
&nbsp;
<span style="color: #808080; font-style: italic;">/*look at each differential change map page in each data file of the database and put the output into ##DCM*/</span>
WHILE @@FETCH_STATUS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> 
BEGIN
&nbsp;
	<span style="color: #993333; font-weight: bold;">SET</span> @currentDCM <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">6</span>
	WHILE @currentDCM <span style="color: #66cc66;">&lt;=</span> @totalExtentsOfFile<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">8</span>
	BEGIN	
		<span style="color: #993333; font-weight: bold;">SET</span> @SQL <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'dbcc page('</span><span style="color: #66cc66;">+</span> @dbname <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', '</span> <span style="color: #66cc66;">+</span> CAST<span style="color: #66cc66;">&#40;</span>@currentFileID <span style="color: #993333; font-weight: bold;">AS</span> VARCHAR<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', '</span> <span style="color: #66cc66;">+</span> CAST<span style="color: #66cc66;">&#40;</span>@currentDCM <span style="color: #993333; font-weight: bold;">AS</span> VARCHAR<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', 3) WITH TABLERESULTS'</span>
		<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #808080; font-style: italic;">##DCM EXEC (@SQL)</span>
		<span style="color: #993333; font-weight: bold;">SET</span> @currentDCM <span style="color: #66cc66;">=</span> @currentDCM <span style="color: #66cc66;">+</span> @step
	END
&nbsp;
	FETCH NEXT <span style="color: #993333; font-weight: bold;">FROM</span> myCursor <span style="color: #993333; font-weight: bold;">INTO</span> @currentFileID<span style="color: #66cc66;">,</span> @totalExtentsOfFile
END
CLOSE myCursor
DEALLOCATE myCursor
&nbsp;
<span style="color: #808080; font-style: italic;">/*remove all unneeded rows from our results table*/</span>
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">##DCM WHERE value = 'NOT CHANGED' OR parentObject NOT LIKE 'DIFF_MAP%'</span>
<span style="color: #808080; font-style: italic;">--SELECT * FROM ##DCM</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*sum the extentTally column*/</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> SUM <span style="color: #66cc66;">&#40;</span>extentTally<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> totalChangedExtents<span style="color: #66cc66;">,</span> SUM<span style="color: #66cc66;">&#40;</span>extentTally<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">16</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'diffPrediction(MB)'</span><span style="color: #66cc66;">,</span> SUM<span style="color: #66cc66;">&#40;</span>extentTally<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'diffPrediction(GB)'</span> 
<span style="color: #993333; font-weight: bold;">FROM</span>
	<span style="color: #808080; font-style: italic;">/*create extentTally column*/</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> extentTally <span style="color: #66cc66;">=</span>
	CASE
		WHEN secondChangedExtent <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> THEN CAST<span style="color: #66cc66;">&#40;</span>secondChangedExtent <span style="color: #993333; font-weight: bold;">AS</span> BIGINT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> CAST<span style="color: #66cc66;">&#40;</span>firstChangedExtent <span style="color: #993333; font-weight: bold;">AS</span> BIGINT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>
		ELSE <span style="color: #cc66cc;">1</span>
	END
	<span style="color: #993333; font-weight: bold;">FROM</span>
		<span style="color: #808080; font-style: italic;">/*parse the 'field' column to give us the first and last extents of the range*/</span>
		<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">')'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#40;</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">8</span> <span style="color: #993333; font-weight: bold;">AS</span> firstChangedExtent<span style="color: #66cc66;">,</span>
		secondChangedExtent <span style="color: #66cc66;">=</span> 
		CASE	
			WHEN CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> THEN <span style="color: #66cc66;">&#40;</span>SUBSTRING<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">')'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">')'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #66cc66;">&#40;</span>CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">8</span>
			ELSE <span style="color: #ff0000;">''</span>
		END 
		<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">##DCM)parsedFieldColumn)extentTallyColumn</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/sql-differential-backup-size-prediction/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Application &#8211; Retrieve SP_WHO2 and the Input Buffer from a SQL Server</title>
		<link>http://dougzuck.com/html-application-retrieve-sp_who2-and-the-input-buffer-from-a-sql-server</link>
		<comments>http://dougzuck.com/html-application-retrieve-sp_who2-and-the-input-buffer-from-a-sql-server#comments</comments>
		<pubDate>Sun, 05 Jul 2009 01:56:56 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[HTML Applications]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[HTA]]></category>

		<guid isPermaLink="false">http://dougzuck.com/?p=600</guid>
		<description><![CDATA[You can find the full post here: http://www.dougzuck.com/hta]]></description>
			<content:encoded><![CDATA[<p>You can find the full post here: <a href="http://www.dougzuck.com/hta" target="_self">http://www.dougzuck.com/hta</a></p>
<p style="text-align: center;"><a href="http://dougzuck.com/wp-content/uploads/2009/05/get_sql_spwho2_and_inputbuffer.png"><img class="aligncenter size-large wp-image-520" title="get_sql_spwho2_and_inputbuffer" src="http://dougzuck.com/wp-content/uploads/2009/05/get_sql_spwho2_and_inputbuffer-1024x676.png" alt="get_sql_spwho2_and_inputbuffer" width="614" height="406" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/html-application-retrieve-sp_who2-and-the-input-buffer-from-a-sql-server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Application &#8211; Retrieve SQL Backup History</title>
		<link>http://dougzuck.com/html-application-retrieve-sql-backup-history</link>
		<comments>http://dougzuck.com/html-application-retrieve-sql-backup-history#comments</comments>
		<pubDate>Thu, 25 Jun 2009 00:46:11 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[HTML Applications]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[HTA]]></category>

		<guid isPermaLink="false">http://www.dougzuck.com/?p=472</guid>
		<description><![CDATA[You can find the full post here: http://www.dougzuck.com/hta]]></description>
			<content:encoded><![CDATA[<p>You can find the full post here: <a href="http://www.dougzuck.com/hta" target="_self">http://www.dougzuck.com/hta</a></p>
<p style="text-align: center;"><a href="http://dougzuck.com/wp-content/uploads/2009/05/get_sql_backup_history.png"><img class="aligncenter size-full wp-image-375" title="get_sql_backup_history" src="http://dougzuck.com/wp-content/uploads/2009/05/get_sql_backup_history.png" alt="get_sql_backup_history" width="602" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/html-application-retrieve-sql-backup-history/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Application &#8211; Retrieving a graphical representation of all SQL databases and the breakdown of space used by each</title>
		<link>http://dougzuck.com/html-application-retrieving-a-graphical-representation-of-all-sql-databases-and-the-breakdown-of-space-used-by-each</link>
		<comments>http://dougzuck.com/html-application-retrieving-a-graphical-representation-of-all-sql-databases-and-the-breakdown-of-space-used-by-each#comments</comments>
		<pubDate>Mon, 08 Jun 2009 03:32:18 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[HTML Applications]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[HTA]]></category>

		<guid isPermaLink="false">http://www.dougzuck.com/?p=345</guid>
		<description><![CDATA[You can find the full post here: http://www.dougzuck.com/hta]]></description>
			<content:encoded><![CDATA[<p>You can find the full post here: <a href="http://www.dougzuck.com/hta" target="_self">http://www.dougzuck.com/hta</a></p>
<p style="text-align: center;"><a href="http://dougzuck.com/wp-content/uploads/2009/06/get_sql_db_sizes.png"><img class="aligncenter size-large wp-image-346" title="get_sql_db_sizes" src="http://dougzuck.com/wp-content/uploads/2009/06/get_sql_db_sizes-1024x322.png" alt="get_sql_db_sizes" width="614" height="193" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/html-application-retrieving-a-graphical-representation-of-all-sql-databases-and-the-breakdown-of-space-used-by-each/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL 2005 Backup History &#8211; How to retrieve a list of the most recent database backups</title>
		<link>http://dougzuck.com/sql-how-to-retrieve-a-list-of-the-most-recent-database-backups</link>
		<comments>http://dougzuck.com/sql-how-to-retrieve-a-list-of-the-most-recent-database-backups#comments</comments>
		<pubDate>Sun, 07 Jun 2009 20:26:59 +0000</pubDate>
		<dc:creator>doug</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.dougzuck.com/?p=287</guid>
		<description><![CDATA[The MSDB database maintains a record of all SQL backup jobs that have been executed.  Specifically you can find this information if you query MSDB..backupset.  This script joins sys.databases, so that if a database exists but has not been backed up yet, it will still be displayed in the results.  If you were to query [...]]]></description>
			<content:encoded><![CDATA[<p>The MSDB database maintains a record of all SQL backup jobs that have been executed.  Specifically you can find this information if you query MSDB..backupset.  This script joins sys.databases, so that if a database exists but has not been backed up yet, it will still be displayed in the results.  If you were to query the backupset table alone without the JOIN statement, you wouldn&#8217;t see any entries for databases on the server that have not been backed up.  Also note that this particular script assumes that you&#8217;re only interested in Full and Differential backups.  You could easily modify it to include information about Log backups.</p>
<p>Download the script here: <a href="http://dougzuck.com/downloads/SQL_Backup_History.sql">SQL Backup History</a></p>
<p>I&#8217;ve also posted a HTML Application (HTA) version of this script as well, which you can see here: <a href="http://dougzuck.com/hta">http://dougzuck.com/hta</a></p>
<p>OK, let&#8217;s take a look at the code&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> @@servername <span style="color: #993333; font-weight: bold;">AS</span> server_name<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> database_name<span style="color: #66cc66;">,</span> backup_type <span style="color: #66cc66;">=</span>
CASE
    WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> THEN <span style="color: #ff0000;">'Full'</span>
    WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'I'</span> THEN <span style="color: #ff0000;">'Diff'</span>
END<span style="color: #66cc66;">,</span>
MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> last_backup_start_time<span style="color: #66cc66;">,</span>
DATEDIFF<span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> getdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> days_since_last_backup<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #66cc66;">=</span>
CASE
    WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> <span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> getdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;=</span> <span style="color: #cc66cc;">7</span> THEN <span style="color: #ff0000;">'OK'</span> <span style="color: #808080; font-style: italic;">/*if the most recent full backup was less than or equal to 7 days ago, we're OK*/</span>     WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'D'</span> <span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> getdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">7</span> THEN <span style="color: #ff0000;">'Possible Problem'</span> <span style="color: #808080; font-style: italic;">/*if the most recent full backup was more than 7 days ago, Possible Problem*/</span>
    WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'I'</span> <span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> getdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;=</span> <span style="color: #cc66cc;">2</span> THEN <span style="color: #ff0000;">'OK'</span> <span style="color: #808080; font-style: italic;">/*if the most recent diff backup was less than or equal to 3 days ago, we're OK*/</span>     WHEN b<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'I'</span> <span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>d<span style="color: #66cc66;">,</span> MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> getdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">2</span> THEN <span style="color: #ff0000;">'Possible Problem'</span> <span style="color: #808080; font-style: italic;">/*if the most recent diff backup was more than 3 days ago, Possible Problem*/</span>
    WHEN MAX<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span>backup_start_date<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #ff0000;">'No Backup Exists'</span>
END
<span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">DATABASES</span> s <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> msdb<span style="color: #66cc66;">..</span>backupset b
<span style="color: #993333; font-weight: bold;">ON</span> s<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>database_name
<span style="color: #993333; font-weight: bold;">WHERE</span> s<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">'master'</span> <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">'model'</span> <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">'msdb'</span> <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">'tempdb'</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> b<span style="color: #66cc66;">.</span>type
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name</pre></div></div>

<p>You can see in the results screenshot below that I haven&#8217;t done backups of my local databases in a long time, which is why the status column is indicating there&#8217;s a &#8220;Possible Problem.&#8221;<br />
<a href="http://www.dougzuck.com/wp-content/uploads/2009/06/backup_history_results.png"></a><a href="http://www.dougzuck.com/wp-content/uploads/2009/06/backup_history_results1.png"><img class="alignnone size-full wp-image-298" title="backup_history_query_results" src="http://www.dougzuck.com/wp-content/uploads/2009/06/backup_history_results1.png" alt="backup_history_query_results" width="595" height="86" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dougzuck.com/sql-how-to-retrieve-a-list-of-the-most-recent-database-backups/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
