<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Data Management - Author(s): ptheriault</title>
		<link>http://blogs.lessthandot.com/index.php/DataMgmt/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>How to Delete Large amounts of data in a Batch.</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/how-to-delete-large-amounts</link>
			<pubDate>Thu, 20 Jan 2011 11:56:00 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>
<category domain="alt">Database Programming</category>
<category domain="alt">Database Administration</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">1076@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Recently I had a request to DELETE all the data except the last 30 days of data from a log table that is&amp;#160;80 GB in size.&amp;#160; It sounded like a simple request on the surface.&amp;#160; However, I couldn&amp;#8217;t shut down the web service that logs to that table every 5 minutes.&amp;#160; So I had to get the delete done between inserts.&amp;#160; So, my only choice was to run the delete in small batches.&amp;#160; That&amp;#8217;s when I stumbled upon this nice little trick.&amp;#160; New to 2005 and 2008 you can place a number after your GO statement and it will execute the batch that many times.&amp;#160; So, I was able delete records from my log table 10000 at a time without causing issues for the Web Service.&lt;/p&gt;
&lt;p&gt;For Example:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb49978&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DECLARE&lt;/span&gt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Timestamp&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;datetime&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;DELETE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;TOP&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000;&quot;&gt;10000&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;from&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #FF00FF;&quot;&gt;Log&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;With&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;tablockx&lt;/span&gt;, &lt;span style=&quot;color: #0000FF;&quot;&gt;holdlock&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;Timestamp&lt;/span&gt; &amp;lt; @&lt;span style=&quot;color: #0000FF;&quot;&gt;Timestamp&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt; &lt;span style=&quot;color: #000;&quot;&gt;500&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb13463&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/how-to-delete-large-amounts&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Recently I had a request to DELETE all the data except the last 30 days of data from a log table that is&#160;80 GB in size.&#160; It sounded like a simple request on the surface.&#160; However, I couldn&#8217;t shut down the web service that logs to that table every 5 minutes.&#160; So I had to get the delete done between inserts.&#160; So, my only choice was to run the delete in small batches.&#160; That&#8217;s when I stumbled upon this nice little trick.&#160; New to 2005 and 2008 you can place a number after your GO statement and it will execute the batch that many times.&#160; So, I was able delete records from my log table 10000 at a time without causing issues for the Web Service.</p>
<p>For Example:</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb51652'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb51652','cb10001'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb51652" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">Timestamp</span> <span style="color: #0000FF;">datetime</span></li><li style="" class="li2"><span style="color: #0000FF;">DELETE</span> <span style="color: #0000FF;">TOP</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">10000</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">from</span>&#160; <span style="color: #FF00FF;">Log</span> <span style="color: #0000FF;">With</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">tablockx</span>, <span style="color: #0000FF;">holdlock</span><span style="color: #808080;">&#41;</span></li><li style="" class="li1"><span style="color: #0000FF;">WHERE</span> <span style="color: #0000FF;">Timestamp</span> &lt; @<span style="color: #0000FF;">Timestamp</span></li><li style="" class="li2"><span style="color: #0000FF;">GO</span> <span style="color: #000;">500</span></li></ol></div><div id="cb10001" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/how-to-delete-large-amounts">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/how-to-delete-large-amounts#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1076</wfw:commentRss>
		</item>
				<item>
			<title>SSRS: How to monitor report subscriptions</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/ssrs-how-to-monitor-report-subscriptions</link>
			<pubDate>Wed, 08 Dec 2010 12:25:06 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>
<category domain="alt">Database Programming</category>
<category domain="alt">Database Administration</category>
<category domain="alt">Microsoft SQL Server Admin</category>
<category domain="alt">Microsoft SQL Server</category>			<guid isPermaLink="false">1036@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;As we all know SQL Server Reporting Services is a very powerful tool that gives end users a multitude of ways to retrieve data.  One such way is through subscriptions.   Subscriptions can be created by both Administrators and end users.  So as an administrator it is difficult to keep track of what subscriptions are running and when they are running.   It can also come as a surprise when the Director of a department comes to you to ask where his report was this morning.  As a DBA we must always know before the end user when there is a problem.  So how can we know if subscriptions are running successfully?   There is actually a very simple query.  When a subscription is created a record is added to the dbo.Subscriptions table in the ReportServer database.  There is also column in that table named LastStatus.  That column is update with the LastStatus of each subscription after the subscription is executed.  I have written a query that selects records where the LastStatus was not successful.  The path field in the query will show you where you find the report.  This way you can go in to correct the subscription if the problem is with the email recipient.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb53415&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;select&lt;/span&gt; s.&lt;span style=&quot;color: #202020;&quot;&gt;LastRunTime&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.&lt;span style=&quot;color: #202020;&quot;&gt;LastStatus&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.&lt;span style=&quot;color: #202020;&quot;&gt;Description&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.&lt;span style=&quot;color: #0000FF;&quot;&gt;Path&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.&lt;span style=&quot;color: #202020;&quot;&gt;name&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;u.&lt;span style=&quot;color: #202020;&quot;&gt;UserName&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;as&lt;/span&gt; SubscriptionOwner&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;from&lt;/span&gt; subscriptions s&lt;br /&gt;JOIN users u &lt;span style=&quot;color: #0000FF;&quot;&gt;on&lt;/span&gt; s.&lt;span style=&quot;color: #202020;&quot;&gt;OwnerId&lt;/span&gt; = u.&lt;span style=&quot;color: #202020;&quot;&gt;UserId&lt;/span&gt;&lt;br /&gt;JOIN &lt;span style=&quot;color: #0000FF;&quot;&gt;Catalog&lt;/span&gt; c &lt;span style=&quot;color: #0000FF;&quot;&gt;on&lt;/span&gt; s.&lt;span style=&quot;color: #202020;&quot;&gt;Report_OID&lt;/span&gt; = c.&lt;span style=&quot;color: #202020;&quot;&gt;ItemID&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;WHERE&lt;/span&gt; LastStatus like &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%Failure%&#039;&lt;/span&gt;&lt;br /&gt;Or LastStatus like &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%Error%&#039;&lt;/span&gt;&lt;br /&gt;or LastStatus like &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%The e-mail address of one or more recipients is not valid.%&#039;&lt;/span&gt;&lt;br /&gt;or LastStatus like &lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;%Thread was being aborted.%&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;Order&lt;/span&gt; &lt;span style=&quot;color: #0000FF;&quot;&gt;by&lt;/span&gt; LastRunTime&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb89437&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I have not been able to find a list of distinct or possible LastStatus values.  That is why I use key words like Failure or error.   If any knows of that list feel free to add a comment on where to find it.&lt;br /&gt;
I have also taken this query and made a report that can be run from SSRS.  I have granted permissions on the report to our Helpdesk.  This allows them to run it as part of their morning processes.  They can then be proactive in trouble shooting failed report subscriptions.  &lt;br /&gt;
One other note about subscriptions, most end users who create their own subscriptions schedule them to run just before they come in for the day.  So you will find that most subscriptions are running first thing in the morning.  You may choose to monitor this and ask end users to run spread them out over larger time period to balance the load.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/ssrs-how-to-monitor-report-subscriptions&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>As we all know SQL Server Reporting Services is a very powerful tool that gives end users a multitude of ways to retrieve data.  One such way is through subscriptions.   Subscriptions can be created by both Administrators and end users.  So as an administrator it is difficult to keep track of what subscriptions are running and when they are running.   It can also come as a surprise when the Director of a department comes to you to ask where his report was this morning.  As a DBA we must always know before the end user when there is a problem.  So how can we know if subscriptions are running successfully?   There is actually a very simple query.  When a subscription is created a record is added to the dbo.Subscriptions table in the ReportServer database.  There is also column in that table named LastStatus.  That column is update with the LastStatus of each subscription after the subscription is executed.  I have written a query that selects records where the LastStatus was not successful.  The path field in the query will show you where you find the report.  This way you can go in to correct the subscription if the problem is with the email recipient.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb63764'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb63764','cb93786'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb63764" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">select</span> s.<span style="color: #202020;">LastRunTime</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp;s.<span style="color: #202020;">LastStatus</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp;s.<span style="color: #202020;">Description</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp;c.<span style="color: #0000FF;">Path</span>,</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp;c.<span style="color: #202020;">name</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp;u.<span style="color: #202020;">UserName</span> <span style="color: #0000FF;">as</span> SubscriptionOwner</li><li style="" class="li1"><span style="color: #0000FF;">from</span> subscriptions s</li><li style="" class="li2">JOIN users u <span style="color: #0000FF;">on</span> s.<span style="color: #202020;">OwnerId</span> = u.<span style="color: #202020;">UserId</span></li><li style="" class="li1">JOIN <span style="color: #0000FF;">Catalog</span> c <span style="color: #0000FF;">on</span> s.<span style="color: #202020;">Report_OID</span> = c.<span style="color: #202020;">ItemID</span></li><li style="" class="li2"><span style="color: #0000FF;">WHERE</span> LastStatus like <span style="color: #FF0000;">'%Failure%'</span></li><li style="" class="li1">Or LastStatus like <span style="color: #FF0000;">'%Error%'</span></li><li style="" class="li2">or LastStatus like <span style="color: #FF0000;">'%The e-mail address of one or more recipients is not valid.%'</span></li><li style="" class="li1">or LastStatus like <span style="color: #FF0000;">'%Thread was being aborted.%'</span></li><li style="" class="li2"><span style="color: #0000FF;">Order</span> <span style="color: #0000FF;">by</span> LastRunTime</li></ol></div><div id="cb93786" style="display: none; color: red;"></div></div></div>

<p>I have not been able to find a list of distinct or possible LastStatus values.  That is why I use key words like Failure or error.   If any knows of that list feel free to add a comment on where to find it.<br />
I have also taken this query and made a report that can be run from SSRS.  I have granted permissions on the report to our Helpdesk.  This allows them to run it as part of their morning processes.  They can then be proactive in trouble shooting failed report subscriptions.  <br />
One other note about subscriptions, most end users who create their own subscriptions schedule them to run just before they come in for the day.  So you will find that most subscriptions are running first thing in the morning.  You may choose to monitor this and ask end users to run spread them out over larger time period to balance the load.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/ssrs-how-to-monitor-report-subscriptions">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/ssrs-how-to-monitor-report-subscriptions#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1036</wfw:commentRss>
		</item>
				<item>
			<title>The Productive DBA: Part 2 Document the Database</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba-document-the-database</link>
			<pubDate>Tue, 23 Nov 2010 11:30:08 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>
<category domain="alt">Database Administration</category>			<guid isPermaLink="false">1021@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;How many times have you started at a new company or been given a new database that you have to code for and you have no clue how the schema relates?  How much time is wasted trying to figure out that schema?  If you&amp;#8217;re lucky you will be given a database that has at least been developed correctly with foreign keys and a document to accompany it.  If you&amp;#8217;re not lucky, you&amp;#8217;ve just been handed a database with 50,000 objects that you need to document.  Don&amp;#8217;t be that DBA that hands off a database to someone else without an accompanying diagram and document that defines each table and object in plain English.  &lt;/p&gt;

&lt;p&gt;There are a few tools and methods to get this done.  I&amp;#8217;ll start with the best way to document your database.  First, write your definitions for each object in plain English.  You must write for a non-technical audience.  You never know who will end of up with your document.  The best location to store each object definition is right within the database.  There are multiple reasons for this, the first is that you don&amp;#8217;t have to worry about maintaining documentation in multiple locations, the second is there are some good tools that can be used to auto generate your documentation.  For example SQL Doc by Red  Gate can create a document in html, chm or doc format.&lt;/p&gt;

&lt;p&gt;There are two ways to add the definitions to the database.  The first way is through the SSMS GUI.  For example if you want to add the description for a column you right click on the table name and select Modify.  This will open the table definition in the GUI.  Select the column that you are going to add the description for.  In the lower window, (column properties) there will be an area to enter the description.  Add you description and save your changes.  I&amp;#8217;m not really a fan of this method for two reasons, first, it&amp;#8217;s very easy to make an error and say change a datatype without meaning to.  The second reason is I believe is every DBA should know the T-SQL behind the GUI.  It would also be faster to create one large script and run it all in at once.   In order to accomplish that you would use &lt;em&gt;sp_addextendedproperty&lt;/em&gt;, see BOL for the syntax and options for this procedure.  As you may have guessed, when you add a description to the database it stores them in the system table &lt;em&gt;sysproperties&lt;/em&gt;.  If you work at a company like mine where your database is in a constant state of development, then ask your developers to include &lt;em&gt;sp_addextendedproperty&lt;/em&gt; scripts with their DDL scripts.  This will cut down on the leg work you might have to do trying to figure out the description for each column.  &lt;/p&gt;

&lt;p&gt;Once you&amp;#8217;ve completed the discovery phase and clearly documented the database objects then it&amp;#8217;s time to create a diagram.  There are many tools on the market that can auto generate your diagrams for you.  I think one of the easier tools to use is Visio.   These tools will include table relationships IF you have created FKs in your database.  If you don&amp;#8217;t have those relationships defined then the process becomes a bit more involved as you will have to go back and identify those relationships. (That would be a whole new blog on the importance of using FKs)  Again, be as detailed as you can here.  Make sure you include the type of relationship, is it 1 to 1, 1 to many, many to 1 or many to many.  Without this information the developer(s) is at a serious disadvantage and must spend time to figure it out.  Depending on the number of tables in your database it may be too large to put it all in one diagram.  You may choose to diagram your db by module.  For example if you work in the Insurance Industry you may have some like Quotes, Policies, Claims, Documents and WorkFlow.  I would create diagram for each module with notation on how Quotes link to Policies, or Policies to Claims.&lt;/p&gt;

&lt;p&gt;The importance of this level of documentation speaks for itself.  Think how easy it would be to just hand a developer or new DBA a document and diagram to your Sales or Insurance database and say &amp;#8220;go to work.&amp;#8221;  The time saved in trying to figure everything out could add up to weeks.  And that is weeks of more production from them!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba-document-the-database&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>How many times have you started at a new company or been given a new database that you have to code for and you have no clue how the schema relates?  How much time is wasted trying to figure out that schema?  If you&#8217;re lucky you will be given a database that has at least been developed correctly with foreign keys and a document to accompany it.  If you&#8217;re not lucky, you&#8217;ve just been handed a database with 50,000 objects that you need to document.  Don&#8217;t be that DBA that hands off a database to someone else without an accompanying diagram and document that defines each table and object in plain English.  </p>

<p>There are a few tools and methods to get this done.  I&#8217;ll start with the best way to document your database.  First, write your definitions for each object in plain English.  You must write for a non-technical audience.  You never know who will end of up with your document.  The best location to store each object definition is right within the database.  There are multiple reasons for this, the first is that you don&#8217;t have to worry about maintaining documentation in multiple locations, the second is there are some good tools that can be used to auto generate your documentation.  For example SQL Doc by Red  Gate can create a document in html, chm or doc format.</p>

<p>There are two ways to add the definitions to the database.  The first way is through the SSMS GUI.  For example if you want to add the description for a column you right click on the table name and select Modify.  This will open the table definition in the GUI.  Select the column that you are going to add the description for.  In the lower window, (column properties) there will be an area to enter the description.  Add you description and save your changes.  I&#8217;m not really a fan of this method for two reasons, first, it&#8217;s very easy to make an error and say change a datatype without meaning to.  The second reason is I believe is every DBA should know the T-SQL behind the GUI.  It would also be faster to create one large script and run it all in at once.   In order to accomplish that you would use <em>sp_addextendedproperty</em>, see BOL for the syntax and options for this procedure.  As you may have guessed, when you add a description to the database it stores them in the system table <em>sysproperties</em>.  If you work at a company like mine where your database is in a constant state of development, then ask your developers to include <em>sp_addextendedproperty</em> scripts with their DDL scripts.  This will cut down on the leg work you might have to do trying to figure out the description for each column.  </p>

<p>Once you&#8217;ve completed the discovery phase and clearly documented the database objects then it&#8217;s time to create a diagram.  There are many tools on the market that can auto generate your diagrams for you.  I think one of the easier tools to use is Visio.   These tools will include table relationships IF you have created FKs in your database.  If you don&#8217;t have those relationships defined then the process becomes a bit more involved as you will have to go back and identify those relationships. (That would be a whole new blog on the importance of using FKs)  Again, be as detailed as you can here.  Make sure you include the type of relationship, is it 1 to 1, 1 to many, many to 1 or many to many.  Without this information the developer(s) is at a serious disadvantage and must spend time to figure it out.  Depending on the number of tables in your database it may be too large to put it all in one diagram.  You may choose to diagram your db by module.  For example if you work in the Insurance Industry you may have some like Quotes, Policies, Claims, Documents and WorkFlow.  I would create diagram for each module with notation on how Quotes link to Policies, or Policies to Claims.</p>

<p>The importance of this level of documentation speaks for itself.  Think how easy it would be to just hand a developer or new DBA a document and diagram to your Sales or Insurance database and say &#8220;go to work.&#8221;  The time saved in trying to figure everything out could add up to weeks.  And that is weeks of more production from them!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba-document-the-database">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba-document-the-database#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1021</wfw:commentRss>
		</item>
				<item>
			<title>The Productive DBA</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba</link>
			<pubDate>Mon, 22 Nov 2010 13:28:57 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>
<category domain="alt">Database Administration</category>			<guid isPermaLink="false">1020@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Over the past 12 years I&amp;#8217;ve received a lot of great suggestions from some very good DBAs on how to best be productive and organized.  One of the best pieces of advice I ever read was out of SQL Server magazine a few years back on how to be organized.  That advice was to create yourself a DBA repository!  What is a DBA repository you ask&amp;#8230; Well it&amp;#8217;s simple, it&amp;#8217;s the one single place where you keep ALL of the things you need to do your job, scripts, logs, executables, trace files, reports.  It&amp;#8217;s anything and everything you would use daily.  So what&amp;#8217;s my repository like?  I have a small server that I loaded all my diagnostic and SQL Tools on where I keep a share named DBA.  In that share I have the following folders, Executable, DR, Diagrams, Documents, SQL Scripts, SSAS, SSIS, SSRS, Trace, Bugs and Fixes and HA.  &lt;/p&gt;

&lt;p&gt;Some of the folders are obvious but let me go through a few of them.  In my executable folder I save every .exe file that I have purchased or downloaded.  I don&amp;#8217;t usually keep executables if we haven&amp;#8217;t installed them.  That cuts down on the size and old exe versions.   In the DR folder is everything I need for a successful DR cutover.  If you are in the middle of a disaster you won&amp;#8217;t look very good if you&amp;#8217;re googleing for scripts or instructions on how to failover your db to the DR server.  Having all that information at your fingertips will not only make you more productive but your boss will appreciate how effective you are.  &lt;/p&gt;

&lt;p&gt;Every script I write no matter how large or small is saved in the SQL Scripts folder by application.  I can&amp;#8217;t stress the importance of saving everything your write.  You never know when you will need that script or a version of it again.  You can save a ton of time if you don&amp;#8217;t have to rewrite scripts.  Also again, in an emergency you must have everything you&amp;#8217;ll need at your fingertips to react quickly and effectively.  I have a subfolder just dedicated to SQL Server perf mon scripts.  I use them daily!   In the SSAS, SSIS, SSRS folder I save all my projects from BIDS.  I have these folder linked to source control too so those projects are checked into SVN.  In the Bugs and Fixes folder I save everything from every issue I&amp;#8217;ve opened with Microsoft or other vendors.  This includes email conversations, scripts and the eventual resolution.  It makes correcting the problem much faster if it ever arises again.  The HA folder is everything I need to setup and maintain High Availability.&lt;/p&gt;


&lt;p&gt;The last thing I do on each database server is to setup a mapped drive to this share and create a local DBA share.  In the local DBA share I keep scripts that are specific to that database server.  Basically it&amp;#8217;s a smaller version of the DBA repository.&lt;/p&gt;

&lt;p&gt;The DBA repository has become my most valuable tool and has saved the day more than once.  Having the repository will help you keep a cool head in an emergency and help you get the answers you need quickly.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Over the past 12 years I&#8217;ve received a lot of great suggestions from some very good DBAs on how to best be productive and organized.  One of the best pieces of advice I ever read was out of SQL Server magazine a few years back on how to be organized.  That advice was to create yourself a DBA repository!  What is a DBA repository you ask&#8230; Well it&#8217;s simple, it&#8217;s the one single place where you keep ALL of the things you need to do your job, scripts, logs, executables, trace files, reports.  It&#8217;s anything and everything you would use daily.  So what&#8217;s my repository like?  I have a small server that I loaded all my diagnostic and SQL Tools on where I keep a share named DBA.  In that share I have the following folders, Executable, DR, Diagrams, Documents, SQL Scripts, SSAS, SSIS, SSRS, Trace, Bugs and Fixes and HA.  </p>

<p>Some of the folders are obvious but let me go through a few of them.  In my executable folder I save every .exe file that I have purchased or downloaded.  I don&#8217;t usually keep executables if we haven&#8217;t installed them.  That cuts down on the size and old exe versions.   In the DR folder is everything I need for a successful DR cutover.  If you are in the middle of a disaster you won&#8217;t look very good if you&#8217;re googleing for scripts or instructions on how to failover your db to the DR server.  Having all that information at your fingertips will not only make you more productive but your boss will appreciate how effective you are.  </p>

<p>Every script I write no matter how large or small is saved in the SQL Scripts folder by application.  I can&#8217;t stress the importance of saving everything your write.  You never know when you will need that script or a version of it again.  You can save a ton of time if you don&#8217;t have to rewrite scripts.  Also again, in an emergency you must have everything you&#8217;ll need at your fingertips to react quickly and effectively.  I have a subfolder just dedicated to SQL Server perf mon scripts.  I use them daily!   In the SSAS, SSIS, SSRS folder I save all my projects from BIDS.  I have these folder linked to source control too so those projects are checked into SVN.  In the Bugs and Fixes folder I save everything from every issue I&#8217;ve opened with Microsoft or other vendors.  This includes email conversations, scripts and the eventual resolution.  It makes correcting the problem much faster if it ever arises again.  The HA folder is everything I need to setup and maintain High Availability.</p>


<p>The last thing I do on each database server is to setup a mapped drive to this share and create a local DBA share.  In the local DBA share I keep scripts that are specific to that database server.  Basically it&#8217;s a smaller version of the DBA repository.</p>

<p>The DBA repository has become my most valuable tool and has saved the day more than once.  Having the repository will help you keep a cool head in an emergency and help you get the answers you need quickly.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-productive-dba#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1020</wfw:commentRss>
		</item>
				<item>
			<title>Upgrading the DBA</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/upgrading-the-dba</link>
			<pubDate>Thu, 18 Nov 2010 12:00:17 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Data Modelling &amp; Design</category>
<category domain="alt">Database Administration</category>			<guid isPermaLink="false">1015@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;It&amp;#8217;s that time of year again to make sure we spend all the money in the training budget. Use it or lose it right!  So, after a quick look at the upcoming projects on the white board, I decided it was time to upgrade my skill set in the area of BI.  I&amp;#8217;ve signed up for &amp;#8220;Implementing and Maintaining SQL Server 2008 Analysis Services and Business Intelligence Solutions&amp;#8221;.  The class is being taught by Global Knowledge up in Boston for 5 days and covers the following;&lt;br /&gt;
&amp;#8226;	How SQL Server Analysis Services can be used to implement analytical solutions&lt;br /&gt;
&amp;#8226;	Create multidimensional analysis solutions with SQL Server Analysis Services&lt;br /&gt;
&amp;#8226;	Implement dimensions and cubes in an Analysis Services solution&lt;br /&gt;
&amp;#8226;	Implement measures and measure groups in an Analysis Services solution&lt;br /&gt;
&amp;#8226;	Query a multidimensional Analysis Services solution&lt;br /&gt;
&amp;#8226;	Customize an Analysis Services cube&lt;br /&gt;
&amp;#8226;	Deploy and secure an Analysis Services database&lt;br /&gt;
&amp;#8226;	Maintain a multidimensional Analysis Services solution&lt;br /&gt;
&amp;#8226;	Implement a Data Mining solution&lt;br /&gt;
&amp;#8226;	Tune SSAS cubes&lt;br /&gt;
&amp;#8226;	Design SSAS for performance&lt;br /&gt;
&amp;#8226;	Load Data Warehouse solutions using SSIS&lt;br /&gt;
&amp;#8226;	Create and implement Reporting Solutions using SQL Server Reporting Services&lt;br /&gt;
&amp;#8226;	Integrate SSAS with Microsoft Excel&lt;br /&gt;
&amp;#8226;	Create Excel Reports against cubes&lt;br /&gt;
&amp;#8226;	Expose cubes in a Sharepoint environment&lt;br /&gt;
They use SQL 2008 R2 for this class so it will be nice to get some exposure to that as well.&lt;br /&gt;
Stay tuned for upcoming blogs about what the class has to offer and my experiences there!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/upgrading-the-dba&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>It&#8217;s that time of year again to make sure we spend all the money in the training budget. Use it or lose it right!  So, after a quick look at the upcoming projects on the white board, I decided it was time to upgrade my skill set in the area of BI.  I&#8217;ve signed up for &#8220;Implementing and Maintaining SQL Server 2008 Analysis Services and Business Intelligence Solutions&#8221;.  The class is being taught by Global Knowledge up in Boston for 5 days and covers the following;<br />
&#8226;	How SQL Server Analysis Services can be used to implement analytical solutions<br />
&#8226;	Create multidimensional analysis solutions with SQL Server Analysis Services<br />
&#8226;	Implement dimensions and cubes in an Analysis Services solution<br />
&#8226;	Implement measures and measure groups in an Analysis Services solution<br />
&#8226;	Query a multidimensional Analysis Services solution<br />
&#8226;	Customize an Analysis Services cube<br />
&#8226;	Deploy and secure an Analysis Services database<br />
&#8226;	Maintain a multidimensional Analysis Services solution<br />
&#8226;	Implement a Data Mining solution<br />
&#8226;	Tune SSAS cubes<br />
&#8226;	Design SSAS for performance<br />
&#8226;	Load Data Warehouse solutions using SSIS<br />
&#8226;	Create and implement Reporting Solutions using SQL Server Reporting Services<br />
&#8226;	Integrate SSAS with Microsoft Excel<br />
&#8226;	Create Excel Reports against cubes<br />
&#8226;	Expose cubes in a Sharepoint environment<br />
They use SQL 2008 R2 for this class so it will be nice to get some exposure to that as well.<br />
Stay tuned for upcoming blogs about what the class has to offer and my experiences there!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/upgrading-the-dba">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/upgrading-the-dba#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=1015</wfw:commentRss>
		</item>
				<item>
			<title>How to Monitor Database Mirroring</title>
			<link>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/how-to-monitor-database-mirroring</link>
			<pubDate>Thu, 15 Oct 2009 10:41:06 +0000</pubDate>			<dc:creator>ptheriault</dc:creator>
			<category domain="main">Database Administration</category>			<guid isPermaLink="false">629@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;This morning I came into work and went through my usual 100 or so emails.  One of the emails was from MSSQLTips.com, it was on how to monitor SQL Server Database mirroring with email alerts. By Alan Cranfield.  While agree with Alan that every DBA should monitor their database mirroring with email alerts I disagreed with his method.  He had the DBA create a job that was scheduled to run at some interval throughout the day.  His job would query the sys.database_mirroring view.  As DBAs we need to know immediately when something fails or changes.  5 minutes could be the difference between a quick fix and restoring a 500 GB db mirror.  &lt;/p&gt;

&lt;p&gt;So what would be a better way to monitor and alert a DBA when there is a change in the state of Database mirroring?  I prefer to use Alerts  for events.  Event notifications can be created directly in the SQL Server Database Engine or by using the WMI Provider for Server Events.  A DBA can specify which db mirroring event they wish to moitor.  Here is a table of events to monitor for:&lt;/p&gt;

&lt;table style=&quot;border:1pt solid #000;&quot;&gt;
&lt;tr style=&quot;background-color:#CCCCCC;&quot;&gt;
&lt;th style=&quot;border:1pt solid #000;&quot;&gt;State&lt;/th&gt;&lt;th style=&quot;border:1pt solid #000;&quot;&gt;Name&lt;/th&gt;&lt;th style=&quot;border:1pt solid #000;&quot;&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;0&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Null Notification&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs briefly when a mirroring session is started.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;1&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronized Principal with Witness&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal when the principal and mirror are connected and synchronized and the principal and witness are connected. For a mirroring configuration with a witness, this is the normal operating state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;2&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronized Principal without Witness&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal when the principal and mirror are connected and synchronized but the principal does not have a connection to the witness. For a mirroring configuration without a witness, this is the normal operating state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;3&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronized Mirror with Witness&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the mirror when the principal and mirror are connected and synchronized and the mirror and witness are connected. For a mirroring configuration with a witness, this is the normal operating state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;4&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronized Mirror without Witness&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the mirror when the principal and mirror are connected and synchronized but the mirror does not have a connection to the witness. For a mirroring configuration without a witness, this is the normal operating state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;5&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Connection with Principal Lost&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the mirror server instance when it cannot connect to the principal.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;6&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Connection with Mirror Lost&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal server instance when it cannot connect to the mirror.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;7&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Manual Failover&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal server instance when the user fails over manually from the principal, or on the mirror server instance when a force service is executed at the mirror.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;8&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Automatic Failover&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the mirror server instance when the operating mode is high safety with automatic failover (synchronous) and the mirror and witness server instances cannot connect to the principal server instance.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;9&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Mirroring Suspended&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on both partner instances when the user suspends (pauses) the mirroring session or when the mirror server instance encounters an error. It also occurs on the mirror server instance following a force service command. When the mirror comes online as the principal, mirroring is automatically suspended.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;10&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;No Quorum&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;If a witness is configured, this state occurs on the principal or mirror server instance when it cannot connect to its partner or to the witness server instance.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;11&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronizing Mirror&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the mirror server instance when there is a backlog of unsent log. The status of the session is Synchronizing.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;12&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Principal Running Exposed&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal server instance when the operating mode is high protection (synchronous) and the principal cannot connect to the mirror server instance.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;13&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Synchronizing Principal&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;This state occurs on the principal server instance when there is a backlog of unsent log. The status of the &lt;/td&gt;&lt;/tr&gt;

&lt;/table&gt;

&lt;p&gt;Now that we know the Event and the State here is how to add an Alert to notify you that the state of DB mirroring has changed.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb64147&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;msdb&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #00AF00;&quot;&gt;/****** Object: &amp;nbsp;Alert [DBM State Change] &amp;nbsp; &amp;nbsp;Script Date: 10/15/2009 08:03:20 ******/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; msdb.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;sp_add_alert&lt;/span&gt; @name=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;DBM State Change&#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @message_id=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @severity=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @enabled=&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @delay_between_responses=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @include_event_description_in=&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @category_name=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;[Uncategorized]&#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @wmi_namespace=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER&#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @wmi_query=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;SELECT * FROM DATABASE_MIRRORING_STATE_CHANGE WHERE State = 6 &#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @job_id=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;00000000-0000-0000-0000-000000000000&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb18848&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is an alert that I created on the principal server.  I also have created a similar alert on the mirror server where I look for state = 5.  These two alerts will notify me if the connection between the Principal and Mirror is lost due to network or some other failure.  &lt;br /&gt;
To receive notification when this event happens it is simple to just create an operator and have the event email the operator if and when the event conditions are met.&lt;/p&gt;

&lt;p&gt;What other Mirror Events should every DBA monitor?  I find the unsent and unrestored log to be two very import  events to receive notifications for.  For those events just simply create a new event for the event ID in the table below and set you monitor threshold.&lt;/p&gt;

&lt;table style=&quot;border:1pt solid #000;&quot;&gt;
&lt;tr style=&quot;background-color:#CCCCCC;&quot;&gt;
&lt;th style=&quot;border:1pt solid #000;&quot;&gt;Database Mirroring Monitor warning&lt;/th&gt;&lt;th style=&quot;border:1pt solid #000;&quot;&gt;Event name&lt;/th&gt;&lt;th style=&quot;border:1pt solid #000;&quot;&gt;Event ID&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Warn if the unsent log exceeds the threshold&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Unsent log&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;32042&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Warn if the unrestored log exceeds the threshold&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Unrestored log&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;32043&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Warn if the age of the oldest unsent transaction exceeds the threshold&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Oldest unsent transaction&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;32044&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Warn if the mirror commit overhead exceeds the threshold&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;Mirror commit overhead&lt;/td&gt;&lt;td style=&quot;border:1pt solid #CCC;&quot;&gt;32045&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;You can also script this by using sp_add_alert as follows:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;tsql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;tsql&quot; id=&quot;cb9072&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;USE&lt;/span&gt; &lt;span style=&quot;color: #808080;&quot;&gt;&amp;#91;&lt;/span&gt;msdb&lt;span style=&quot;color: #808080;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #00AF00;&quot;&gt;/****** Object: &amp;nbsp;Alert [DB Mirroring Unsent Log Warning] &amp;nbsp; &amp;nbsp;Script Date: 10/15/2009 08:14:29 ******/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;EXEC&lt;/span&gt; msdb.&lt;span style=&quot;color: #202020;&quot;&gt;dbo&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;sp_add_alert&lt;/span&gt; @name=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;DB Mirroring Unsent Log Warning&#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @message_id=&lt;span style=&quot;color: #000;&quot;&gt;32042&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @severity=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @enabled=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @delay_between_responses=&lt;span style=&quot;color: #000;&quot;&gt;0&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @include_event_description_in=&lt;span style=&quot;color: #000;&quot;&gt;1&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @category_name=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;[Uncategorized]&#039;&lt;/span&gt;, &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @job_id=N&lt;span style=&quot;color: #FF0000;&quot;&gt;&#039;00000000-0000-0000-0000-000000000000&#039;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb32165&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Good Luck and Happy monitoring!&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/how-to-monitor-database-mirroring&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>This morning I came into work and went through my usual 100 or so emails.  One of the emails was from MSSQLTips.com, it was on how to monitor SQL Server Database mirroring with email alerts. By Alan Cranfield.  While agree with Alan that every DBA should monitor their database mirroring with email alerts I disagreed with his method.  He had the DBA create a job that was scheduled to run at some interval throughout the day.  His job would query the sys.database_mirroring view.  As DBAs we need to know immediately when something fails or changes.  5 minutes could be the difference between a quick fix and restoring a 500 GB db mirror.  </p>

<p>So what would be a better way to monitor and alert a DBA when there is a change in the state of Database mirroring?  I prefer to use Alerts  for events.  Event notifications can be created directly in the SQL Server Database Engine or by using the WMI Provider for Server Events.  A DBA can specify which db mirroring event they wish to moitor.  Here is a table of events to monitor for:</p>

<table style="border:1pt solid #000;">
<tr style="background-color:#CCCCCC;">
<th style="border:1pt solid #000;">State</th><th style="border:1pt solid #000;">Name</th><th style="border:1pt solid #000;">Description</th>
</tr>
<tr>
<td style="border:1pt solid #CCC;">0</td><td style="border:1pt solid #CCC;">Null Notification</td><td style="border:1pt solid #CCC;">This state occurs briefly when a mirroring session is started.</td>
</tr>
<tr>
<td style="border:1pt solid #CCC;">1</td><td style="border:1pt solid #CCC;">Synchronized Principal with Witness</td><td style="border:1pt solid #CCC;">This state occurs on the principal when the principal and mirror are connected and synchronized and the principal and witness are connected. For a mirroring configuration with a witness, this is the normal operating state.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">2</td><td style="border:1pt solid #CCC;">Synchronized Principal without Witness</td><td style="border:1pt solid #CCC;">This state occurs on the principal when the principal and mirror are connected and synchronized but the principal does not have a connection to the witness. For a mirroring configuration without a witness, this is the normal operating state.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">3</td><td style="border:1pt solid #CCC;">Synchronized Mirror with Witness</td><td style="border:1pt solid #CCC;">This state occurs on the mirror when the principal and mirror are connected and synchronized and the mirror and witness are connected. For a mirroring configuration with a witness, this is the normal operating state.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">4</td><td style="border:1pt solid #CCC;">Synchronized Mirror without Witness</td><td style="border:1pt solid #CCC;">This state occurs on the mirror when the principal and mirror are connected and synchronized but the mirror does not have a connection to the witness. For a mirroring configuration without a witness, this is the normal operating state.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">5</td><td style="border:1pt solid #CCC;">Connection with Principal Lost</td><td style="border:1pt solid #CCC;">This state occurs on the mirror server instance when it cannot connect to the principal.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">6</td><td style="border:1pt solid #CCC;">Connection with Mirror Lost</td><td style="border:1pt solid #CCC;">This state occurs on the principal server instance when it cannot connect to the mirror.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">7</td><td style="border:1pt solid #CCC;">Manual Failover</td><td style="border:1pt solid #CCC;">This state occurs on the principal server instance when the user fails over manually from the principal, or on the mirror server instance when a force service is executed at the mirror.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">8</td><td style="border:1pt solid #CCC;">Automatic Failover</td><td style="border:1pt solid #CCC;">This state occurs on the mirror server instance when the operating mode is high safety with automatic failover (synchronous) and the mirror and witness server instances cannot connect to the principal server instance.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">9</td><td style="border:1pt solid #CCC;">Mirroring Suspended</td><td style="border:1pt solid #CCC;">This state occurs on both partner instances when the user suspends (pauses) the mirroring session or when the mirror server instance encounters an error. It also occurs on the mirror server instance following a force service command. When the mirror comes online as the principal, mirroring is automatically suspended.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">10</td><td style="border:1pt solid #CCC;">No Quorum</td><td style="border:1pt solid #CCC;">If a witness is configured, this state occurs on the principal or mirror server instance when it cannot connect to its partner or to the witness server instance.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">11</td><td style="border:1pt solid #CCC;">Synchronizing Mirror</td><td style="border:1pt solid #CCC;">This state occurs on the mirror server instance when there is a backlog of unsent log. The status of the session is Synchronizing.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">12</td><td style="border:1pt solid #CCC;">Principal Running Exposed</td><td style="border:1pt solid #CCC;">This state occurs on the principal server instance when the operating mode is high protection (synchronous) and the principal cannot connect to the mirror server instance.</td></tr>
<tr>
<td style="border:1pt solid #CCC;">13</td><td style="border:1pt solid #CCC;">Synchronizing Principal</td><td style="border:1pt solid #CCC;">This state occurs on the principal server instance when there is a backlog of unsent log. The status of the </td></tr>

</table>

<p>Now that we know the Event and the State here is how to add an Alert to notify you that the state of DB mirroring has changed.</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb75965'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb75965','cb11716'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb75965" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>msdb<span style="color: #808080;">&#93;</span></li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #00AF00;">/****** Object: &nbsp;Alert [DBM State Change] &nbsp; &nbsp;Script Date: 10/15/2009 08:03:20 ******/</span></li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> msdb.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">sp_add_alert</span> @name=N<span style="color: #FF0000;">'DBM State Change'</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @message_id=<span style="color: #000;">0</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @severity=<span style="color: #000;">0</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @enabled=<span style="color: #000;">1</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @delay_between_responses=<span style="color: #000;">0</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @include_event_description_in=<span style="color: #000;">1</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @category_name=N<span style="color: #FF0000;">'[Uncategorized]'</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @wmi_namespace=N<span style="color: #FF0000;">'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER'</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @wmi_query=N<span style="color: #FF0000;">'SELECT * FROM DATABASE_MIRRORING_STATE_CHANGE WHERE State = 6 '</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @job_id=N<span style="color: #FF0000;">'00000000-0000-0000-0000-000000000000'</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb11716" style="display: none; color: red;"></div></div></div>

<p>This is an alert that I created on the principal server.  I also have created a similar alert on the mirror server where I look for state = 5.  These two alerts will notify me if the connection between the Principal and Mirror is lost due to network or some other failure.  <br />
To receive notification when this event happens it is simple to just create an operator and have the event email the operator if and when the event conditions are met.</p>

<p>What other Mirror Events should every DBA monitor?  I find the unsent and unrestored log to be two very import  events to receive notifications for.  For those events just simply create a new event for the event ID in the table below and set you monitor threshold.</p>

<table style="border:1pt solid #000;">
<tr style="background-color:#CCCCCC;">
<th style="border:1pt solid #000;">Database Mirroring Monitor warning</th><th style="border:1pt solid #000;">Event name</th><th style="border:1pt solid #000;">Event ID</th>
</tr>
<tr>
<td style="border:1pt solid #CCC;">Warn if the unsent log exceeds the threshold</td><td style="border:1pt solid #CCC;">Unsent log</td><td style="border:1pt solid #CCC;">32042</td></tr>
<tr>
<td style="border:1pt solid #CCC;">Warn if the unrestored log exceeds the threshold</td><td style="border:1pt solid #CCC;">Unrestored log</td><td style="border:1pt solid #CCC;">32043</td></tr>
<tr>
<td style="border:1pt solid #CCC;">Warn if the age of the oldest unsent transaction exceeds the threshold</td><td style="border:1pt solid #CCC;">Oldest unsent transaction</td><td style="border:1pt solid #CCC;">32044</td></tr>
<tr>
<td style="border:1pt solid #CCC;">Warn if the mirror commit overhead exceeds the threshold</td><td style="border:1pt solid #CCC;">Mirror commit overhead</td><td style="border:1pt solid #CCC;">32045</td></tr>
</table>

<p>You can also script this by using sp_add_alert as follows:</p>

<div class="codebox"><div class="codeheader"><span>tsql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb15961'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb15961','cb80985'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="tsql" id="cb15961" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>msdb<span style="color: #808080;">&#93;</span></li><li style="" class="li2"><span style="color: #0000FF;">GO</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #00AF00;">/****** Object: &nbsp;Alert [DB Mirroring Unsent Log Warning] &nbsp; &nbsp;Script Date: 10/15/2009 08:14:29 ******/</span></li><li style="" class="li1"><span style="color: #0000FF;">EXEC</span> msdb.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">sp_add_alert</span> @name=N<span style="color: #FF0000;">'DB Mirroring Unsent Log Warning'</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @message_id=<span style="color: #000;">32042</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @severity=<span style="color: #000;">0</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @enabled=<span style="color: #000;">0</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @delay_between_responses=<span style="color: #000;">0</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @include_event_description_in=<span style="color: #000;">1</span>, </li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; @category_name=N<span style="color: #FF0000;">'[Uncategorized]'</span>, </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; @job_id=N<span style="color: #FF0000;">'00000000-0000-0000-0000-000000000000'</span></li><li style="" class="li1"><span style="color: #0000FF;">GO</span></li></ol></div><div id="cb80985" style="display: none; color: red;"></div></div></div>

<p>Good Luck and Happy monitoring!</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/how-to-monitor-database-mirroring">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/how-to-monitor-database-mirroring#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DataMgmt/?tempskin=_rss2&#38;disp=comments&#38;p=629</wfw:commentRss>
		</item>
			</channel>
</rss>
