<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Sans SQL</title><link>http://www.sanssql.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SansSQL" /><description>Tips and Tricks on SQL Server</description><language>en</language><managingEditor>noreply@blogger.com (Sandesh Segu)</managingEditor><lastBuildDate>Thu, 26 Jan 2012 19:41:50 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">185</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">25</openSearch:itemsPerPage><feedburner:info uri="sanssql" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Software How-To</media:category><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><itunes:explicit>no</itunes:explicit><itunes:subtitle>Tips and Tricks on SQL Server</itunes:subtitle><itunes:category text="Technology"><itunes:category text="Software How-To" /></itunes:category><creativeCommons:license>http://creativecommons.org/licenses/by-nd/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nd/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>SansSQL</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Welcome to SansSQL...</title><link>http://feedproxy.google.com/~r/SansSQL/~3/tPmSDIJgrVE/welcome-to-sanssql.html</link><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Fri, 05 Nov 2010 21:31:11 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8076857913536425920</guid><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span id="goog_258336285"&gt;&lt;/span&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_AbIKetdYOrc/TNQZftSPMMI/AAAAAAAAEv0/a_nsmesakts/s1600/My_Logo_New.png" /&gt;&lt;span id="goog_258336286"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;SansSQL&amp;nbsp;is an SQL server blog which is dedicated for SQL Server related topics, tips and tricks. In this Blog I will also be posting about Business Intelligence and Data Warehousing too.&amp;nbsp; For&amp;nbsp;further questions, suggestions, feedback&amp;nbsp;or topics that you would like to post on this blog, feel free to contact me @ &lt;/div&gt;&lt;/div&gt;&lt;div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;"&gt;&lt;a href="mailto:segu.sandesh@gmail.com" style="cssfloat: right; margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="Contact Me" border="0" iq="true" src="http://2.bp.blogspot.com/_AbIKetdYOrc/SrMFfAS4paI/AAAAAAAADpw/DUYCumDfxto/s320/segu.sandesh-email.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8076857913536425920?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sY5bG6KZxYLSb_B9fLNpiv1Qt9A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sY5bG6KZxYLSb_B9fLNpiv1Qt9A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sY5bG6KZxYLSb_B9fLNpiv1Qt9A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sY5bG6KZxYLSb_B9fLNpiv1Qt9A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/tPmSDIJgrVE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-06T10:01:11.640+05:30</app:edited><media:thumbnail url="http://3.bp.blogspot.com/_AbIKetdYOrc/TNQZftSPMMI/AAAAAAAAEv0/a_nsmesakts/s72-c/My_Logo_New.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.sanssql.com/2009/09/welcome-to-sanssql.html</feedburner:origLink></item><item><title>Replication Error - SQL Server replication requires the actual server name to make connection to the server</title><link>http://feedproxy.google.com/~r/SansSQL/~3/lU9xlY1RKr8/replication-error-sql-server.html</link><category>Replication</category><category>Troubleshooting</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Wed, 11 Jan 2012 02:24:50 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-6869767462719729003</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Sometimes when we try to configuration relpication we might receive the below error which says that "SQL Server replication requires the actual server name to make connection to the server" &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://1.bp.blogspot.com/-j3vnKrtov4g/Tw1WgefivYI/AAAAAAAAFS4/5MJ0zl_EzYA/s1600/Replication+error.png" /&gt;&lt;/div&gt;
&lt;span id="goog_1413184287"&gt;&lt;/span&gt;&lt;span id="goog_1413184288"&gt;&lt;/span&gt;&lt;br /&gt;
This can happen during the situations&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;When you are connected to the server in object explorer using the IP address&lt;/li&gt;
&lt;li&gt;When the actual server&amp;nbsp;host name&amp;nbsp;hosting the SQL server database engine is changed&lt;/li&gt;
&lt;/ol&gt;
In the first case we can solve this issue by connecting to the server with the host name.&lt;br /&gt;
&lt;br /&gt;
In the second case, to fix the issue we need to update the system&amp;nbsp;catalogs&amp;nbsp;by dropping and adding the server and&amp;nbsp;restarting&amp;nbsp;the SQL Server services. The updation of&amp;nbsp;system&amp;nbsp;catalogs can be done using the below queries.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE master 
GO
EXEC sp_dropserver 'OldServerName'

USE master 
GO
EXEC sp_addserver 'NewServerName',local
&lt;/pre&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-6869767462719729003?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TQk9Zno8M40e1JoTPBV2we2ngZ0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TQk9Zno8M40e1JoTPBV2we2ngZ0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TQk9Zno8M40e1JoTPBV2we2ngZ0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TQk9Zno8M40e1JoTPBV2we2ngZ0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/lU9xlY1RKr8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-11T15:54:50.492+05:30</app:edited><media:thumbnail url="http://1.bp.blogspot.com/-j3vnKrtov4g/Tw1WgefivYI/AAAAAAAAFS4/5MJ0zl_EzYA/s72-c/Replication+error.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.sanssql.com/2012/01/replication-error-sql-server.html</feedburner:origLink></item><item><title>Happy New Year 2012</title><link>http://feedproxy.google.com/~r/SansSQL/~3/tGZxqYSwxrc/happy-new-year-2012.html</link><category>What's New</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sun, 01 Jan 2012 20:16:51 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-6212320756174502405</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Wishing you all a very happy and prosperous new year.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;A Special Query for you all on this new year day :)&lt;/span&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SET NOCOUNT ON
Select CHAR(72) + CHAR(97) + CHAR(112) + CHAR(112) + CHAR(121) + 
  SPACE(1) +  
  CHAR(78) + CHAR(101) + CHAR(119) +
  SPACE(1) +
  CHAR(89) + CHAR(101) + CHAR(97) + CHAR(114) +
  SPACE(1) +
CHAR(50)+CHAR(48)+CHAR(49)+CHAR(50) AS 'Surprise'
SET NOCOUNT OFF
&lt;/pre&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-6212320756174502405?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tPp6NwUzmaAD6CsErqZWqh7UkjY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tPp6NwUzmaAD6CsErqZWqh7UkjY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tPp6NwUzmaAD6CsErqZWqh7UkjY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tPp6NwUzmaAD6CsErqZWqh7UkjY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/tGZxqYSwxrc" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-02T09:46:51.902+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2012/01/happy-new-year-2012.html</feedburner:origLink></item><item><title>Granting Read-Only and administrative access to Central Management Server (CMS)</title><link>http://feedproxy.google.com/~r/SansSQL/~3/TIbHuc5Mzss/granting-read-only-and-administrative.html</link><category>SQL Server 2008</category><category>Central Management Server</category><category>SQL Information</category><category>SQL Server 2012</category><category>msdb</category><category>SQL Server 2011</category><category>CMS</category><category>SQL Queries</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sun, 04 Dec 2011 17:30:01 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8686055138577515460</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In one of my previous &lt;a href="http://www.sanssql.com/2009/10/central-management-server.html" target="_blank"&gt;post&lt;/a&gt;, I had discussed about the Central Management Server and how to Register it.&lt;br /&gt;
In this post, I will be telling how to give read-only access and a Administrative access to an existing CMS.&lt;br /&gt;
&lt;br /&gt;
Grating the Read-Only and Administrative access to CMS is very simply and the activity&amp;nbsp;includes&amp;nbsp;adding&amp;nbsp;the right database users to right groups in msdb database.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Granting Read-Only access&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [msdb]
GO
CREATE USER [DBUserName] FOR LOGIN [LoginName]
GO
EXEC sp_addrolemember N'ServerGroupReaderRole', N'DBUserName'
GO
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Granting Administrator access&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
This access is usually give to the DBA's&lt;/div&gt;
&lt;pre class="brush:sql"&gt;USE [msdb]
GO
CREATE USER [DBAUserName] FOR LOGIN [DBALoginName]
GO
EXEC sp_addrolemember N'ServerGroupAdministratorRole', N'DBAUserName'
GO
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8686055138577515460?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/R4tXyxp-6x1YMcqbYgJ-pV8elqE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R4tXyxp-6x1YMcqbYgJ-pV8elqE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/R4tXyxp-6x1YMcqbYgJ-pV8elqE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R4tXyxp-6x1YMcqbYgJ-pV8elqE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/TIbHuc5Mzss" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-05T07:00:01.146+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/12/granting-read-only-and-administrative.html</feedburner:origLink></item><item><title>Give access to a non sysadmin user to run Profiler</title><link>http://feedproxy.google.com/~r/SansSQL/~3/nyA768KeO3g/give-access-to-non-sysadmin-user-to-run.html</link><category>Trace</category><category>SQL Server 2008</category><category>SQL Server 2012</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>Profiler</category><category>SQL Queries</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sat, 03 Dec 2011 20:18:47 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-1298421960621420756</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Sometimes as a DBA,&amp;nbsp;you&amp;nbsp;come&amp;nbsp;across&amp;nbsp;a situation where you need to give access to a non sysadmin user to run&amp;nbsp;profiler&amp;nbsp;on a particular SQL server.&lt;br /&gt;
If you try to run the profiler using the user who does not have sysadmin access then you will get the below error.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://4.bp.blogspot.com/-zBHiWzrz5GM/TtruQ5nN4RI/AAAAAAAAFSs/o7eJ56NysA4/s1600/1.JPG" /&gt;&lt;/div&gt;
&lt;br /&gt;
Here is the solution how to grant access to a non sysadmin user to run profiler.&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Using Query:&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- To Grant access to a Windows Login
USE master;
GRANT ALTER TRACE TO [Domain\WindowsLogin]

-- To Grant access to a SQL Login
USE master;
GRANT ALTER TRACE TO [SQL User]
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Using SSMS:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Expand the Server in object Explorer&lt;/li&gt;
&lt;li&gt;Expand "Security" folder and then "logins"&lt;/li&gt;
&lt;li&gt;Right-Click on the login to which you need to give access and then go to "Properties" of that login&lt;/li&gt;
&lt;li&gt;Go to "Securables" Tab&lt;/li&gt;
&lt;li&gt;Select the server you want to add the permission&lt;/li&gt;
&lt;li&gt;In the "Permission for &amp;lt;Server Name&amp;gt;" block, click on "Grant" check box for "Alter Trace" and click "OK"&lt;/li&gt;
&lt;li&gt;Once this is completed, the permission should appear in the "Effective" Tab&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Note&lt;/u&gt;&lt;/b&gt;: The&amp;nbsp;Granter should be a sysadmin user. &amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-1298421960621420756?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8srNmxEawCN1pN5NWUmD93kSBy8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8srNmxEawCN1pN5NWUmD93kSBy8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8srNmxEawCN1pN5NWUmD93kSBy8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8srNmxEawCN1pN5NWUmD93kSBy8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/nyA768KeO3g" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-04T09:48:47.666+05:30</app:edited><media:thumbnail url="http://4.bp.blogspot.com/-zBHiWzrz5GM/TtruQ5nN4RI/AAAAAAAAFSs/o7eJ56NysA4/s72-c/1.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/12/give-access-to-non-sysadmin-user-to-run.html</feedburner:origLink></item><item><title>Convert Rows to Column using COALESCE() function</title><link>http://feedproxy.google.com/~r/SansSQL/~3/sRaArkx0Ay0/convert-rows-to-column-using-coalesce.html</link><category>SQL Information</category><category>Interview Questions</category><category>SQL Queries</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Fri, 25 Nov 2011 08:25:09 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-4574058028598437656</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Using the below query we can convert the rows to column sperated by a delimiter.&lt;br /&gt;
In the query I am using ';' as the delimiter and you can change the delimiter of your choice by replacing ';'.&lt;br /&gt;
&lt;strong&gt;Data from Table:&lt;/strong&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://2.bp.blogspot.com/-_wY49qugWow/Ts--W_aIj5I/AAAAAAAAFSc/KpscW_16D-4/s1600/1.PNG" /&gt;&lt;/div&gt;
&lt;strong&gt;Query:&lt;/strong&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;Use AdventureWorks2008R2
GO
DECLARE @eMailList nvarchar(max) 

SELECT @eMailList = COALESCE(@eMailList + ';', '') + 
   CAST(eMail AS nvarchar(max))
FROM Employees

Select @eMailList as eMailList
&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;strong&gt;Output of the above Query:&lt;/strong&gt;﻿&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/-hptPcQnKdos/Ts-_HiGwMaI/AAAAAAAAFSk/DsQTW8wQzp8/s1600/2.PNG" /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-4574058028598437656?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/r7uSaz6i6T3wcTwDRsHUQUv6knM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r7uSaz6i6T3wcTwDRsHUQUv6knM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/r7uSaz6i6T3wcTwDRsHUQUv6knM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r7uSaz6i6T3wcTwDRsHUQUv6knM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/sRaArkx0Ay0" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-25T21:55:09.138+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/-_wY49qugWow/Ts--W_aIj5I/AAAAAAAAFSc/KpscW_16D-4/s72-c/1.PNG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/11/convert-rows-to-column-using-coalesce.html</feedburner:origLink></item><item><title>Microsoft SQL Server 2012 Release Candidate 0 (RC0) - Available for Download</title><link>http://feedproxy.google.com/~r/SansSQL/~3/yDdDgm5ZATU/microsoft-sql-server-2012-release.html</link><category>Denali</category><category>SQL Server 2012</category><category>Downloads</category><category>SQL Server 2011</category><category>What's New</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Fri, 18 Nov 2011 06:39:47 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-815596787276883570</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;Microsoft SQL Server 2012 RC0 enables a cloud-ready information platform that will help organizations unlock breakthrough insights across the organization as well as quickly build solutions and extend data across on-premises and public cloud backed by capabilities for mission critical confidence.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;To read more and download&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;Microsoft SQL Server 2012 RC0&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt; &lt;span class="Apple-style-span" style="color: black;"&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?id=28145" target="_blank"&gt;click here&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-815596787276883570?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kn4ToGDPBuWkVqiYcPv8l2-eI08/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kn4ToGDPBuWkVqiYcPv8l2-eI08/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kn4ToGDPBuWkVqiYcPv8l2-eI08/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kn4ToGDPBuWkVqiYcPv8l2-eI08/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/yDdDgm5ZATU" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-18T20:09:47.886+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/11/microsoft-sql-server-2012-release.html</feedburner:origLink></item><item><title>Backup Database to multiple locations simultaneously - Mirror Backups</title><link>http://feedproxy.google.com/~r/SansSQL/~3/aVXP2OEkO7g/backup-database-to-multiple-locations.html</link><category>SQL Server 2008</category><category>Backup and Restore</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>What's New</category><category>Backup</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Tue, 27 Sep 2011 08:20:32 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-9151359768786323927</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Database backup is one the regular activity a DBA would perform. Some times you might come across a situation where in you need to backup the database to different location. When I say backup database to different locations, it means that a copy of backup&amp;nbsp;file&amp;nbsp;needs to be placed on a different location as well and this is different from the Split Backups.&lt;br /&gt;
&lt;div&gt;
This is can be achieved by different methods,&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Take backup and then copy to multiple location&lt;/li&gt;
&lt;li&gt;Take backup of the same database multiple times pointing to different locations&lt;/li&gt;
&lt;li&gt;Use "MIRROR TO" Option in the Backup command&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Using the option "MIRROR TO" is very simple, you just need to mention "MIRROR TO" and "WITH FORMAT" options in the normal BACKUP DATABASE Statement and you are done. The backup database statement with these two options will take the backup of the same database to multiple locations at the same time.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
This option "MIRROR TO" is introduced in SQL Server 2005&amp;nbsp;and this works only in SQL Server 2005 Enterprise Edition and later versions.&lt;/div&gt;
&lt;div&gt;
This can be used for all backup types and the&amp;nbsp;Maximum&amp;nbsp;number of "MIRROR TO" clauses that you can&amp;nbsp;specify&amp;nbsp;is three.&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Example&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 650px;"&gt;

&lt;tbody&gt;
&lt;tr&gt;

 &lt;td&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;BACKUP&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; &lt;span style="color: teal;"&gt;AdventureWorks&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;TO&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Backup\AdventureWorks_Full.bak'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;MIRROR&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;TO&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Mirror\AdventureWorks_Full.bak'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;WITH&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: green;"&gt;STATS&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;10&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: teal;"&gt;FORMAT&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;BACKUP&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; &lt;span style="color: teal;"&gt;AdventureWorks&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;TO&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Backup\AdventureWorks_Differential.bak'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;MIRROR&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;TO&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Mirror\AdventureWorks_Differential.bak'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;WITH&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: green;"&gt;STATS&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;10&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: blue;"&gt;DIFFERENTIAL&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: teal;"&gt;FORMAT&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;BACKUP&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: magenta;"&gt;LOG&lt;/span&gt; &lt;span style="color: teal;"&gt;AdventureWorks&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;TO&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Backup\AdventureWorks_log.trn'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;MIRROR&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;TO&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'C:\Mirror\AdventureWorks_log.trn'&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;WITH&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: green;"&gt;STATS&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;10&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: teal;"&gt;FORMAT&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt; 

&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="143" src="http://3.bp.blogspot.com/-hrYMCr67cIc/ToHoF31Uw7I/AAAAAAAAFSA/aspz6TL_sdQ/s640/Backup.JPG" width="640" /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="140" src="http://1.bp.blogspot.com/-0unen_a09FQ/ToHoHdRjW5I/AAAAAAAAFSE/0vSmv8J8GYA/s640/Mirror.JPG" width="640" /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
When it comes to restoring the database, we can use either of the backup copies to restore or recover the database.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-9151359768786323927?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Os3zUvbG-kiFEkHJWsyTf_nh6FQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Os3zUvbG-kiFEkHJWsyTf_nh6FQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Os3zUvbG-kiFEkHJWsyTf_nh6FQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Os3zUvbG-kiFEkHJWsyTf_nh6FQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/aVXP2OEkO7g" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-27T20:50:32.358+05:30</app:edited><media:thumbnail url="http://3.bp.blogspot.com/-hrYMCr67cIc/ToHoF31Uw7I/AAAAAAAAFSA/aspz6TL_sdQ/s72-c/Backup.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/09/backup-database-to-multiple-locations.html</feedburner:origLink></item><item><title>Hide an Instance of SQL Server Database Engine</title><link>http://feedproxy.google.com/~r/SansSQL/~3/5PTSH3QHzgY/hide-instance-of-sql-server-database.html</link><category>SQL Server 2008</category><category>SQL Server Protocols</category><category>Hide Instance</category><category>SQL Server 2011</category><category>SQL Server 2005</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Thu, 15 Sep 2011 21:03:12 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8555452120075801366</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In one of my previous post "&lt;a href="http://www.sanssql.com/2010/02/list-of-sql-server-instances-currently.html" target="_blank"&gt;List of SQL Server instances currently installed in your network&lt;/a&gt;", I explained how to get the list of SQL server instances installed in your network.&lt;br /&gt;
Sometimes you might require an SQL Server instance to be not exposed to others due to some security reason. This can be done by using the "Hide" option available for an SQL Server instance.&lt;br /&gt;
&lt;b&gt;Before Hiding an Instance:&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="323" src="http://1.bp.blogspot.com/-L-YKKYQP3cw/TnLFat5bxKI/AAAAAAAAFR0/zwZi2Lhts4g/s640/BeforeHiding.JPG" width="640" /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Steps to Hide an Instance of SQL Server Database Engine&lt;/b&gt;&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Go to "SQL Server Configuration Manager"&lt;/li&gt;
&lt;li&gt;In the Left Pane Expand "SQL Server Network Configuration"&lt;/li&gt;
&lt;li&gt;Now Right Click on "Protocols for &amp;lt;ServerName&amp;gt;" and go to Properties for the server you need to hide.&lt;/li&gt;
&lt;li&gt;In the "Flags" Tab, change the option to "Yes" for "Hide Instance"
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://4.bp.blogspot.com/-mEOkBgYE0Ig/TnLITO41N1I/AAAAAAAAFR4/tdU1NMicYnI/s1600/1.jpg" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Click on "Apply" and "OK"&lt;/li&gt;
&lt;li&gt;Now re-start the SQL Server Service for this Instance and you are done.&amp;nbsp;This instance from now will be hidden.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;b&gt;After Hiding an Instance:&lt;/b&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="322" src="http://2.bp.blogspot.com/-kDMCATbjwS8/TnLJrfYflkI/AAAAAAAAFR8/Ek-VwgbcWIE/s640/AfterHiding.JPG" width="640" /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8555452120075801366?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/K6KveR7QBFSZafFEfoKtj2SEiRk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K6KveR7QBFSZafFEfoKtj2SEiRk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/K6KveR7QBFSZafFEfoKtj2SEiRk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K6KveR7QBFSZafFEfoKtj2SEiRk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/5PTSH3QHzgY" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-16T09:33:12.539+05:30</app:edited><media:thumbnail url="http://1.bp.blogspot.com/-L-YKKYQP3cw/TnLFat5bxKI/AAAAAAAAFR0/zwZi2Lhts4g/s72-c/BeforeHiding.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/09/hide-instance-of-sql-server-database.html</feedburner:origLink></item><item><title>Get last backup details of all databases in a server</title><link>http://feedproxy.google.com/~r/SansSQL/~3/Wkh_ZYtaDew/get-last-backup-details-of-all.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>Backup and Restore</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>SQL Queries</category><category>Backup</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Thu, 01 Sep 2011 20:55:17 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-2161860663344756581</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
This stored procedure give you the information about latest backups happened on all databases in a server.&lt;br /&gt;
This SP works for SQL server 2005 and up.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 650px;"&gt;

&lt;tbody&gt;
&lt;tr&gt;

 &lt;td&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Create&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;Proc&lt;/span&gt; &lt;span style="color: teal;"&gt;sp_BackupDetails&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;AS&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;@BackupDetails&lt;/span&gt; &lt;span style="color: blue;"&gt;table&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: grey; font-family: Consolas; font-size: 9.5pt;"&gt;(&lt;/span&gt;&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Server Name]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Database Name]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Full Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Differential Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Log Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last File or filegroup Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Differential file Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Partial Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: teal; font-family: Consolas; font-size: 9.5pt;"&gt;[Last Differential Partial Backup]&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: grey; font-family: Consolas; font-size: 9.5pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Declare&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt; &lt;span style="color: blue;"&gt;Cursor&lt;/span&gt; &lt;span style="color: blue;"&gt;for&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;name&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Open&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Fetch&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;Next&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; &lt;span style="color: teal;"&gt;@DBName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;While&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: magenta;"&gt;@@fetch_status&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;BEGIN&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; &lt;span style="color: teal;"&gt;@BackupDetails&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;select&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: magenta;"&gt;@@ServerName&lt;/span&gt; &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: teal;"&gt;[Server Name]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: teal;"&gt;SDB&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: teal;"&gt;name&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Database Name]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'D'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Full Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'I'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Differential Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'L'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Log Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'F'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last File or filegroup Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'G'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Differential file Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'P'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Partial Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;,(&lt;/span&gt;&lt;span style="color: blue;"&gt;Select&lt;/span&gt; &lt;span style="color: magenta;"&gt;COALESCE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;20&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;span style="color: magenta;"&gt;MAX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: teal;"&gt;backup_finish_date&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt; 100&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'NA'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;msdb&lt;/span&gt;&lt;span style="color: grey;"&gt;..&lt;/span&gt;&lt;span style="color: teal;"&gt;backupset&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: teal;"&gt;database_name&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'Q'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: teal;"&gt;[Last Differential Partial Backup]&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;from&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: teal;"&gt;SDB&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;where&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;SDB&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: teal;"&gt;name&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: teal;"&gt;@DBName&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Fetch&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;Next&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; &lt;span style="color: teal;"&gt;@DBName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;END&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Close&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;DEALLOCATE&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;DBName&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: teal;"&gt;@BackupDetails&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt; 

&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;u&gt;Usage&lt;/u&gt;&lt;/b&gt;:&lt;/div&gt;
&lt;div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Exec&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: teal;"&gt;sp_BackupDetails&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;b&gt;&lt;u&gt;Results&lt;/u&gt;&lt;/b&gt;:&lt;/o:p&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="116" src="http://1.bp.blogspot.com/-opUOpKnyK2k/TmBS_V7G7HI/AAAAAAAAFRo/2TV3O2SPitU/s640/1.JPG" width="640" /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-2161860663344756581?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iymraBMt1Q4zEmP8Qh4F5WfgHzM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iymraBMt1Q4zEmP8Qh4F5WfgHzM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iymraBMt1Q4zEmP8Qh4F5WfgHzM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iymraBMt1Q4zEmP8Qh4F5WfgHzM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/Wkh_ZYtaDew" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-02T09:25:17.161+05:30</app:edited><media:thumbnail url="http://1.bp.blogspot.com/-opUOpKnyK2k/TmBS_V7G7HI/AAAAAAAAFRo/2TV3O2SPitU/s72-c/1.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.sanssql.com/2011/09/get-last-backup-details-of-all.html</feedburner:origLink></item><item><title>Denali CTP 3 - Show\Hide Results Pane keyboard shortcut not working - Ctrl+R not working</title><link>http://feedproxy.google.com/~r/SansSQL/~3/-JHjQhbvdqE/denali-ctp-3-showhide-results-pane.html</link><category>Denali</category><category>SSMS</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Thu, 01 Sep 2011 11:15:31 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-2393921875172271795</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Recently I installed Denali CTP 3 version and was writing a code which is coming next in this blog. During that time I attempted to hide the results pane using the keyboard shortcut Ctrl+R and was surprised that the keyboard shortcut Ctrl+R was not working. 
When I investigated further I found that that the keyboard shortcut was not assigned to the command "Hide Results Pane".&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/-es0PhgY7pqA/Tl_Dcf6s8JI/AAAAAAAAFRU/b12IDvpkz48/s1600/1.png" /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
To fix this issue or to assign the keyboard shortcut to the command "Hide Results Pane", follow the below steps.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;In a SSMS window, go to "Tools" menu and choose "Options".&lt;/li&gt;
&lt;li&gt;In the left pane of "Options" window, expand "Environment" and then click on "Keyboard".&lt;/li&gt;
&lt;li&gt;In the right pane, Search for the command "Window.ShowResultsPane"&amp;nbsp;Under "Show Commands Containing:" section and select that command&lt;/li&gt;
&lt;li&gt;Now, Under "Shortcuts for selected command:" section choose "SQL Query Editor" from the dropdown list of "Use new shortcut in:" sub-section.&lt;/li&gt;
&lt;li&gt;In the "Press shortcut keys:" sub-section place the cursor and press the keys "Ctrl" followed&amp;nbsp;by "R"&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Click on "Assign" button and click "OK" to exit the "Options" menu and start using the keyboard shortcut "Ctrl+R" to Hide\Show Results Pane.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;img border="0" height="368" src="http://4.bp.blogspot.com/-bkyRMHOOWvk/Tl_I9zANvpI/AAAAAAAAFRg/eRXxYIkvMUI/s640/2.JPG" width="640" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://4.bp.blogspot.com/-S8-xFPXeuqI/Tl_J8jAfwjI/AAAAAAAAFRk/nNhjmwWY2XE/s1600/3.png" /&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-2393921875172271795?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1XM2HyyZeGExXvUxy7Tdziv1lFo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1XM2HyyZeGExXvUxy7Tdziv1lFo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1XM2HyyZeGExXvUxy7Tdziv1lFo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1XM2HyyZeGExXvUxy7Tdziv1lFo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/-JHjQhbvdqE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-01T23:45:31.877+05:30</app:edited><media:thumbnail url="http://3.bp.blogspot.com/-es0PhgY7pqA/Tl_Dcf6s8JI/AAAAAAAAFRU/b12IDvpkz48/s72-c/1.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.sanssql.com/2011/09/denali-ctp-3-showhide-results-pane.html</feedburner:origLink></item><item><title>Looping through SQL Servers using SSIS or Dynamically build connection to multiple SQL Servers</title><link>http://feedproxy.google.com/~r/SansSQL/~3/zcA6mO7vq0E/looping-through-sql-servers-using-ssis.html</link><category>SQL Server 2008</category><category>Business Intelligence</category><category>SSIS</category><category>Downloads</category><category>Automate</category><category>SQL Server 2011</category><category>SQL Server 2005</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Wed, 09 Nov 2011 06:43:28 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-6183824267313582044</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="text-align: left;"&gt;
Consider you are giver a task of gathering information from multiple servers. What are the&amp;nbsp;different&amp;nbsp;ways you can automate this?&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Create linked servers in each server pointing to your central repository&lt;/li&gt;
&lt;li&gt;Create&amp;nbsp;Separate&amp;nbsp;SSIS package in each servers which loads data to your central repository&lt;/li&gt;
&lt;li&gt;Create one SSIS package with multiple data sources and duplicate the tasks for each data source.&lt;/li&gt;
&lt;li&gt;Create one SSIS package which dynamically builds connection to each server and does the data loading tasks.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="text-align: left;"&gt;
If you choose an option between 1 and 3 , then &amp;nbsp;you will have to do some extra work for gathering the server information when there are new servers added to your environment.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
If you choose the 4th option then also you will have some extra work but it is very small and easy when compared to the first 3 options. Here you need to just add the new Server Names to the table and that is all and everything else will be taken care by the SSIS package. &lt;/div&gt;
&lt;div style="text-align: left;"&gt;
In this post I am&amp;nbsp;going&amp;nbsp;to explain how to create a SSIS package which loops through multiple SQL server and gathers information &amp;nbsp;by building the connection to those servers dynamically.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Open “Microsoft Visual Studio”&lt;/li&gt;
&lt;li&gt;Create a new “Integration Services Project”&lt;/li&gt;
&lt;li&gt;Create a SSIS Package&lt;/li&gt;
&lt;li&gt;Create 2 Connection Managers, 1 for the source (which will be set dynamically for each iteration of the loop) &amp;nbsp;and the other for destination (which will remain constant, in other terms your Central Repository)&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://2.bp.blogspot.com/-2XXxr5Q_e3s/TkdQ3gdh_HI/AAAAAAAAFPs/pEBzr1auWys/s1600/1.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Store All your Server Names in a table preferably in the Central Repository (Destination Connection)&lt;/li&gt;
&lt;li&gt;Add 2 variables&lt;/li&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; a.&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Name: ConnectionVariable (A name of your choice)
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Scope: Package&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Type: Object&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Value: System.Object&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; b.&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Name: ServerName &amp;nbsp;(A name of your choice)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Scope: Package&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Type: String&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Value: A Valid Server Name&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/-B_RrFBMM9eE/TkdRtp9r9wI/AAAAAAAAFPw/GzpLS0Is7FQ/s1600/2.png" /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;li&gt;Add an "Execute SQL Task" with SQL Statement like "select FullName from dba..tbl_ListOfServers".&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://2.bp.blogspot.com/-x31GnI0rRQE/Tkta5NvIlGI/AAAAAAAAFQU/n-mElJPlw3s/s1600/11.PNG" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Set the result set to Full Result Set.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/-pV7AJf1SGlI/TkteMGG-jFI/AAAAAAAAFQc/WrJZzUeJwtI/s1600/12.PNG" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;On the Result Set page, Add a Result&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Set Result Name "0" and assign it to your Object variable (In our case it is “ConnectionVariable”). 
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://2.bp.blogspot.com/-ZTTMxckGH9k/TkdSh0iN9TI/AAAAAAAAFP4/xg2yf5X4uw8/s1600/4.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Now add a “Foreach Loop Container”&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Connect it from the “Execute SQL Task”&lt;/li&gt;
&lt;li&gt;Inside the “Foreach Loop Container” , add the required “Data Flow Task”
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://2.bp.blogspot.com/-5BJhkNT3uQI/TkdS_-11woI/AAAAAAAAFP8/8ZOX6-Y8jvw/s1600/5.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Now Right-Click on the “Foreach Loop Container” and click on “Edit”&lt;/li&gt;
&lt;li&gt;Now Go to “Collection” page and Set “Enumerator” to “Foreach ADO Enumerator” and “Enumerator Configuration ” to the Object Variable(In Our Case “ConnectionVariable”) and Set “Enumeration Mode” to “Rows in the First Table”
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://1.bp.blogspot.com/-WPp0CzsF9ik/Tkdfdl-CeII/AAAAAAAAFQA/_H-uLr6YpFg/s1600/6.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Now go to the “Variable Mapping” page and Choose the “String Variable” (In our case it is “ServerName”) and set the Index=0
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/-kwdb2kAW8Vw/TkdgD7jS0iI/AAAAAAAAFQE/IeootWdLfCA/s1600/7.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Now, in the “Data Flow Task” add a “OLE DB Source” (Dynamic Connection) and connect it down to a “OLE DB Destination” (which will be your Central Repository).
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://4.bp.blogspot.com/-thn8ECS_ar4/TkdgfTsAHAI/AAAAAAAAFQI/EXZYB2tEXk8/s1600/8.png" /&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Now Select the Source Connection Manager (In Our Case it is “Source”) and Right-Click on this Source and choose “Properties”.&lt;/li&gt;
&lt;li&gt;Expand the “Expressions” Option and click on the browse button (…)&lt;/li&gt;
&lt;li&gt;Now in the “Property Expression Editor”, Choose the property “ServerName” and click on browse button (…). Now choose the String Variable (in our case “ServerName”) and Drag and Drop this variable into the “Expression” box and click “OK” and “OK”.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://1.bp.blogspot.com/-6IpFWWE7cT0/TkdhSIQAgoI/AAAAAAAAFQM/1P5ziegbLpU/s1600/9.png" /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" src="http://4.bp.blogspot.com/-N3wcNNDgDS8/TkdhkWJpTII/AAAAAAAAFQQ/dYsC0_sE1eI/s1600/10.png" /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
Now when the package runs, the “Execute SQL Task” will read the list of servers and stored in the table you specified and the “Foreach loop” will iterate over each record in that table, running the “Data Flow Task” each time while each time, the ServerName property of the Source Connection in the data flow will get a new value.
&lt;br /&gt;
&lt;br /&gt;
This article is also available in pdf format for downloading.&lt;br /&gt;
Please &lt;a href="https://docs.google.com/viewer?a=v&amp;amp;pid=explorer&amp;amp;chrome=true&amp;amp;srcid=0B2KTftq5oM9HODg0MmM2NDUtOGU5Yi00ZWE1LTliMWMtYWZkOGNhNTU0OGEw&amp;amp;hl=en_US" target="_blank"&gt;Click here&lt;/a&gt; to get your copy.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoListParagraph" style="text-align: left; text-indent: -0.25in;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-6183824267313582044?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0L8VEz4uPrf_FU5r84DblMPgJO8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0L8VEz4uPrf_FU5r84DblMPgJO8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0L8VEz4uPrf_FU5r84DblMPgJO8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0L8VEz4uPrf_FU5r84DblMPgJO8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/zcA6mO7vq0E" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-09T20:13:28.456+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/-2XXxr5Q_e3s/TkdQ3gdh_HI/AAAAAAAAFPs/pEBzr1auWys/s72-c/1.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://www.sanssql.com/2011/08/looping-through-sql-servers-using-ssis.html</feedburner:origLink></item><item><title>Finding space usage of database files</title><link>http://feedproxy.google.com/~r/SansSQL/~3/uF51zgRqUFY/finding-space-usage-of-database-files.html</link><category>Space Usage</category><category>Database Files</category><category>Automate</category><category>SQL Queries</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sun, 07 Aug 2011 06:12:38 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-4431266662889309371</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
DBA's are required to watch the space usage of database files in order to take preventive measures of future failures with respect to database full issues.&lt;br /&gt;
This will be usually required when there is a bulk activity happening on a database.&lt;br /&gt;
To do this make use of the below stored procedure.&lt;br /&gt;
Create this SP in a database and execute it in regular intervals to get the latest status of the database files.&lt;br /&gt;
This can be used to view the space usage of all the database files or for a particular threshold value.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 600px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Use&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;master&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Create&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;proc&lt;/span&gt; sp_SpaceUsageReport&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;@Threshold &lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;80&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;as&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; tempdb&lt;span style="color: grey;"&gt;..&lt;/span&gt;SpaceUsage&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; DatabaseName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;LogicalFileName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;FileType &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;PhysicalFileLocation &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;[FileSize (MB)] &lt;span style="color: blue;"&gt;float&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;[SpaceUsed (MB)] &lt;span style="color: blue;"&gt;float&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;[FreeSpace (MB)] &lt;span style="color: blue;"&gt;float&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;[% Used] &lt;span style="color: blue;"&gt;AS&lt;/span&gt; 100&lt;span style="color: grey;"&gt;-((&lt;/span&gt;[FileSize (MB)]&lt;span style="color: grey;"&gt;-&lt;/span&gt;[SpaceUsed (MB)]&lt;span style="color: grey;"&gt;)/&lt;/span&gt;[FileSize (MB)]&lt;span style="color: grey;"&gt;)*(&lt;/span&gt;100&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: grey;"&gt;,&lt;/span&gt;[% Free]&amp;nbsp; &lt;span style="color: blue;"&gt;AS &lt;/span&gt;&lt;span style="color: grey;"&gt;((&lt;/span&gt;[FileSize (MB)]&lt;span style="color: grey;"&gt;-&lt;/span&gt;[SpaceUsed (MB)]&lt;span style="color: grey;"&gt;)/&lt;/span&gt;[FileSize (MB)]&lt;span style="color: grey;"&gt;)*(&lt;/span&gt;100&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;If &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;varchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;),(&lt;/span&gt;&lt;span style="color: magenta;"&gt;SERVERPROPERTY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'ProductVersion'&lt;/span&gt;&lt;span style="color: grey;"&gt;))))&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; 8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXEC&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;sp_MSforeachdb&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;'USE [?];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT INTO tempdb..SpaceUsage(DatabaseName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,LogicalFileName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,FileType&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,PhysicalFileLocation&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[FileSize (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SpaceUsed (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[FreeSpace (MB)])&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT DB_NAME() AS DatabaseName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,name AS LogicalFileName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,FileType = CASE WHEN FILEPROPERTY(name,''IsLogFile'')=0 THEN ''Data File'' WHEN FILEPROPERTY(name,''IsLogFile'')=1 THEN ''Log File'' END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,filename AS PhysicalFileLocation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND(size/128.000,2)) AS [FileSize (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND(FILEPROPERTY(name,''SpaceUsed'')/128.000,2)) AS [SpaceUsed (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND((size-FILEPROPERTY(name,''SpaceUsed''))/128.000,2)) AS [FreeSpace (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;FROM dbo.sysfiles &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;ORDER BY FileType '&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;If &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;varchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;),(&lt;/span&gt;&lt;span style="color: magenta;"&gt;SERVERPROPERTY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'ProductVersion'&lt;/span&gt;&lt;span style="color: grey;"&gt;))))&amp;lt;&amp;gt;&lt;/span&gt; 8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXEC&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;sp_MSforeachdb&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;'USE [?];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT INTO tempdb..SpaceUsage(DatabaseName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,LogicalFileName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,FileType&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,PhysicalFileLocation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[FileSize (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[SpaceUsed (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,[FreeSpace (MB)])&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT DB_NAME() AS DatabaseName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,name AS LogicalFileName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,FileType = CASE WHEN type_desc =''Rows'' THEN ''Data File'' WHEN type_desc =''LOG'' THEN ''Log File'' END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,physical_name AS PhysicalFileLocation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND(size/128.000,2)) AS [FileSize (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND(FILEPROPERTY(name,''SpaceUsed'')/128.000,2)) AS [SpaceUsed (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,CONVERT(float,ROUND((size-FILEPROPERTY(name,''SpaceUsed''))/128.000,2)) AS [FreeSpace (MB)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;FROM sys.database_files&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;ORDER BY FileType'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;if &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;COUNT&lt;/span&gt;&lt;span style="color: grey;"&gt;(*)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; tempdb&lt;span style="color: grey;"&gt;..&lt;/span&gt;SpaceUsage &lt;span style="color: blue;"&gt;where&lt;/span&gt; [% Used]&lt;span style="color: grey;"&gt;&amp;gt;&lt;/span&gt;@Threshold&lt;span style="color: grey;"&gt;)&amp;gt;&lt;/span&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;/* -- Enable this Content if you want to send email.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE @table&amp;nbsp; NVARCHAR(MAX),@Subject Nvarchar(500) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;Set @Subject='[SQLAlert] Database Files Space Threshold exceeded Report from ' + CAST(@@SERVERNAME as nvarchar)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;SET @table =&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;H1&amp;gt;Threshold Value for this Report is '+CAST(@Threshold AS nvarchar)+' Percentage. &amp;lt;/H1&amp;gt;' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;table border="1"&amp;gt;' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;DatabaseName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;FileType&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;PhysicalFileLocation&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;FileSize (MB)&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;% Used&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt; ' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAST ( ( Select td=DatabaseName, '',td=FileType, '',td=PhysicalFileLocation,'',td=CAST([FileSize (MB)] as nvarchar),'',td=CAST([% Used] AS nvarchar) from tempdb..SpaceUsage where [% Used]&amp;gt;@Threshold&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOR XML PATH('tr'), TYPE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS NVARCHAR(MAX) )&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;/table&amp;gt;' ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;EXEC msdb.dbo.sp_send_dbmail @profile_name='DatabaseMail', --Change to your Profile Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @recipients='sandeshsegu@SansSQL.com', --Put the email address of those who want to receive the e-mail&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @subject = @Subject,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @body = @table,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @body_format = 'HTML' ;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;*/&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt;&amp;nbsp; tempdb&lt;span style="color: grey;"&gt;..&lt;/span&gt;SpaceUsage &lt;span style="color: blue;"&gt;where&lt;/span&gt; [% Used]&lt;span style="color: grey;"&gt;&amp;gt;&lt;/span&gt;@Threshold&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;End&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; tempdb&lt;span style="color: grey;"&gt;..&lt;/span&gt;SpaceUsage&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
To send an email of this report you need to&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Configure Database Mail option. To configure Database mail option, follow &lt;a href="http://www.sanssql.com/2011/01/configuring-database-mail.html" target="_blank"&gt;this post&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Uncomment the below content in the SP.&lt;/li&gt;
&lt;/ol&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 600px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span class="Apple-style-span" style="color: green; font-family: 'Courier New'; font-size: 13px;"&gt;/* -- Enable this Content if you want to send email.&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE @table&amp;nbsp; NVARCHAR(MAX),@Subject Nvarchar(500) ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;Set @Subject='[SQLAlert] Database Files Space Threshold exceeded Report from ' + CAST(@@SERVERNAME as nvarchar)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;SET @table =&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;H1&amp;gt;Threshold Value for this Report is '+CAST(@Threshold AS nvarchar)+' Percentage. &amp;lt;/H1&amp;gt;' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;table border="1"&amp;gt;' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;DatabaseName&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;FileType&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;PhysicalFileLocation&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;FileSize (MB)&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;% Used&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt; ' +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAST ( ( Select td=DatabaseName, '',td=FileType, '',td=PhysicalFileLocation,'',td=CAST([FileSize (MB)] as nvarchar),'',td=CAST([% Used] AS nvarchar) from tempdb..SpaceUsage where [% Used]&amp;gt;@Threshold&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOR XML PATH('tr'), TYPE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS NVARCHAR(MAX) )&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; N'&amp;lt;/table&amp;gt;' ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;EXEC msdb.dbo.sp_send_dbmail @profile_name='DatabaseMail', --Change to your Profile Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @recipients='sandeshsegu@SansSQL.com', --Put the email address of those who want to receive the e-mail&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @subject = @Subject,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @body = @table,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @body_format = 'HTML' ;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;*/&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
Usage of this SP:&lt;br /&gt;
This SP expects a parameter called @Threshold&lt;br /&gt;
If you specify the&amp;nbsp;@Threshold=0 then, this SP will give space usage details of all the database files.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 600px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Exec&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; sp_SpaceUsageReport&lt;span style="color: blue;"&gt; &lt;/span&gt;@Threshold&lt;span style="color: grey;"&gt;=&lt;/span&gt;0&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
If you specify the&amp;nbsp;@Threshold=80 then, this SP will give space usage details of those database files which exceeds the threshold 80 percent.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 600px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Exec&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; sp_SpaceUsageReport&lt;span style="color: blue;"&gt; &lt;/span&gt;@Threshold&lt;span style="color: grey;"&gt;=&lt;/span&gt;80&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-4431266662889309371?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zY4TD_W4W-Ty_zyEhIudyJ3_QSU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zY4TD_W4W-Ty_zyEhIudyJ3_QSU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zY4TD_W4W-Ty_zyEhIudyJ3_QSU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zY4TD_W4W-Ty_zyEhIudyJ3_QSU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/uF51zgRqUFY" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-07T18:42:38.798+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/08/finding-space-usage-of-database-files.html</feedburner:origLink></item><item><title>T-SQL Query to find the list of Indexed Views in a Database</title><link>http://feedproxy.google.com/~r/SansSQL/~3/nQHZ1q5kfSE/t-sql-query-to-find-list-of-indexed.html</link><category>SQL Queries</category><category>Indexes</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sun, 24 Jul 2011 01:52:53 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8042230978213354809</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Here is the query which can be used for getting the list of Indexed views in a Database.&lt;br /&gt;
&lt;blockquote&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;USE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: grey;"&gt;&amp;lt;&lt;/span&gt;DatabaseName&lt;span style="color: grey;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;objects&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;
&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt;WHERE&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-no-proof: yes;"&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'V'&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;span style="color: grey; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; line-height: 115%; mso-no-proof: yes;"&gt;and&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; line-height: 115%; mso-no-proof: yes;"&gt; &lt;span style="color: magenta;"&gt;OBJECTPROPERTY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;object_id&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'IsIndexed'&lt;/span&gt;&lt;span style="color: grey;"&gt;)=&lt;/span&gt;1&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
&lt;div class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8042230978213354809?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8g1n4KPaJZMemsPtH7x1w6OVK88/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8g1n4KPaJZMemsPtH7x1w6OVK88/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8g1n4KPaJZMemsPtH7x1w6OVK88/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8g1n4KPaJZMemsPtH7x1w6OVK88/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/nQHZ1q5kfSE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-24T14:22:53.028+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/07/t-sql-query-to-find-list-of-indexed.html</feedburner:origLink></item><item><title>SQL Server Migration Checklist</title><link>http://feedproxy.google.com/~r/SansSQL/~3/O2B-fND8OGE/sql-server-migration-checklist.html</link><category>Checklist</category><category>SQL Server Migration</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Thu, 09 Jun 2011 09:27:10 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-7705077437961295232</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Are you migrating your SQL Servers?&lt;br /&gt;
Here is a quick checklist for your SQL Server Migration.&lt;br /&gt;
&lt;div style="text-align: left;"&gt;&lt;/div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Build your New&amp;nbsp;Server, Install SQL Server and required updates and keep the server ready for migration&lt;/li&gt;
&lt;li&gt;Stop Application Service(s).&lt;br /&gt;
This is to ensure that the no applications are connected to the Databases during the migration process.&lt;/li&gt;
&lt;li&gt;Change&amp;nbsp;the Properties of the databases&amp;nbsp;that are part of Migration&amp;nbsp;to "Read-only".&lt;br /&gt;
This is to ensure that the data modification is not&amp;nbsp;happening&amp;nbsp;by any other sources.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Take a FULL backup of all the User databases that are involved in the&amp;nbsp;Migration&amp;nbsp;Process.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Move the backups to the destination server or a Shared location, then restore them to the appropriate drives on the destination.&lt;/li&gt;
&lt;li&gt;Change the compatibility level of the databases (Optional)&lt;br /&gt;
Do this if the applications connecting to these databases are independent of the database compatibility level.&lt;/li&gt;
&lt;li&gt;Transfer logins using SSIS (Transfer Logins Task) or using "sp_help_revlogin"&lt;br /&gt;
More information about sp_help_revlogin is at&amp;nbsp;&lt;span style="color: black; font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;a href="http://support.microsoft.com/kb/246133" target="_blank"&gt;http://support.microsoft.com/kb/246133&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Check for Orphaned Users in the databases and Fix them (if Any)&lt;/li&gt;
&lt;li&gt;Update&amp;nbsp;Usage&amp;nbsp;on the migrated Databases&lt;/li&gt;
&lt;li&gt;Update&amp;nbsp;Stats on the migrated Databases&lt;/li&gt;
&lt;li&gt;Re-Index or Re-Organize Indexes on the migrated Databases&lt;/li&gt;
&lt;li&gt;Transfer Jobs using SSIS or manually create them&lt;/li&gt;
&lt;li&gt;Build Maintenance plans (if Any)&lt;/li&gt;
&lt;li&gt;Recompile database objects if required&lt;/li&gt;
&lt;li&gt;Move or rebuild SSIS or DTS packages (if Any)&lt;/li&gt;
&lt;li&gt;Create Alerts and Operators (if Any)&lt;/li&gt;
&lt;li&gt;Setup High Availability Options (if Any Like Replication, LogShipping, Mirroring)&lt;/li&gt;
&lt;li&gt;Test the High&amp;nbsp;Availability&amp;nbsp;options that were setup in the previous step&lt;/li&gt;
&lt;li&gt;Point the Application(s) to new Server and start the Application Service(s)&lt;/li&gt;
&lt;li&gt;Test the Application(s)&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-7705077437961295232?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6uhm1HrKUR_dtceIUztf-X_sNTQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6uhm1HrKUR_dtceIUztf-X_sNTQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6uhm1HrKUR_dtceIUztf-X_sNTQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6uhm1HrKUR_dtceIUztf-X_sNTQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/O2B-fND8OGE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-09T21:57:10.110+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/06/sql-server-migration-checklist.html</feedburner:origLink></item><item><title>SQL Server 2008 Service fails to start after Service Pack Installation</title><link>http://feedproxy.google.com/~r/SansSQL/~3/BxzS6mjTjb8/sql-server-2008-service-fails-to-start.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>Service Pack</category><category>Undocumented</category><category>Troubleshooting</category><category>SQL Server 2011</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Tue, 07 Jun 2011 07:45:20 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-5937234814175150623</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Some times you may find that the SQL Server Service is not starting after applying a service pack and when you check in the Event Viewer you find the below message.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Script level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql' encountered error 598, state 1, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;SQL Server Setup creates a database with the data file name temp_MS_AgentSigningCertificate_Database.mdf during the installation process and if the SQL Server setup is not able to create that database in the default data path then the above error is returned as it is not able to find the path.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;To fix this issue.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Go to Registry editor, To open this, go to "Run" and type "regedit" and click "ok"&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;First go to this path and make sure that the path in the key SQLDataRoot exists. If not then give a valid path to this key.&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span style="color: black;"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL&lt;/span&gt;&lt;span style="color: #1f497d;"&gt;10&lt;/span&gt;&lt;span style="color: black;"&gt;.&lt;instance name=""&gt;&amp;lt;instance name&amp;gt;\Setup&lt;/instance&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span style="color: black;"&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span"&gt;Then go to this path and&amp;nbsp;make sure that the path in&amp;nbsp;&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span style="color: black;"&gt;&lt;span class="Apple-style-span"&gt;the keys&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;"BackupDirectory", "DefaultData" and "DefaultLog"&amp;nbsp;exists.&amp;nbsp;If not then give a valid path to these keys.&lt;/span&gt;&lt;br /&gt;
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.&amp;lt;instance name&amp;gt;\MSSQLServer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Now you should be able to start the SQL Server Service without any issues.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Once the Service is started, verify the SQL Server, databases and others to make sure everything is fine.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Also verify if the Service pack or the CU is installed correctly.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-5937234814175150623?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FFEd3qrfZPyUd0ABFLoDX2XmoSY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FFEd3qrfZPyUd0ABFLoDX2XmoSY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FFEd3qrfZPyUd0ABFLoDX2XmoSY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FFEd3qrfZPyUd0ABFLoDX2XmoSY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/BxzS6mjTjb8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-07T20:15:20.531+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.sanssql.com/2011/06/sql-server-2008-service-fails-to-start.html</feedburner:origLink></item><item><title>Unable to start mail session (reason: No mail profile defined) - Message in Error Log</title><link>http://feedproxy.google.com/~r/SansSQL/~3/w7kua7HZxhY/unable-to-start-mail-session-reason-no.html</link><category>SQL Server 2008</category><category>Mail Session</category><category>SQL Server Agent</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>Database Mail</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Tue, 31 May 2011 20:41:31 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8565245042678680643</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There will be many different messages that will be logged in the Error Log of SQL Server. Among them you might also find the below message some times.&lt;br /&gt;
&lt;div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 500px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;Date&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;6/1/2011 8:18:27 AM&lt;br /&gt;
Log&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;SQL Server Agent (Archive #2 - 6/1/2011 8:18:00 AM)&lt;br /&gt;
&lt;br /&gt;
Message&lt;br /&gt;
[098] SQLServerAgent terminated (normally)&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;This is the most common&amp;nbsp;message&amp;nbsp;that will be logged when there is no "Mail Session" defined for the SQL Server Agent Alert System.&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;To Fix this or to make this message&amp;nbsp;disappear in the Error Log, you have to enable "Mail Session" and re-start the SQL Server Agent.&lt;/div&gt;&lt;div&gt;To Do this,&lt;/div&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Connect to the Server&lt;/li&gt;
&lt;li&gt;Right Click on the "SQL Server Agent" and go to "Properties" &amp;nbsp;&lt;/li&gt;
&lt;li&gt;Then Go to "Alert System" Tab&lt;/li&gt;
&lt;li&gt;Make sure the check box "Enable Mail&amp;nbsp;Profile" is checked&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Click OK to exit&lt;/li&gt;
&lt;li&gt;Re-start the SQL Server Agent Service&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" height="574" src="http://4.bp.blogspot.com/-w7JzUFlN6RQ/TeWxuGNNo4I/AAAAAAAAFAU/lTBcwt71cKU/s640/Mail+Session.png" width="640" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now if you again look into the Error Log you will not find this message anymore after re-starting the Agent Service. &amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8565245042678680643?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zt3jOaqfyYzkl1wzbEQBNvzW4D8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zt3jOaqfyYzkl1wzbEQBNvzW4D8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zt3jOaqfyYzkl1wzbEQBNvzW4D8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zt3jOaqfyYzkl1wzbEQBNvzW4D8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/w7kua7HZxhY" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-01T09:11:31.978+05:30</app:edited><media:thumbnail url="http://4.bp.blogspot.com/-w7JzUFlN6RQ/TeWxuGNNo4I/AAAAAAAAFAU/lTBcwt71cKU/s72-c/Mail+Session.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/06/unable-to-start-mail-session-reason-no.html</feedburner:origLink></item><item><title>SQL Server 2011 - Zoom Query Window and Results pane - New Feature</title><link>http://feedproxy.google.com/~r/SansSQL/~3/qnsXOQqKqD4/sql-server-2011-zoom-query-window-and.html</link><category>Denali</category><category>SQL Server 2011</category><category>What's New</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Mon, 18 Apr 2011 20:03:49 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-7827076026131799824</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;SQL Server 2011 comes with lots of new features and here is one such new feature.&lt;br /&gt;
SQL Server 2011 has introduced zooming of Query window and results pane.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-4cVL5CcYdwc/Taz5yRPenMI/AAAAAAAAE_c/4hWFuM_ghKI/s1600/Query+window+Normal.png" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Query Window - Normal&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;br /&gt;
&lt;img border="0" src="http://3.bp.blogspot.com/--Q-QFobuiM0/Taz55pxa3VI/AAAAAAAAE_g/2nqxGOKrQ5Q/s1600/Query+window+Zoomed.png" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Query Window - Zoomed&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-7J1JuOeYw5w/Taz6QRmHgZI/AAAAAAAAE_k/r4xXLamhkWc/s1600/Results+Pane+Normal.png" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Results Pane - Normal&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-tg2Wgm6oBSg/Taz6YnndltI/AAAAAAAAE_o/duORrGO2x5w/s1600/Results+Pane+Zoomed.png" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Results Pane - Zoomed&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-7827076026131799824?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zV9PY7Ocm1ckYr1K7eCS1UEQiq8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zV9PY7Ocm1ckYr1K7eCS1UEQiq8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zV9PY7Ocm1ckYr1K7eCS1UEQiq8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zV9PY7Ocm1ckYr1K7eCS1UEQiq8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/qnsXOQqKqD4" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-19T08:33:49.403+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/-4cVL5CcYdwc/Taz5yRPenMI/AAAAAAAAE_c/4hWFuM_ghKI/s72-c/Query+window+Normal.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/04/sql-server-2011-zoom-query-window-and.html</feedburner:origLink></item><item><title>T-SQL Query to find the SQL Server Protocols Status</title><link>http://feedproxy.google.com/~r/SansSQL/~3/75ws_BkMcHI/t-sql-query-to-find-sql-server.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>SQL Server Protocols</category><category>Downloads</category><category>SQLExpress</category><category>Automate</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>SQLCMD</category><category>SQL Queries</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Thu, 07 Apr 2011 07:39:47 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-1552933703002376454</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Here is a T-SQL Query that I have developed to get the status of the SQL Server Protocols.&lt;br /&gt;
This query reads data from the registry.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @InstanceName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @value &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @value_Out &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey_InstanceName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;500&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @InstanceName&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;nVARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: magenta;"&gt;isnull&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;SERVERPROPERTY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'INSTANCENAME'&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: grey;"&gt;&lt;/span&gt;&lt;span style="color: red;"&gt;'MSSQLSERVER'&lt;/span&gt;&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #SQLServerProtocols&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;ProtocolName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;25&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;Value &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;Data &lt;span style="color: blue;"&gt;bit&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;if&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;Convert&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;varchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;),(&lt;/span&gt;&lt;span style="color: magenta;"&gt;SERVERPROPERTY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'ProductVersion'&lt;/span&gt;&lt;span style="color: grey;"&gt;))))&amp;lt;&amp;gt;&lt;/span&gt;8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey_InstanceName&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey_InstanceName&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; @InstanceName&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value &lt;span style="color: grey;"&gt;=&lt;/span&gt; @value &lt;span style="color: blue;"&gt;OUTPUT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server\'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@value&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'\MSSQLServer\SuperSocketNetLib\Sm'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; #SQLServerProtocols&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;Value&lt;span style="color: grey;"&gt;,&lt;/span&gt;Data&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'Enabled'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'DisplayName'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value &lt;span style="color: grey;"&gt;=&lt;/span&gt; @value_Out &lt;span style="color: blue;"&gt;OUTPUT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;UPDATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; #SQLServerProtocols &lt;span style="color: blue;"&gt;set&lt;/span&gt; ProtocolName&lt;span style="color: grey;"&gt;=&lt;/span&gt;@value_Out&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt; ProtocolName &lt;span style="color: grey;"&gt;is&lt;/span&gt; &lt;span style="color: grey;"&gt;null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server\'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@value&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'\MSSQLServer\SuperSocketNetLib\Np'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; #SQLServerProtocols&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;Value&lt;span style="color: grey;"&gt;,&lt;/span&gt;Data&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'Enabled'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'DisplayName'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value &lt;span style="color: grey;"&gt;=&lt;/span&gt; @value_Out &lt;span style="color: blue;"&gt;OUTPUT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;UPDATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; #SQLServerProtocols &lt;span style="color: blue;"&gt;set&lt;/span&gt; ProtocolName&lt;span style="color: grey;"&gt;=&lt;/span&gt;@value_Out&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt; ProtocolName &lt;span style="color: grey;"&gt;is&lt;/span&gt; &lt;span style="color: grey;"&gt;null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server\'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@value&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'\MSSQLServer\SuperSocketNetLib\TCP'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; #SQLServerProtocols&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;Value&lt;span style="color: grey;"&gt;,&lt;/span&gt;Data&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'Enabled'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'DisplayName'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value &lt;span style="color: grey;"&gt;=&lt;/span&gt; @value_Out &lt;span style="color: blue;"&gt;OUTPUT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;UPDATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; #SQLServerProtocols &lt;span style="color: blue;"&gt;set&lt;/span&gt; ProtocolName&lt;span style="color: grey;"&gt;=&lt;/span&gt;@value_Out&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt; ProtocolName &lt;span style="color: grey;"&gt;is&lt;/span&gt; &lt;span style="color: grey;"&gt;null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @RegKey&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server\'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@value&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'\MSSQLServer\SuperSocketNetLib\Via'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; #SQLServerProtocols&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;Value&lt;span style="color: grey;"&gt;,&lt;/span&gt;Data&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'Enabled'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; @RegKey&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'DisplayName'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value &lt;span style="color: grey;"&gt;=&lt;/span&gt; @value_Out &lt;span style="color: blue;"&gt;OUTPUT&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;UPDATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; #SQLServerProtocols &lt;span style="color: blue;"&gt;set&lt;/span&gt; ProtocolName&lt;span style="color: grey;"&gt;=&lt;/span&gt;@value_Out&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;where&lt;/span&gt; ProtocolName &lt;span style="color: grey;"&gt;is&lt;/span&gt; &lt;span style="color: grey;"&gt;null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; ProtocolName&lt;span style="color: grey;"&gt;,&lt;/span&gt; IsEnabled&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;CASE&lt;/span&gt; &lt;span style="color: blue;"&gt;WHEN&lt;/span&gt; Data&lt;span style="color: grey;"&gt;=&lt;/span&gt;1 &lt;span style="color: blue;"&gt;THEN&lt;/span&gt; &lt;span style="color: red;"&gt;'Enabled'&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;ELSE&lt;/span&gt; &lt;span style="color: red;"&gt;'Disabled'&lt;/span&gt; &lt;span style="color: blue;"&gt;END&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; #SQLServerProtocols&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #SQLServerProtocols&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div&gt;Download this script from &lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HNGUzOTRjODEtMmU2MS00ZmMyLWI1YjQtNWIyZDVhODczOTQ1&amp;amp;hl=en&amp;amp;authkey=COGQw7IK" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-1552933703002376454?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/40GvWxmN6vnnCYPooscuAtD5wDo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/40GvWxmN6vnnCYPooscuAtD5wDo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/40GvWxmN6vnnCYPooscuAtD5wDo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/40GvWxmN6vnnCYPooscuAtD5wDo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/75ws_BkMcHI" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-07T20:09:47.062+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/04/t-sql-query-to-find-sql-server.html</feedburner:origLink></item><item><title>Page Level Restoration</title><link>http://feedproxy.google.com/~r/SansSQL/~3/l6pdCRK8LoY/page-level-restoration.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>Page Level Restore</category><category>Backup and Restore</category><category>SQLExpress</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>SQL Queries</category><category>Backup</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sat, 26 Mar 2011 02:22:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-5060090829511001557</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Sometimes you might come across a situation where a particular Page of a SQL Server database gets corrupted due to various reasons. In such cases only that corrupted page can be&amp;nbsp;recovered&amp;nbsp;using a backup.&lt;br /&gt;
To explain how to recover a page from the backup, I will first need to corrupt a page on a database.&lt;br /&gt;
By using the below method I am going to simulate the page corruption and then recover using the backup taken before corruption.&lt;br /&gt;
First I am going to create a database by name "TestPageLevelRestore" and Set its recovery Model to FULL.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;master&lt;/span&gt;&lt;span style="color: grey;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;ON&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; NAME &lt;span style="color: grey;"&gt;=&lt;/span&gt; TestPageLevelRestore&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;FILENAME&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'D:\TestPageLevelRestore.mdf'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIZE &lt;span style="color: grey;"&gt;=&lt;/span&gt; 10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: magenta; font-family: 'Courier New'; font-size: 10pt;"&gt;LOG&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; NAME &lt;span style="color: grey;"&gt;=&lt;/span&gt; TestPageLevelRestore_log&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;FILENAME&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'D:\TestPageLevelRestore_log.ldf'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIZE &lt;span style="color: grey;"&gt;=&lt;/span&gt; 5MB&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: red;"&gt;'Database TestPageLevelRestore Created'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;ALTER&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;SET&lt;/span&gt; &lt;span style="color: blue;"&gt;RECOVERY&lt;/span&gt; &lt;span style="color: blue;"&gt;FULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: red;"&gt;'Recovery Model of database TestPageLevelRestore has been changed to FULL'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-ms59qKjJOzo/TY2UTshqMHI/AAAAAAAAE9k/ht0M9HFrwkE/s1600/1.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Now Create a table and insert data into that table.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Use&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; TestPageLevelRestore&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; [Shift]&lt;span style="color: grey;"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ShiftID] &lt;span style="color: blue;"&gt;tinyint&lt;/span&gt; &lt;span style="color: blue;"&gt;IDENTITY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Name] &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [StartTime] &lt;span style="color: blue;"&gt;datetime&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [EndTime] &lt;span style="color: blue;"&gt;datetime&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ModifiedDate] &lt;span style="color: blue;"&gt;datetime&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;CONSTRAINT&lt;/span&gt; [PK_Shift_ShiftID] &lt;span style="color: blue;"&gt;PRIMARY&lt;/span&gt; &lt;span style="color: blue;"&gt;KEY&lt;/span&gt; &lt;span style="color: blue;"&gt;CLUSTERED &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;[ShiftID] &lt;span style="color: blue;"&gt;ASC&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: red;"&gt;'Creation of Table "Shift" Completed'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;IDENTITY_INSERT&lt;/span&gt; [Shift] &lt;span style="color: blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; [Shift]&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;[ShiftID]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [Name]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [StartTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [EndTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [ModifiedDate]&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;N'Day'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 07:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 15:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1998-06-01 00:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; [Shift]&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;[ShiftID]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [Name]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [StartTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [EndTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [ModifiedDate]&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;2&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;N'Evening'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 15:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 23:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1998-06-01 00:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; [Shift]&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;[ShiftID]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [Name]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [StartTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [EndTime]&lt;span style="color: grey;"&gt;,&lt;/span&gt; [ModifiedDate]&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;3&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;N'Night'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 23:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1900-01-01 07:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'1998-06-01 00:00:00.000'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;IDENTITY_INSERT&lt;/span&gt; [Shift] &lt;span style="color: blue;"&gt;OFF&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: red;"&gt;'Data Insertion to table "Shift" Completed'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh5.googleusercontent.com/-t-4-FPDHCTI/TY2U611cy6I/AAAAAAAAE9o/kUp-KP_Vfz8/s1600/2.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Now take a FULL backup of the database&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;BACKUP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;TO&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'D:\TestPageLevelRestore_FullBackup.bak'&lt;/span&gt; &lt;span style="color: blue;"&gt;WITH&lt;/span&gt; &lt;span style="color: green;"&gt;STATS&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;10&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: red;"&gt;'Full Backup Completed'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-eQ9d1ZQtpk0/TY2W_0mVGaI/AAAAAAAAE90/LOQTX69rQOE/s1600/3.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
After the backup is completed, get the list of index ID's from which you can choose one to corrupt&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="color: green; line-height: 14px;"&gt;--To get the list of index ID's from which you can choose one to corrupt&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="color: green; line-height: 14px;"&gt;&lt;/span&gt;Use&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; TestPageLevelRestore&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;indexes&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: magenta;"&gt;OBJECT_NAME&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;object_id&lt;/span&gt;&lt;span style="color: grey;"&gt;)=&lt;/span&gt;&lt;span style="color: red;"&gt;'Shift'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-t4uLRIpGAqs/TY2Xy-hFIRI/AAAAAAAAE94/BRSKeKYXoYY/s1600/4.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Now get the list of pages in that index.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="color: green; font-family: 'Courier New'; font-size: 13px;"&gt;--To get the list of pages&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;DBCC&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; IND&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'TestPageLevelRestore'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'Shift'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-cGzWCpLa1FM/TY2ZQhvbNRI/AAAAAAAAE-A/2Rvf0nmujU8/s1600/5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-cGzWCpLa1FM/TY2ZQhvbNRI/AAAAAAAAE-A/2Rvf0nmujU8/s1600/5.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now you can get the page level details using the below query&lt;/div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="color: green; font-family: 'Courier New'; font-size: 13px;"&gt;-- To display the contents&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DBCC&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; TRACEON&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;3604&lt;span style="color: grey;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;--TO get the page level data details&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;DBCC&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; PAGE&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'TestPageLevelRestore'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;,&lt;/span&gt;147&lt;span style="color: grey;"&gt;,&lt;/span&gt;3&lt;span style="color: grey;"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh4.googleusercontent.com/-v7LlZ_5q5vY/TY2Z4L8KuUI/AAAAAAAAE-E/SC9AMHKcGAM/s1600/6.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
For corrupting a particular page using a hex editor, you need to get the offset value, to obtain the offset value of a page simply multiply the PageID with 8192&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="color: green; font-family: 'Courier New'; font-size: 13px;"&gt;--Get the Offset Value. This can be obtained by multiplying the page ID with 8192.&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 10pt;"&gt;--Once you get the result copy the result and set the database to offline&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; 147&lt;span style="color: grey;"&gt;*&lt;/span&gt;8192 &lt;span style="color: blue;"&gt;AS&lt;/span&gt; [OffSetValue]&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-4_gzJziGrwQ/TY2a4WrAzqI/AAAAAAAAE-I/jOo5QTQQklQ/s1600/7.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
Once you get the offset Value, just copy it and take the database Offline.&lt;/div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;MASTER&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;ALTER&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;SET&lt;/span&gt; &lt;span style="color: blue;"&gt;OFFLINE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: red;"&gt;'Database TestPageLevelRestore is set to Offline. Now Open the TestPageLevelRestore.mdf file in the hex editor and press ctrl+g to go the page where the index data is located. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;Choose Decimal and paste the offset value. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;once you go to the location, then manuplate the value and save the file and exit hex editor. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;After manuplating data bring database online.'&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-R92jL5KrqZI/TY2bsPR9bKI/AAAAAAAAE-Q/W3rgMLgwyqY/s1600/8.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Now Open the data file of the database "TestPageLevelRestore.mdf" file in the hex editor and press ctrl+g to go the page where the index data is located.&lt;br /&gt;
&lt;br /&gt;
Then choose Decimal option and paste the offset value.&lt;br /&gt;
Once you go to the location, then manuplate the value and save the file and exit hex editor.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh5.googleusercontent.com/-kiyIInbT2kk/TY2dIgN9crI/AAAAAAAAE-U/pzCtmrar-sE/s1600/9.PNG" /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-FExMWg-qhIg/TY2dlOO1UGI/AAAAAAAAE-Y/OIkgkmwdbAY/s1600/10.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
You can now see that I have edited the page and saved the file.&lt;br /&gt;
&lt;img border="0" src="https://lh4.googleusercontent.com/-hlftJVnwNrk/TY2ePSQB2zI/AAAAAAAAE-c/_lgcoblSfDY/s1600/11.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
Once you edit the file and saved it, exit the Hex Editor and bring back the database to Online state.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;MASTER&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;ALTER&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;SET&lt;/span&gt; &lt;span style="color: blue;"&gt;ONLINE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: red;"&gt;'Database TestPageLevelRestore is set to Online'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-MhfyFpeRmys/TY2euQa4hLI/AAAAAAAAE-g/nxmtD9N5vuI/s1600/12.PNG" /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now try to read data from the table and you will get error&amp;nbsp;which states that the read failed at page (x:xxxx)&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span class="Apple-style-span" style="color: green; font-family: 'Courier New'; font-size: 13px;"&gt;--Select the data and you will get error stating that the read failed at page (x:xxxx)&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; TestPageLevelRestore&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; shift&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;master_files&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; &lt;span style="color: magenta;"&gt;DB_NAME&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;)=&lt;/span&gt;&lt;span style="color: red;"&gt;'TestPageLevelRestore'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-rVbe6og5rXg/TY2fj5Vd_BI/AAAAAAAAE-k/MlukVloxRm4/s1600/13.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
So this means that the page is now corrupted. By this the simulation of page&amp;nbsp;corruption&amp;nbsp;is completed.&lt;br /&gt;
Now we need to start looking on how to recover the page using page level restore.&lt;br /&gt;
Before we start the recovery process, we need to backup the tail of the log.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;master&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;BACKUP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;LOG&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;TO&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'D:\TestPageLevelRestore_log.bak'&lt;/span&gt; &lt;span style="color: blue;"&gt;WITH&lt;/span&gt; &lt;span style="color: blue;"&gt;INIT&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: blue;"&gt;NORECOVERY&lt;/span&gt;&lt;span style="color: grey;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;GO&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh4.googleusercontent.com/-gbl0ra9N3Go/TY2gxtrwTWI/AAAAAAAAE-o/Z-b_ecDxPKk/s1600/14.png" /&gt;&lt;/div&gt;After backing up the tail log, restore the corrupted page using the below command.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Restore&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;DATABASE&lt;/span&gt; TestPageLevelRestore Page&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'1:147'&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt;&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'D:\TestPageLevelRestore_FullBackup.bak'&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh5.googleusercontent.com/-UwHGg1tkYZA/TY2hgrUBHUI/AAAAAAAAE-s/nlcEYwjx1Dg/s1600/15.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
After the page restoration is completed, Restore the tail log backup.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;RESTORE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: magenta;"&gt;LOG&lt;/span&gt; TestPageLevelRestore &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: blue;"&gt;DISK&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'D:\TestPageLevelRestore_log.bak'&lt;/span&gt;&lt;span style="color: grey;"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;GO&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh3.googleusercontent.com/-ygPddJLcIkA/TY2iZPAdNPI/AAAAAAAAE-w/sFLLWIsnOoI/s1600/16.png" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Now you have restored the corrupted page from a good backup and this can be verified by selecting the data from the table and you will be able to&amp;nbsp;retrieve&amp;nbsp;the data.&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;USE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; TestPageLevelRestore&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; shift&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh6.googleusercontent.com/-F2HKkpPpHtA/TY2jTsxi9cI/AAAAAAAAE-0/sgEJAORvb5E/s1600/17.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
The complete demo script that I have used in this post can be downloaded from &lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HMDczY2U3ZGMtYzI5YS00OGVlLThhOTktNjE3OTViNjY5OWJj&amp;amp;hl=en&amp;amp;authkey=CNvbu4AF" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-5060090829511001557?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gEWKbXcw6X6uhGGQpo_jW_mfYAk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gEWKbXcw6X6uhGGQpo_jW_mfYAk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gEWKbXcw6X6uhGGQpo_jW_mfYAk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gEWKbXcw6X6uhGGQpo_jW_mfYAk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/l6pdCRK8LoY" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-26T14:52:15.743+05:30</app:edited><media:thumbnail url="https://lh6.googleusercontent.com/-ms59qKjJOzo/TY2UTshqMHI/AAAAAAAAE9k/ht0M9HFrwkE/s72-c/1.PNG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://www.sanssql.com/2011/03/page-level-restoration.html</feedburner:origLink></item><item><title>Automating SQL Server Express Backups</title><link>http://feedproxy.google.com/~r/SansSQL/~3/IH5AH4h9jDc/automating-sql-server-express-backups.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>Downloads</category><category>SQLExpress</category><category>Automate</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>SQLCMD</category><category>SQL Queries</category><category>Backup</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sat, 19 Mar 2011 20:36:30 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-3700995185195924180</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As we all know that many of the third party applications uses SQL Server Express Edition to store their&amp;nbsp;backend&amp;nbsp;data. And also these application will be used in Live environments which requires backing up of the databases to recover data during a disaster.&lt;br /&gt;
Since there is no SQL Server agent in Express Edition, we cannot schedule SQL Backups or any other DB Maintenance activities using SQL Scheduler. So for this purpose, we have to make use of the windows scheduler.&lt;br /&gt;
For Automating the backup process, i have developed the below query which can be used for multiple purpose and can be scheduled using windows scheduler as well as SQL Agent.&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;
Script&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp; &lt;span style="color: grey;"&gt;EXISTS&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT&lt;/span&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;objects&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; &lt;span style="color: magenta;"&gt;object_id&lt;/span&gt; &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;OBJECT_ID&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;N'[dbo].[sp_BackupDatabases]'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; &lt;span style="color: blue;"&gt;type&lt;/span&gt; &lt;span style="color: grey;"&gt;in&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;N'P'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;N'PC'&lt;/span&gt;&lt;span style="color: grey;"&gt;))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;PRINT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'Stored Procedure "sp_BackupDatabases" already exists in the database. Dropping the SP to create a newer Version.'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;PROCEDURE&lt;/span&gt; [dbo]&lt;span style="color: grey;"&gt;.&lt;/span&gt;[sp_BackupDatabases]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;PROC&lt;/span&gt; sp_BackupDatabases&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;@BackupDBType &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)=&lt;/span&gt;&lt;span style="color: red;"&gt;'Help'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; @DBName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;max&lt;/span&gt;&lt;span style="color: grey;"&gt;)=NULL,&lt;/span&gt; @BackupPath &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;max&lt;/span&gt;&lt;span style="color: grey;"&gt;)=NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;AS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;/*&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;Author: Sandesh Segu&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;Website: http://www.SansSQL.com&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;NOCOUNT&lt;/span&gt; &lt;span style="color: blue;"&gt;ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DateTime &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;25&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DateTime&lt;span style="color: grey;"&gt;=LEFT(&lt;/span&gt;&lt;span style="color: magenta;"&gt;REPLACE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;REPLACE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;REPLACE&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;30&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color: grey;"&gt;(),&lt;/span&gt;120&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;':'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;''&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;'-'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;''&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt;&lt;span style="color: red;"&gt;' '&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;''&lt;/span&gt;&lt;span style="color: grey;"&gt;),&lt;/span&gt;12&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType &lt;span style="color: grey;"&gt;not&lt;/span&gt; &lt;span style="color: grey;"&gt;in&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'ALL'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'System'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'User'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'Specific'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'Help'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;RAISERROR &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(&lt;/span&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 9pt;"&gt;'Incorrect Parameter Value Passed. @BackupDBType Parameters should be ''ALL'',''System'',''User'',''Specific'''&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;16&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span style="color: red;"&gt;'HELP'&lt;/span&gt; &lt;span style="color: grey;"&gt;and&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;RAISERROR &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(&lt;/span&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 9pt;"&gt;'Specify the path to backup databases. @BackupPath must be specified'&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;16&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(RIGHT(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;@BackupPath&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;))&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style="color: red;"&gt;'\'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupPath&lt;span style="color: grey;"&gt;=&lt;/span&gt;@BackupPath&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'\'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;ELSE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupPath&lt;span style="color: grey;"&gt;=&lt;/span&gt;@BackupPath&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'Help'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'Usage of this Stored Proc can be in any of the below format.'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'-------------------------------------------------------------------------'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'1. To Backup All Databases in a instance'&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = ''ALL'', @BackupPath = ''C:\Backup'''&lt;/span&gt; &lt;span style="color: grey;"&gt;+&lt;/span&gt; &lt;span style="color: blue;"&gt;Char&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'2. To Backup only System Databases in a instance'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = ''System'', @BackupPath = ''C:\Backup'''&lt;/span&gt; &lt;span style="color: grey;"&gt;+&lt;/span&gt; &lt;span style="color: blue;"&gt;Char&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'3. To Backup only User Databases in a instance'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = ''User'', @BackupPath = ''C:\Backup'''&lt;/span&gt; &lt;span style="color: grey;"&gt;+&lt;/span&gt; &lt;span style="color: blue;"&gt;Char&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'4. To Backup specific (One) Database(s) in a instance'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = ''Specific'', @DBName = ''AdventureWorks'', @BackupPath = ''C:\Backup'''&lt;/span&gt; &lt;span style="color: grey;"&gt;+&lt;/span&gt; &lt;span style="color: blue;"&gt;Char&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;10&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'5. To Backup specific (more than One) Database(s) in a instance'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = ''Specific'', @DBName = ''AdventureWorks,master,msdb'', @BackupPath = ''C:\Backup'''&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'-------------------------------------------------------------------------'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: grey;"&gt;exists&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;select&lt;/span&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;objects&lt;/span&gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; name&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'BackupDatabases'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; BackupDatabases&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; BackupDatabases&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;DBName &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;DatabaseID &lt;span style="color: blue;"&gt;int&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;[BackupStatement] &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;max&lt;/span&gt;&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'ALL'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; BackupDatabases&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; name&lt;span style="color: grey;"&gt;,&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;''&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; name &lt;span style="color: grey;"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style="color: red;"&gt;'tempdb'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'System'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; BackupDatabases &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; name&lt;span style="color: grey;"&gt;,&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;''&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; name &lt;span style="color: grey;"&gt;in&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: red;"&gt;'master'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;'model'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;'msdb'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'User'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; BackupDatabases &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; name&lt;span style="color: grey;"&gt;,&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;''&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; database_id&lt;span style="color: grey;"&gt;&amp;gt;&lt;/span&gt;4&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'Specific'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;RAISERROR &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(&lt;/span&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 9pt;"&gt;'Specify the Database Name(s) to Backup. @DBName must be specified.'&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;,&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;16&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;IF&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupDBType&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: red;"&gt;'Specific'&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @DBName &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;/span&gt; &lt;span style="color: grey;"&gt;AND&lt;/span&gt; @BackupPath &lt;span style="color: grey;"&gt;IS&lt;/span&gt; &lt;span style="color: grey;"&gt;NOT&lt;/span&gt; &lt;span style="color: grey;"&gt;NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DelimiterPos &lt;span style="color: blue;"&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;-- Find the first comma&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DelimiterPos &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;PATINDEX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt; &lt;span style="color: red;"&gt;'%,%'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; @DBName&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;-- If a delimiter was found, @DelimiterPos will be &amp;gt; 0.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;WHILE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DelimiterPos &lt;span style="color: grey;"&gt;&amp;gt;&lt;/span&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;-- Insert the value between the start of the string and the first delimiter, into the table variable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; BackupDatabases &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; name&lt;span style="color: grey;"&gt;,&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;''&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; name &lt;span style="color: grey;"&gt;in&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT&lt;/span&gt; &lt;span style="color: magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;LTRIM&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;RTRIM&lt;/span&gt;&lt;span style="color: grey;"&gt;((&lt;/span&gt;&lt;span style="color: magenta;"&gt;SUBSTRING&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;@DBName&lt;span style="color: grey;"&gt;,&lt;/span&gt; 1&lt;span style="color: grey;"&gt;,&lt;/span&gt; @DelimiterPos &lt;span style="color: grey;"&gt;-&lt;/span&gt;1&lt;span style="color: grey;"&gt;))))&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: grey;"&gt;))&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;-- Trim the string of the first value and delimiter.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DBName &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;SUBSTRING&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;@DBName&lt;span style="color: grey;"&gt;,&lt;/span&gt; @DelimiterPos &lt;span style="color: grey;"&gt;+&lt;/span&gt;1&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: magenta;"&gt;LEN&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;@DBName&lt;span style="color: grey;"&gt;)&lt;/span&gt; &lt;span style="color: grey;"&gt;-&lt;/span&gt; @DelimiterPos&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: green; font-family: 'Courier New'; font-size: 9pt;"&gt;-- Look for the next delimiter in the string.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @DelimiterPos &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: magenta;"&gt;PATINDEX&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt; &lt;span style="color: red;"&gt;'%,%'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt; @DBName&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;INSERT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;INTO&lt;/span&gt; BackupDatabases &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; name&lt;span style="color: grey;"&gt;,&lt;/span&gt;database_id&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: red;"&gt;''&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;databases&lt;/span&gt; &lt;span style="color: blue;"&gt;WHERE&lt;/span&gt; name &lt;span style="color: grey;"&gt;in&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT&lt;/span&gt; &lt;span style="color: magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;LTRIM&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;RTRIM&lt;/span&gt;&lt;span style="color: grey;"&gt;((&lt;/span&gt;@DBName&lt;span style="color: grey;"&gt;)))&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;UPDATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; BackupDatabases &lt;span style="color: blue;"&gt;SET&lt;/span&gt; BackupStatement&lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'Print ''Backup of Database '&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;DBName&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;' Started''; Backup Database ['&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;DBName&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'] TO DISK='''&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@BackupPath&lt;span style="color: grey;"&gt;+&lt;/span&gt;DBName&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'_Backup_'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@DateTime&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'.bak'' WITH INIT, STATS=10'&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Print&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: red;"&gt;'The Requested database(s) are being backed up to the location "'&lt;/span&gt;&lt;span style="color: grey;"&gt;+&lt;/span&gt;@BackupPath&lt;span style="color: grey;"&gt;+&lt;/span&gt;&lt;span style="color: red;"&gt;'"'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;WHILE &lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 9pt;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: magenta;"&gt;COUNT&lt;/span&gt;&lt;span style="color: grey;"&gt;(*)&lt;/span&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; BackupDatabases&lt;span style="color: grey;"&gt;)&amp;gt;&lt;/span&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupStatement &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;max&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; @BackupStatement&lt;span style="color: grey;"&gt;=&lt;/span&gt; [BackupStatement] &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; BackupDatabases&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Exec&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: maroon;"&gt;sp_executesql&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;@BackupStatement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;Delete&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;from&lt;/span&gt; BackupDatabases &lt;span style="color: blue;"&gt;where&lt;/span&gt; [BackupStatement]&lt;span style="color: grey;"&gt;=&lt;/span&gt;@BackupStatement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; BackupDatabases&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt;"&gt;SET&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="color: blue;"&gt;NOCOUNT&lt;/span&gt; &lt;span style="color: blue;"&gt;OFF&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 9pt; line-height: 115%;"&gt;GO&lt;/span&gt;&lt;span style="font-size: 9pt; line-height: 115%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Usage&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;Usage of this Stored Proc can be in any of the below format.&lt;br /&gt;
-------------------------------------------------------------------------&lt;br /&gt;
1. To Backup All Databases in a instance&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = 'ALL', @BackupPath = 'C:\Backup'&lt;br /&gt;
&lt;br /&gt;
2. To Backup only System Databases in a instance&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = 'System', @BackupPath = 'C:\Backup'&lt;br /&gt;
&lt;br /&gt;
3. To Backup only User Databases in a instance&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = 'User', @BackupPath = 'C:\Backup'&lt;br /&gt;
&lt;br /&gt;
4. To Backup specific (One) Database(s) in a instance&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = 'Specific', @DBName = 'AdventureWorks', @BackupPath = 'C:\Backup'&lt;br /&gt;
&lt;br /&gt;
5. To Backup specific (more than One) Database(s) in a instance&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Exec sp_BackupDatabases @BackupDBType = 'Specific', @DBName = 'AdventureWorks,master,msdb', @BackupPath = 'C:\Backup'&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div&gt;To Delete the old backups I use the below query.&lt;/div&gt;&lt;div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @TwoDaysOld &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;50&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Set&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @TwoDaysOld&lt;span style="color: grey;"&gt;=&lt;/span&gt;&lt;span style="color: magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;DATEADD&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;d&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: grey;"&gt;-&lt;/span&gt;2&lt;span style="color: grey;"&gt;,&lt;/span&gt; &lt;span style="color: magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color: grey;"&gt;())&lt;/span&gt; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @TwoDaysOld&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;Exec&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;master&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;dbo&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: maroon;"&gt;xp_delete_file&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;0&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;N'C:\Backups\'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: red;"&gt;N'bak'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;@TwoDaysOld&lt;/span&gt;&lt;span style="font-size: 9pt; line-height: 115%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;This will delete any .bak files in the given location which are older than 2 days.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So after creating the&amp;nbsp;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;sp_BackupDatabases stored proc, if we want to schedule the backups using windows scheduler than we have create a batch file (.bat file) which will be called in the windows scheduler at the scheduled time.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 630px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;sqlcmd -S(local)\SQLEXPRESS -E -Q"DECLARE @TwoDaysOld VARCHAR(50) Set @TwoDaysOld=CAST(DATEADD(d, -2, GETDATE()) AS VARCHAR)&lt;br /&gt;
Exec&amp;nbsp;master.dbo.sp_BackupDatabases @BackupDBType = 'User', @BackupPath = 'C:\Backup'&lt;br /&gt;
Exec master.dbo.xp_delete_file 0,N'D:\Backups\',N'bak',@TwoDaysOld" &lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
Scripts can be downloaded from the below locations&lt;/div&gt;&lt;div&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;&lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HZDEwYWQ4ZmQtMzk2OS00NzQwLWExMmUtNDZkMDE1YWU5MTJh&amp;amp;hl=en&amp;amp;authkey=CLDZr6wL" target="_blank"&gt;SansSQL_Automate Backup in Express Edition.sql&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HZjc1NTNiY2ItM2Q2YS00ZjMyLTk5NjYtNjQ5NGUwNTJjYmUz&amp;amp;hl=en&amp;amp;authkey=CIfx5uMN" target="_blank"&gt;SansSQL_Delete_bakfilesOlderThan2Days.sql&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HNGVkYmY2MGUtZjVkNC00MmRkLWEwYTMtMjY3YWY0YmUxZmU2&amp;amp;hl=en&amp;amp;authkey=CNWfn_IG" target="_blank"&gt;SansSQL_sp_BackupDatabases_User.bat&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-3700995185195924180?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xxE0AaO1UC_VcSuGJzWhoUf57dk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xxE0AaO1UC_VcSuGJzWhoUf57dk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xxE0AaO1UC_VcSuGJzWhoUf57dk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xxE0AaO1UC_VcSuGJzWhoUf57dk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/IH5AH4h9jDc" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-20T09:06:30.934+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/03/automating-sql-server-express-backups.html</feedburner:origLink></item><item><title>T-SQL Query to find list of Instances Installed on a machine</title><link>http://feedproxy.google.com/~r/SansSQL/~3/_7_0FPpp9Tc/t-sql-query-to-find-number-of-instances.html</link><category>SQL Server 2008</category><category>SQL Information</category><category>Undocumented</category><category>SQL Server 2011</category><category>SQL Server 2005</category><category>SQL Queries</category><category>Installed Instances</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sun, 13 Mar 2011 01:11:10 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-1528546735563393021</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Here is a T-SQL Query to find the list of instances Installed on a machine.&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DECLARE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; @GetInstances &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; Value &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;InstanceNames &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;Data &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; @GetInstances&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'InstalledInstances'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; InstanceNames &lt;span style="color: blue;"&gt;from&lt;/span&gt; @GetInstances&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;div style="text-align: center;"&gt;OR&lt;/div&gt;&lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 650px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Create&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;Table&lt;/span&gt; #GetInstances&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;(&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; Value &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;InstanceNames &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;Data &lt;span style="color: blue;"&gt;nvarchar&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;100&lt;span style="color: grey;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Insert&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;into&lt;/span&gt; #GetInstances&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;xp_regread&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;@rootkey &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'HKEY_LOCAL_MACHINE'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @key &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'SOFTWARE\Microsoft\Microsoft SQL Server'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; @value_name &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'InstalledInstances'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;Select&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; InstanceNames &lt;span style="color: blue;"&gt;from&lt;/span&gt; #GetInstances&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;drop&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt; &lt;span style="color: blue;"&gt;table&lt;/span&gt; #GetInstances&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
Both the queries are almost similar, except for that first query uses a table variable and the second one uses temporary table.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-1528546735563393021?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2vHppb8FCPIbYDDthFd2StAqkWc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2vHppb8FCPIbYDDthFd2StAqkWc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2vHppb8FCPIbYDDthFd2StAqkWc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2vHppb8FCPIbYDDthFd2StAqkWc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/_7_0FPpp9Tc" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-13T14:41:10.076+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/03/t-sql-query-to-find-number-of-instances.html</feedburner:origLink></item><item><title>T-SQL Query to find the date when was DBCC CHECKDB Last run</title><link>http://feedproxy.google.com/~r/SansSQL/~3/SKVbqx7L40s/t-sql-query-to-find-date-when-was-dbcc.html</link><category>SQL Server 2008</category><category>Undocumented</category><category>Downloads</category><category>DBCC CHECKDB</category><category>Troubleshooting</category><category>SQL Server 2011</category><category>SQL Server 2005</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sat, 12 Mar 2011 22:20:19 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-3280538509352376136</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As a Database Administrator, we know the importance of DBCC CHECKDB and will run this command&amp;nbsp;to check the logical and physical integrity of all objects in the specified database.&lt;br /&gt;
When DBCC CHECKDB is run on a database, it does the following actions&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Runs DBCC CHECKALLOC on the database&lt;/li&gt;
&lt;li&gt;Runs DBCC CHECKTABLE on every table and view in the database&lt;/li&gt;
&lt;li&gt;Runs DBCC CHECKCATALOG on the database&lt;/li&gt;
&lt;li&gt;Validates the contents of every indexed view in the database&lt;/li&gt;
&lt;li&gt;Validates Service Broker data in the database&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;Before you start the DBCC CHECKDB on a database you might want to know the date and time when this command was lust run by you or someone else from your team.&lt;br /&gt;
Prior to SQL Server 2005, this data was not getting logged in the system. But in SQL Server 2005 onwards this data is getting logged in the system and using the below script you can find the date and time when DBCC CHECKDB was last run on a database.&lt;br /&gt;
&lt;/div&gt;&lt;table border="1" cellpadding="2" cellspacing="2" style="width: 640px;"&gt;&lt;tbody&gt;
&lt;tr&gt;   &lt;td&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #DBInfo&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id &lt;span style="color: blue;"&gt;INT&lt;/span&gt; &lt;span style="color: blue;"&gt;IDENTITY&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;1&lt;span style="color: grey;"&gt;,&lt;/span&gt;1&lt;span style="color: grey;"&gt;),&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ParentObject &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Object] &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Field &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Value] &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;CREATE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #Value&lt;span style="color: grey;"&gt;(&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;DatabaseName &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt;LastDBCCCHeckDB_RunDate &lt;span style="color: blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;255&lt;span style="color: grey;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;EXECUTE&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: maroon;"&gt;SP_MSFOREACHDB&lt;/span&gt;&lt;span style="color: red;"&gt;'INSERT INTO #DBInfo Execute (''DBCC DBINFO ( ''''?'''') WITH TABLERESULTS'');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;INSERT INTO #Value (DatabaseName) SELECT [Value] FROM #DBInfo WHERE Field IN (''dbi_dbname'');&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;UPDATE #Value SET LastDBCCCHeckDB_RunDate=(SELECT TOP 1 [Value] FROM #DBInfo WHERE Field IN (''dbi_dbccLastKnownGood'')) where LastDBCCCHeckDB_RunDate is NULL;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: red; font-family: 'Courier New'; font-size: 10pt;"&gt;TRUNCATE TABLE #DBInfo'&lt;/span&gt;&lt;span style="color: grey; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: grey;"&gt;*&lt;/span&gt; &lt;span style="color: blue;"&gt;FROM&lt;/span&gt; #Value&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #DBInfo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;DROP&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;TABLE&lt;/span&gt; #Value&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The Script can be downloaded from &lt;a href="https://docs.google.com/leaf?id=0B2KTftq5oM9HZjE1Mjg2YTEtOGIzYS00NTUwLWIyZDYtMTZlZTFlOGUwYzA2&amp;amp;sort=name&amp;amp;layout=list&amp;amp;num=50" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-3280538509352376136?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wvpFe5Lwf2CVXNDJmsVIvlMcUKk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wvpFe5Lwf2CVXNDJmsVIvlMcUKk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wvpFe5Lwf2CVXNDJmsVIvlMcUKk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wvpFe5Lwf2CVXNDJmsVIvlMcUKk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/SKVbqx7L40s" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-13T11:50:19.766+05:30</app:edited><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/03/t-sql-query-to-find-date-when-was-dbcc.html</feedburner:origLink></item><item><title>ERROR - Cannot set a credential for principal 'sa'</title><link>http://feedproxy.google.com/~r/SansSQL/~3/PYu681jhz04/error-cannot-set-credential-for.html</link><category>SQL Server 2008</category><category>Troubleshooting</category><category>SQL Server 2011</category><category>SQL Server 2005</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Sat, 26 Feb 2011 22:43:56 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-8695794433545221604</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;You may sometimes receive an error which says "Cannot set a credential for principal 'sa'" while you are trying to alter the login 'sa' in SQL Server 2005 or SQL Server 2008.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh5.googleusercontent.com/-YIvJ3OZCIeY/TWiWp1ZlUpI/AAAAAAAAE7o/MET2SQPZ9NM/s1600/FailedSa.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;This happens because, the SQL Server tries to drop any credential that is mapped to your login credentials while altering and because your credential cannot be set to "sa" login, you will receive this error.&lt;br /&gt;
&lt;/div&gt;&lt;b&gt;&lt;u&gt;FIX&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
Fix for this error is very simple. Just make sure that the option "Map to Credential" is checked in the "General" tab of the Login Properties Page.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="https://lh4.googleusercontent.com/-LC3N_epX8ls/TWntGDnWOAI/AAAAAAAAE7s/njTonI7snxE/s1600/Capture.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Reference&lt;/u&gt;&lt;/b&gt;:&amp;nbsp;&lt;a href="http://support.microsoft.com/kb/956177" target="_blank"&gt;http://support.microsoft.com/kb/956177&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-8695794433545221604?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/g6xM3TvRpXBJr7096OJ8OXfrieI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g6xM3TvRpXBJr7096OJ8OXfrieI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/g6xM3TvRpXBJr7096OJ8OXfrieI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g6xM3TvRpXBJr7096OJ8OXfrieI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/PYu681jhz04" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-27T12:13:56.737+05:30</app:edited><media:thumbnail url="https://lh5.googleusercontent.com/-YIvJ3OZCIeY/TWiWp1ZlUpI/AAAAAAAAE7o/MET2SQPZ9NM/s72-c/FailedSa.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/02/error-cannot-set-credential-for.html</feedburner:origLink></item><item><title>SQL Server 2011 (Denali) - First Look</title><link>http://feedproxy.google.com/~r/SansSQL/~3/8C8MLnx1wWE/sql-server-2011-denali-first-look.html</link><category>Denali</category><category>SQL Server 2011</category><category>What's New</category><author>noreply@blogger.com (Sandesh Segu)</author><pubDate>Tue, 22 Feb 2011 04:59:19 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-370183193676959553.post-2175480296890817398</guid><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;First look of SQL Server Denali after Installation.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: center;"&gt;&lt;b&gt;&lt;u&gt;Splash Screen&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-VHHAw6YKudY/TWOPwvfMXFI/AAAAAAAAE5w/hsIOYs58qaU/s1600/1.PNG" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;b&gt;&lt;u&gt;Login Window&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-YCHnpNQSza4/TWOPxekKzlI/AAAAAAAAE50/skPFiMjW7Nc/s1600/2.PNG" /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;SQL Server&amp;nbsp;Management&amp;nbsp;Studio&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-max8L42FoZ0/TWOiL-gvi3I/AAAAAAAAE6I/ZiRbuWnYmHs/s1600/3+-+Copy+%25282%2529.PNG" /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/370183193676959553-2175480296890817398?l=www.sanssql.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8WTe0JBHNtbJDz_J9wqeFAhck5o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8WTe0JBHNtbJDz_J9wqeFAhck5o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8WTe0JBHNtbJDz_J9wqeFAhck5o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8WTe0JBHNtbJDz_J9wqeFAhck5o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SansSQL/~4/8C8MLnx1wWE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-22T18:29:19.724+05:30</app:edited><media:thumbnail url="http://4.bp.blogspot.com/-VHHAw6YKudY/TWOPwvfMXFI/AAAAAAAAE5w/hsIOYs58qaU/s72-c/1.PNG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.sanssql.com/2011/02/sql-server-2011-denali-first-look.html</feedburner:origLink></item><media:rating>nonadult</media:rating></channel></rss>

