<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'maintenance' and 'administration'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=maintenance,administration&amp;orTags=0</link><description>Search results matching tags 'maintenance' and 'administration'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Using the catalog views : clearing out a &amp;quot;botched&amp;quot; schema</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/07/07/using-the-catalog-views-clearing-out-a-botched-schema.aspx</link><pubDate>Thu, 07 Jul 2011 15:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:36703</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;A user on StackOverflow had populated a custom schema with a bunch of tables, and needed to replace them with a new set of tables due to various changes. But he couldn't just drop them all in any arbitrary order, because there were foreign keys in place. His workaround was to just run a "drop all tables" script multiple times until there were no more errors. As you can imagine, on a complicated enough schema, this can be really tedious. Even on a small schema, this just doesn't feel like the right way.&lt;br&gt;&lt;br&gt;Let's assume the following case:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[tempdb]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE SCHEMA &lt;/font&gt;&lt;font color="black"&gt;[blat] &lt;/font&gt;&lt;font color="blue"&gt;AUTHORIZATION &lt;/font&gt;&lt;font color="black"&gt;[dbo]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;[blat].A&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id &lt;/font&gt;&lt;font color="blue"&gt;INT PRIMARY KEY&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;[blat].B&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id &lt;/font&gt;&lt;font color="blue"&gt;INT PRIMARY KEY FOREIGN KEY &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REFERENCES &lt;/font&gt;&lt;font color="black"&gt;[blat].A&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;[blat].C&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id &lt;/font&gt;&lt;font color="blue"&gt;INT FOREIGN KEY &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REFERENCES &lt;/font&gt;&lt;font color="black"&gt;[blat].B&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="green"&gt;-- let's also create a table in another schema&lt;br&gt;-- that points at tables in this schema:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;[dbo].D&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id1 &lt;/font&gt;&lt;font color="blue"&gt;INT FOREIGN KEY &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REFERENCES &lt;/font&gt;&lt;font color="black"&gt;[blat].A&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id2 &lt;/font&gt;&lt;font color="blue"&gt;INT FOREIGN KEY &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REFERENCES &lt;/font&gt;&lt;font color="black"&gt;[blat].B&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;);&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;


&lt;p&gt;Initially if you try this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DROP TABLE &lt;/font&gt;&lt;font color="black"&gt;[blat].A&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;



You get this error message:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div style="color:red;padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;
Msg 3726, Level 16, State 1, Line 1&lt;br&gt;Could not drop object 'blat.A' because it is referenced by a FOREIGN KEY constraint. &lt;br&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;



&lt;p&gt;So I put together a quick script that would allow you to drop all of the tables in the schema, by first removing all of the foreign key constraints. In this case order within each set of statements is unimportant, so we can use lazy string concatenation instead of more complicated FOR XML queries that allow you to dictate order:&lt;/p&gt;
&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@schema_to_empty &lt;/font&gt;&lt;font color="blue"&gt;SYSNAME &lt;/font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;font&gt;&lt;font color="#434343"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;N'blat'&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@sql &lt;/font&gt;&lt;font color="blue"&gt;             NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;MAX&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;font&gt;&lt;font color="#434343"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;N''&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="green"&gt;-- drop all references to tables in the blat schema,&lt;br&gt;-- even FKs on tables in other schemas.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="#434343"&gt;@sql &lt;/font&gt;&lt;font color="gray"&gt;+=&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;N'&lt;br&gt;	ALTER TABLE '&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;OBJECT_SCHEMA_NAME&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;k.parent_object_id&lt;/font&gt;&lt;font color="gray"&gt;))&lt;br&gt;&amp;nbsp;&amp;nbsp; + &lt;/font&gt;&lt;font color="red"&gt;'.' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_NAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;k.parent_object_id&lt;/font&gt;&lt;font color="gray"&gt;))&lt;br&gt;&amp;nbsp;&amp;nbsp; + &lt;/font&gt;&lt;font color="red"&gt;' DROP CONSTRAINT ' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;k.[name]&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;';'&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;foreign_keys&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;k&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER JOIN &lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;tables&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;t&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;k.referenced_object_id &lt;/font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="black"&gt;t.[object_id]&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;t.[schema_id] &lt;/font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;SCHEMA_ID&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="#434343"&gt;@schema_to_empty&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="green"&gt;-- then drop all the tables.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="#434343"&gt;@sql &lt;/font&gt;&lt;font color="gray"&gt;+=&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;N'&lt;br&gt;	DROP TABLE ' &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="#434343"&gt;@schema_to_empty&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;'.'&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[name]&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;';'&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;tables&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;[schema_id]&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;SCHEMA_ID&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="#434343"&gt;@schema_to_empty&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;-- if the output is &amp;lt; 8K, you can inspect it using PRINT:&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;PRINT &lt;/font&gt;&lt;font color="#434343"&gt;@sql&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="green"&gt;-- in case it's too big for PRINT (&amp;gt; 8K), but still less than 64K&lt;br&gt;-- you can run this in grid mode, click on the output, and copy the&lt;br&gt;-- script from the new window that is created:&lt;br&gt;&lt;br&gt;-- SELECT CONVERT(XML, @sql);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="green"&gt;-- or you can just trust me and run it, MWAHAHAHAHA!:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="green"&gt;-- EXEC sp_executeSQL @sql;&lt;/font&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;




&lt;p&gt;You may also want / need to clear out other objects, such as views that reference objects in this schema, or triggers on tables in other schemas that reference objects in this schema. Those bring about other complications I'll address in a future post, if there is enough interest. &lt;/p&gt;
&lt;p&gt;In the meantime, wouldn't it be great if we had CREATE OR REPLACE functionality that would, in addition to preventing us from having to drop all the objects first or write complex existence checks and alter commands, also sever these dependencies for us? You can vote for this functionality at &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/127219/create-or-replace" title="http://connect.microsoft.com/SQLServer/feedback/details/127219/create-or-replace" target="_blank"&gt;Connect #127219&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;It would also be nice to have a DROP SCHEMA command that did the same type of thing as I manually do above. Instead of just complaining that the schema is not empty, I'd love to see a DROP SCHEMA ... WITH FORCE option, or something similar, where it took care of all the objects for you - much like DROP DATABASE does. Of course this would be easy to implement in a simple case, but not when schemas have cross-dependencies and references that are embedded in module definitions rather than straightforward DRI and similar constructs.&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;br&gt;&lt;/p&gt;</description></item><item><title>Backup those keys, citizen</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/04/20/backup-those-keys-citizen.aspx</link><pubDate>Tue, 20 Apr 2010 12:14:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:24408</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;Periodically I back up the keys within my servers and databases, and when I do, I blog a reminder here. This should be part of your standard backup rotation – the keys should be backed up often enough to have at hand and again when they change.&lt;/p&gt;  &lt;p&gt;The first key you need to back up is the Service Master Key, which each Instance already has built-in. You do that with the &lt;a href="http://msdn.microsoft.com/en-us/library/ms190337.aspx" target="_blank"&gt;BACKUP SERVICE MASTER KEY command, which you can read more about here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The second set of keys are the Database Master Keys, stored per database, if you’ve created one. You can back those up with the &lt;a href="http://technet.microsoft.com/en-us/library/ms174387.aspx" target="_blank"&gt;BACKUP MASTER KEY command, which you can read more about here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Finally, you can use the keys to create certificates and other keys – those should also be backed up. &lt;a href="http://msdn.microsoft.com/en-us/library/ms189586.aspx" target="_blank"&gt;Read more about those here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Anyway, the important part here is the backup. Make sure you keep those keys safe!&lt;/p&gt;</description></item><item><title>Backup Meta-Data</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/03/30/backup-meta-data.aspx</link><pubDate>Tue, 30 Mar 2010 14:46:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:23870</guid><dc:creator>BuckWoody</dc:creator><description>&lt;P&gt;I'm working on a PowerShell script to show me the trending durations of my backup activities. The first thing I need is the data, so I looked at the Standard Reports in SQL Server Management Studio, and found a report that suited my needs, so I pulled out the script that it runs and modified it to this T-SQL Script. &lt;/P&gt;
&lt;P&gt;A few words here - you need to be in the MSDB database for this to run, and you can add a WHERE clause to limit to a database, timeframe, type of backup, whatever. For that matter, I won't use all of the data in this query in my PowerShell script, but it gives me lots of avenues to graph:&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#009900&gt;SELECT distinct t1.name AS 'DatabaseName'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,(datediff( ss,&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;t3.backup_start_date, t3.backup_finish_date)) AS 'DurationInSeconds'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.user_name AS 'UserResponsible'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.name AS backup_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.description&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_start_date&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_finish_date&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,CASE WHEN t3.type = 'D' THEN 'Database'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'L' THEN 'Log'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'F' THEN 'FileOrFilegroup'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'G' THEN 'DifferentialFile'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'P' THEN 'Partial'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'Q' THEN 'DifferentialPartial'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;END AS 'BackupType'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_size AS 'BackupSizeKB' &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t6.physical_device_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,CASE WHEN t6.device_type = 2 THEN 'Disk'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 102 THEN 'Disk'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 5 THEN 'Tape'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 105 THEN 'Tape'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;END AS 'DeviceType'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.recovery_model&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;FROM sys.databases t1 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;INNER JOIN backupset t3 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON (t3.database_name = t1.name )&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;LEFT OUTER JOIN backupmediaset t5 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON ( t3.media_set_id = t5.media_set_id ) &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;LEFT OUTER JOIN backupmediafamily t6 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON ( t6.media_set_id = t5.media_set_id ) &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ORDER BY backup_start_date DESC&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I'll munge this into my Excel PowerShell chart script tomorrow.&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;B&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-size:11.0pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;Script Disclaimer, for people who need to be told this sort of thing: &lt;/SPAN&gt;&lt;/I&gt;&lt;/B&gt;&lt;B&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0pt;" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;&lt;FONT face=Calibri&gt;Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. Yes, there are always multiple ways to do things, and this script may not work in every situation, for everything. It’s just a script, people. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea&amp;nbsp;during the operation of this script, see a physician immediately.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;</description></item><item><title>Have you backed up your keys lately?</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/03/01/have-you-backed-up-your-keys-lately.aspx</link><pubDate>Mon, 01 Mar 2010 14:06:04 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:22679</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;Did you know that you already have a Server Master Key (SMK) generated for your system? That’s right – while a Database Master Key (DMK) is generated when you encrypt a certificate or Asymmetric Key with code, the Server Master Key is generated automatically when you start the Instance. &lt;/p&gt;  &lt;p&gt;So you should back all of those keys up periodically, and then store that backup AWAY from the server itself. &lt;/p&gt;  &lt;p&gt;There are two reasons for this – first, if the drives get stolen and you’re storing the key backup there, well, that should be obvious why that’s bad. Second, you want to protect the keys in case the system is destroyed or you can’t recover the drives. You will need those keys if you have encrypted anything in the database to get the data back.&lt;/p&gt;  &lt;p&gt;More here: &lt;a href="http://technet.microsoft.com/en-us/library/bb964742.aspx"&gt;http://technet.microsoft.com/en-us/library/bb964742.aspx&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;No, the standard Maintenance Wizards don’t get this data. And no, I haven’t seen it addressed in most of the maintenance scripts out there anyway – sometimes for good reason, but this means you need to take care of it manually, and then document where you put that backup.&lt;/p&gt;</description></item><item><title>Tracking SQL Server Time</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/01/25/tracking-sql-server-time.aspx</link><pubDate>Mon, 25 Jan 2010 14:10:28 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21420</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;In the past few blog posts I’ve showed you how to use several methods to track things in SQL Server. You can use the “tags” to the right of this post here at this site to list things like PowerShell, Performance Tuning and so on. Now that you’re armed with these tools, what should you track?&lt;/p&gt;  &lt;p&gt;Well, one of the items I track is &lt;em&gt;time&lt;/em&gt;. I track the time it takes for lots of things, but they fall into three general buckets:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Queries – Normally I track the five longest running queries with their query plans. &lt;/li&gt;    &lt;li&gt;Maintenance – From how long each backup takes to index reorgs and rebuilds, I want to know how long these things take.&lt;/li&gt;    &lt;li&gt;Jobs – Most all of us have SQL Server Agent Jobs, and developing a schedule of how long they are running is very useful.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;For each of these, I track the minimum, maximum and average times. I look for outliers – things that suddenly change and so on.&lt;/p&gt;  &lt;p&gt;There are a lot of uses for this information. From performance tuning to developing a recovery plan, all of these actions need to be taken into account.&lt;/p&gt;  &lt;p&gt;I think I’ll write up an article sometime on how I do this – it’s a little long for a blog post.&lt;/p&gt;</description></item></channel></rss>