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

<channel>
	<title>Jonathan Gardner &#187; SQL Server</title>
	<atom:link href="http://www.jonathanagardner.com/tag/sql-server/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jonathanagardner.com</link>
	<description>Drinking from the Information Fire Hose</description>
	<lastBuildDate>Thu, 19 Jan 2012 23:20:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SRS Double Hop Authentication</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/srs-double-hop-authentication.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/srs-double-hop-authentication.html#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:35:25 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Reporting]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/?p=1041</guid>
		<description><![CDATA[I was recently asked by a client to architect a data and reporting environment.  Part of the business requirements was separation of the production database server and the reporting services server.   Another part of the business requirements stated that the reports were to leverage a shared data source and Windows Authentication.  While none of the [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I was recently asked by a client to architect a data and reporting environment.  Part of the business requirements was separation of the production database server and the reporting services server.   Another part of the business requirements stated that the reports were to leverage a shared data source and Windows Authentication.  While none of the business requirements were a problem for the SQL Server 2008 R2 environment I was creating, there was an issue with the double hop authentication.  I struggled to find a guide to setting this up in the BOL or on any of the usual blog suspects.  After opening a case with Microsoft I finally got all the information.</p>

<h1>Architecture</h1>

<p>This article will cover implementation of a 3-Tier SQL Server 2008 R2 reporting services installation.  For this discussion the database will be running on SQL01.  Reporting Services will be running on SRS01, and the client consuming the reports will be a local workstation LAPPY386.</p>

<h1>Reporting Services Configuration</h1>

<p><strong><em>NOTE</em></strong>: This article assumes that Microsoft best practices were followed and the SQL Server services are running under domain accounts.</p>

<p>To use double hop authentication, SRS uses Kerberos authentication.  This is not enabled by default in the reporting services configuration.  It is added to the reporting services configuration file.  For a default installation the file is C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\rsreportserver.config.  Edit this file in notepad and add thetag in the authentication section.  Once the file is modified it should look like the section below.
<pre><code>&lt;AuthenticationTypes&gt;; &lt;RSWindowsNegotiate /&gt;; &lt;RSWindowsNTLM /&gt;; &lt;/AuthenticationTypes&gt; </code></pre>
Modifications to the Reporting Services configuration file requires a restart of the services to take effect.</p>

<h1>Service Principal Names</h1>

<p>This article is not about SPNs so I won’t go into detail about them.  In short, they help facilitate authentication for a service when it executes.   You can find more information about SPNs in the Books Online <a href="http://technet.microsoft.com/en-us/library/cc961723.aspx">here</a>.</p>

<p>Without the SPNs set properly the following error is a common issue:
<pre><code> An error has occurred during report processing. (rsProcessingAborted)      Cannot create a connection to data source 'Datasource'. (rsErrorOpeningConnection) </code><code>          Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.</code></pre>
<span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">SPNs need to be set on the SQL Server, SQL01, and the Reporting Server, SRS01.   Setting a SPN is done through the SetSPN.exe tool run from the command line.  The URL of the SPN needs to be set the same way the data source will be configured.  For good measure, always enter both the short name and the FQDN to make sure that it will function if someone comes behind me and creates a data source with either server name.  The URL needs to be set with the proper port number.  Below the default SQL Server port is used but for a named instance or non-default port this will need to be adjusted accordingly.  A port number only needs to be specified for the SRS http SPN when a non standard port is used.  The SPN is set for the service account that is being used.</span></p>

<p>On SQL01:
<pre>SetSPN –A mssql/sql01:1433 domain\SQLServiceAcct</pre>
And
<pre>SetSPN –A mssql/sql01.domain.local:1433 domain\SQLServiceAcct</pre>
ON SRS01
<pre>SetSPN –A http/srs01 domain\SRSServiceAcct<span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"> </span></pre>
<pre>SetSPN –A http/srs.01.domain.local domain\SRSServiceAcct</pre>
A restart of the SQL Server or Reporting Server services is not required for the SPN to take effect but it will have to propagate throughout the domain.  The frequency of this varies.  If you are an Enterprise Administrator and want to force this replication in your domain, information to do that can be found <a href="http://technet.microsoft.com/en-us/library/cc816926(WS.10).aspx">here</a>.</p>

<p>To ensure that the SPN has been configured correctly for each account the SetSPN command is able to list all SPNs set for a service account.
<pre>SetSPN –L domain\account</pre>
It also can check the entire domain for duplicate SPN entries.
<pre>SetSPN –X</pre>
<pre><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">With all of this in place the double hop authentication should now be working.</span></pre>
<pre><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">UPDATED:</span></pre>
<pre><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">Vijay Krishnan (<a href="http://montagepages.fuselabs.com/public/VijayKrishnan/sqlserverreportingservices/fd3e3efa-cf8a-4867-be5f-2bb14bf38c23.htm">Blog</a> | <a href="https://twitter.com/#!/vijayreports">Twitter</a> ) pointed out something I was missing in this guide.  </span></pre></p>

<h1><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">Account Delegation</span></h1>

<p><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"> The service account domain\account needs to be configured for Kerberos Delegation. The configuration needs to be set on the service account in Active Directory.  See the image below for the setting. </span></p>

<p><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;"><a href="http://www.jonathanagardner.com/wp-content/uploads/2011/09/Delegation.jpg"><img class="alignnone size-thumbnail wp-image-1047" title="Delegation" src="http://www.jonathanagardner.com/wp-content/uploads/2011/09/Delegation-150x150.jpg" alt="User Delegation Configuration" width="150" height="150" /></a></span></p>

<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/srs-double-hop-authentication.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQLSaturday #57, Houston</title>
		<link>http://www.jonathanagardner.com/training/sqlsaturday-57-houston.html</link>
		<comments>http://www.jonathanagardner.com/training/sqlsaturday-57-houston.html#comments</comments>
		<pubDate>Fri, 23 Jul 2010 20:51:09 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLSaturday]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/training/sqlsaturday-57-houston.html</guid>
		<description><![CDATA[As Cochair of the planning committee I am very pleased to announce that we are officially having a SQLSaturday in Houston. The event will be on January 29th, 2011 at the Bammel Church of Christ. Co Chairs Jonathan Gardner (Blog&#124;Twitter) Malik Al-Amin (Blog&#124;Twitter) Nancy Hidy Wilson (Twitter) Information We have created a Twitter account @SQLSatHou [...]]]></description>
			<content:encoded><![CDATA[<p><a class="post_image_link" href="http://www.jonathanagardner.com/training/sqlsaturday-57-houston.html" title="Permanent link to SQLSaturday #57, Houston"><img class="post_image alignnone frame" src="http://www.jonathanagardner.com/wp-content/uploads/2010/07/sqlsat57_transparent.png.jpg" width="220" height="90" alt="Post image for SQLSaturday #57, Houston" /></a>
</p><p>As Cochair of the planning committee I am very pleased to announce that we are officially having a SQLSaturday in Houston.  The event will be on January 29th, 2011 at the Bammel Church of Christ.</p>

<h2>Co Chairs</h2>

<p>Jonathan Gardner (<a href="http://www.jonathanagardner.com">Blog</a>|<a href="http://twitter.com/jgardner04">Twitter</a>)</p>

<p>Malik Al-Amin (<a href="http://www.fortitudeconsulting.biz/">Blog</a>|<a href="http://twitter.com/Malik_Alamin">Twitter</a>)</p>

<p>Nancy Hidy Wilson (<a href="http://twitter.com/NancyHidyWilson">Twitter</a>)</p>

<h2>Information</h2>

<p>We have created a Twitter account <a href="http://twitter.com/SQLSatHou">@SQLSatHou</a> to distribute information.  Please use the hastag #SQLSat57 when discussing the event and it will show up on the official SQLSaturday site.</p>

<p>The official SQLSaturday #57, Houston website is <a href="http://sqlsaturday.com/57/eventhome.aspx">here</a>.</p>

<h2>Volunteers</h2>

<p>We are always looking for people to help out.  On the registration page there is a section to volunteer.  I would highly encourage everyone to do this.  While my motives are a bit selfish, it is really a great way to network with other volunteers and give back.  If that is not enough, check out David&#8217;s Post on <a href="http://www.made2mentor.com/2010/05/five-reasons-you-should-volunteer-with-your-local-sql-user-group-and-host-a-sql-saturday/">Five Reasons You Should Volunteer with Your Local SQL User Group and Host a SQL Saturday</a></p>

<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/training/sqlsaturday-57-houston.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Model to Change Default Database Settings</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/using-model-to-change-default-database-settings.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/using-model-to-change-default-database-settings.html#comments</comments>
		<pubDate>Mon, 12 Apr 2010 19:35:37 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/technology/sql/using-model-to-change-default-database-settings.html</guid>
		<description><![CDATA[During a Twitter conversation today Malik Alamin (Twitter) asked about the Autogrow settings on his databases. The conversation naturally progressed to the question of how you change the default behavior and set all newly created databases to have user defined settings. Brent Ozar (Blog &#124; Twitter) was able to point us in the right direction [...]]]></description>
			<content:encoded><![CDATA[<p></p><p style="clear: both;">During a Twitter conversation today Malik Alamin (<a href="http://twitter.com/Malik_Alamin/" target="_blank">Twitter</a>) asked about the Autogrow settings on his databases. The conversation naturally progressed to the question of how you change the default behavior and set all newly created databases to have user defined settings. Brent Ozar (<a href="http://www.brentozar.com/" target="_blank">Blog</a> | <a href="http://twitter.com/brento" target="_blank">Twitter</a>) was able to point us in the right direction to find a solution.  Modifying the model database.</p>

<h2>About the model Database</h2>

<p style="clear: both;">When a new database is created either by using the CREATE DATABASE statement, that mean via SSMS as well, the model database is used as a template. This means that change made to the model database settings, including tables, permissions, stored procedures, and functions will all transfer over to the newly created database.</p>

<p style="clear: both;">According to the TechNet article about the model database some file sizes may look different depending on what version of SQL Server is installed.  Also, there are some things that cannot be modified in the model database. Items like CHANGE_TRACKING, ENCRYPTION, and TRUSTWORTY cannot be modified. A full list of restrictions can be found in the <a href="http://technet.microsoft.com/en-us/library/ms186388.aspx" target="_blank">TechNet Article</a>.</p>

<h2>Example</h2>

<p style="clear: both;">I need to set the auto grow on my data file to Autogrow by 10% instead of 1 MB as was the default on my instance. I can run the ALTER DATABASE command or use SSMS against the model database</p>

<blockquote style="clear: both;">USE [master]
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N&#8217;modeldev&#8217;, FILEGROWTH = 10%)
GO
USE [master]
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N&#8217;modeldev&#8217;, FILEGROWTH = 10%)
GO</blockquote>

<p style="clear: both;"><a class="image-link" href="http://www.jonathanagardner.com/wp-content/uploads/2010/04/L2535-TABLET.HMS-CORP.HANOVERMEASUREMENT.COM_.jpg"><img class="linked-to-original" style="text-align: center; display: block; margin: 0 auto 10px;" src="http://www.jonathanagardner.com/wp-content/uploads/2010/04/L2535-TABLET-thumb.HMS-CORP.HANOVERMEASUREMENT.COM_.jpg" alt="" width="379" height="324" /></a>Making these changes will alter all newly created databases to have the same settings.</p>

<p>Note: Jorge Segarra (<a href="http://sqlchicken.com/" target="_blank">Blog</a> | <a href="http://twitter.com/SQLChicken/" target="_blank">Twitter</a>) pointed out that this does NOT work in a SharePoint environment.  SharePoint does not use the model database when it creates new site databases.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/using-model-to-change-default-database-settings.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Features Visual Studio 2010 Offers DBAs and Database Devs</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/what-features-visual-studio-2010-offer-dbas-and-database-devs.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/what-features-visual-studio-2010-offer-dbas-and-database-devs.html#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:00:23 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/2010/04/08/what-features-visual-studio-2010-offer-dbas-and-database-devs/</guid>
		<description><![CDATA[I was recently reviewing some the change management and document control policies that governs our IT group. While I have been confirming to these change management policies I started to think back on how we make our developers work with code. We have deployed a Team Foundation Server 2010 and are using it for source [...]]]></description>
			<content:encoded><![CDATA[<p></p><p style="clear: both;"><a class="image-link" href="http://www.jonathanagardner.com/wp-content/uploads/2010/04/visual_studio_logo-full.png"><img class="linked-to-original" style="display: inline; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px;" src="http://www.jonathanagardner.com/wp-content/uploads/2010/04/visual_studio_logo-thumb1.png" alt="" width="214" height="32" align="left" /></a>I was recently reviewing some the change management and document control policies that governs our IT group. While I have been confirming to these change management policies I started to think back on how we make our developers work with code.</p>

<p style="clear: both;"></p>

<div>We have deployed a Team Foundation Server 2010 and are using it for source control and remote build functionalities. We require all source code to be managed and maintained on the TFS. We also work with a Test Driven Development philosophy creating Unit Testing to ensure code integrity as members of the team work on different aspects of an application.</div>

<p style="clear: both;">It seems that we were holding our database developers (i.e. me) and our application developers to two different standards. This article is the first in a series to explore what Visual Studio 2010 and TFS 2010 has to offer for Database Developers and DBAs.</p>

<p style="clear: both;">These topics will include but not be limited to:</p>

<ul style="clear: both;">
    <li>Database Deployment</li>
    <li>Database Change Management</li>
    <li>Database Unit Testing</li>
    <li>Database Test Data Generation</li>
    <li>Data Access</li>
    <li>Version Control</li>
    <li>Build Automation</li>
</ul>

<p style="clear: both;">Some of these features are only available in certain versions of Visual Studio and/or only available via TFS. I will outline and note these feature when we cross them. Keep an eye out for our first article on Database Deployment next week.</p>

<p><br class="final-break" style="clear: both;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/what-features-visual-studio-2010-offer-dbas-and-database-devs.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Joins instead of Sub Queries: a Case Study</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/using-joins-instead-of-sub-queries-a-case-study.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/using-joins-instead-of-sub-queries-a-case-study.html#comments</comments>
		<pubDate>Thu, 10 Dec 2009 21:45:24 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/?p=437</guid>
		<description><![CDATA[During a recent upgrade from SQL 2000 to SQL 2005 some poorly written code was exposed on a custom web application.  Users and developers started reporting that their applications were timing out.  One of the queries I posted in the Execution Plan Challenge.  Another exposed query involved a sub query.]]></description>
			<content:encoded><![CDATA[<p></p><div class="wlWriterHeaderFooter" style="float: right; margin: 0px; padding: 0px 0px 4px 8px;"><script type="text/javascript">// <![CDATA[
digg_url = "http://www.jonathanagardner.com/?p=437";digg_title = "Using Joins instead of Sub Queries: a Case Study";digg_bgcolor = "#EBEFF2";digg_skin = "normal";
// ]]&gt;</script><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><script type="text/javascript">// <![CDATA[
digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;
// ]]&gt;</script></div>

<p>During a recent upgrade from SQL 2000 to SQL 2005 some poorly written code was exposed on a custom web application.  Users and developers started reporting that their applications were timing out.  One of the queries I posted in the <a href="http://www.jonathanagardner.com/2009/12/02/execution-plan-challenge/" target="_blank">Execution Plan Challenge</a>.  Another exposed query involved a sub query.
<pre class="code">    <span style="color: blue;">FROM
        </span>SUM_METER_DAILY a<span style="color: gray;">,
        </span>METER_MASTER b<span style="color: gray;">,
        </span>MS_METER c
    <span style="color: blue;">WHERE
        </span>b<span style="color: gray;">.</span>METER_ID <span style="color: gray;">IN (</span><span style="color: blue;">SELECT DISTINCT </span>d<span style="color: gray;">.</span>METER_ID
            <span style="color: blue;">FROM </span>LINE_SEGMENT_DETAIL d
            <span style="color: blue;">WHERE </span>d<span style="color: gray;">.</span>LINE_SEGMENT <span style="color: gray;">= </span>@LINESEG<span style="color: gray;">)</span></pre>
<a href="http://www.jonathanagardner.com/wp-content/uploads/2009/12/SELECT_DISTINCT88Percent.png"><img style="display: inline; margin-left: 0px; margin-right: 0px; border-width: 0px;" title="SELECT_DISTINCT88Percent" src="http://www.jonathanagardner.com/wp-content/uploads/2009/12/SELECT_DISTINCT88Percent_thumb.png" border="0" alt="SELECT_DISTINCT88Percent" width="104" height="77" align="left" /></a> While this was not the only issue with this query the execution plan showed that 88% of the query time was being spent on the SELECT DISTINCT portion of the query.  It was taking over 4 min to return a result set that contained only 55 rows.</p>

<p>By using the joins below we were able to reduce the time of the query from over 4 minutes to sub 1 second.
<pre class="code"><span style="color: blue;">FROM </span>dbo<span style="color: gray;">.</span>MS_METER b
    <span style="color: gray;">INNER JOIN </span>dbo<span style="color: gray;">.</span>SUM_METER_DAILY a
        <span style="color: blue;">ON </span>a<span style="color: gray;">.</span>METER_ID <span style="color: gray;">= </span>b<span style="color: gray;">.</span>METER_ID
    <span style="color: gray;">INNER JOIN </span>dbo<span style="color: gray;">.</span>MS_METER_CFG c
        <span style="color: blue;">ON </span>b<span style="color: gray;">.</span>METER_ID <span style="color: gray;">= </span>c<span style="color: gray;">.</span>METER_ID
    <span style="color: gray;">INNER JOIN </span>dbo<span style="color: gray;">.</span>BAL_GROUP_ASSIGNMENTS e
        <span style="color: blue;">ON </span>c<span style="color: gray;">.</span>STATION_ID <span style="color: gray;">= </span>e<span style="color: gray;">.</span><span style="color: magenta;">OBJECT_ID
    </span><span style="color: gray;">INNER JOIN </span>dbo<span style="color: gray;">.</span>BAL_GROUP f
        <span style="color: blue;">ON </span>e<span style="color: gray;">.</span>PARENT_BAL_GROUP_ID <span style="color: gray;">= </span>f<span style="color: gray;">.</span>BAL_GROUP_ID</p>

<pre><code>&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;b&lt;span style="color: gray;"&gt;.&lt;/span&gt;METER_IDNUM &lt;span style="color: gray;"&gt;is not NULL
    AND &lt;/span&gt;a&lt;span style="color: gray;"&gt;.&lt;/span&gt;IN_USE_FLAG &lt;span style="color: gray;"&gt;= &lt;/span&gt;1
    &lt;span style="color: gray;"&gt;AND &lt;/span&gt;a&lt;span style="color: gray;"&gt;.&lt;/span&gt;CONTRACT_DAY &lt;span style="color: gray;"&gt;&amp;lt;= &lt;/span&gt;@CONTRACTDATE
    &lt;span style="color: gray;"&gt;AND &lt;/span&gt;a&lt;span style="color: gray;"&gt;.&lt;/span&gt;CONTRACT_DAY &lt;span style="color: gray;"&gt;&amp;gt;= &lt;/span&gt;&lt;span style="color: magenta;"&gt;DATEADD&lt;/span&gt;&lt;span style="color: gray;"&gt;(&lt;/span&gt;&lt;span style="color: magenta;"&gt;DAY&lt;/span&gt;&lt;span style="color: gray;"&gt;, -&lt;/span&gt;4&lt;span style="color: gray;"&gt;, &lt;/span&gt;@CONTRACTDATE&lt;span style="color: gray;"&gt;)
    AND &lt;/span&gt;a&lt;span style="color: gray;"&gt;.&lt;/span&gt;IN_USE_FLAG &lt;span style="color: gray;"&gt;= &lt;/span&gt;1
    &lt;span style="color: gray;"&gt;AND &lt;/span&gt;f&lt;span style="color: gray;"&gt;.&lt;/span&gt;BALANCE_GROUP_NAME &lt;span style="color: gray;"&gt;= &lt;/span&gt;@LINESEG&lt;/pre&gt;
</code></pre>

<p><a href="http://11011.net/software/vspaste"></a></p>

<p>Are Joins better than Sub-Queries.  The answer to that question is the same as the answer to most SQL questions.  'It depends’.  Joins and Sub-Queries need to be taken on a case by case basis.</p>

<p>In this case the major problem was the SELECT DISTINCT in the subquery.  Using a subquery forces SQL to evaluate each row in the outer query.  Using DISTINCT in the subquery means that the subquery must do a complete scan of the table, sort the values and then return TRUE if any rows are returned.</p>

<p>If you have examples of subqueries that are faster than a join to return the same data set we would love to share them with everyone.</p>

<p>References:</p>

<p>Using Subqueries, <a href="http://docs.hp.com/en/36216-90103/ch03s02.html">http://docs.hp.com/en/36216-90103/ch03s02.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/using-joins-instead-of-sub-queries-a-case-study.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>User and Schema Association after Restore on DR Computer</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/user-and-schema-association-after-restore-on-dr-computer.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/user-and-schema-association-after-restore-on-dr-computer.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 12:53:43 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[Disaster Recovery]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/2009/10/27/user-and-schema-association-after-restore-on-dr-computer/</guid>
		<description><![CDATA[I was faced with a situation I have yet to encounter as a DBA. I don't know why I have yet to find this but I will write about it anyway. I have been working on a side by side upgrade/migration project going from SQL Server 2000 to SQL Server 2005. I have the two boxes configured but in the upgrade we are also going to have to correct some 'error' in security. It is because of this fact that I just can't migrate the master database and get all of my user associations back working together.]]></description>
			<content:encoded><![CDATA[<p></p><div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"><script type="text/javascript">// <![CDATA[
 digg_url = "http://www.jonathanagardner.com/2009/10/27/user-and-schema-association-after-restore-on-dr-computer/";digg_title = "User and Schema Association after Restore on DR Computer";digg_bgcolor = "#121314";digg_skin = "normal";
// ]]&gt;</script><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script><script type="text/javascript">// <![CDATA[
 digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;
// ]]&gt;</script></div>

<p>I was faced with a situation I have yet to encounter as a DBA. I don&#8217;t know why I have yet to find this but I will write about it anyway. I have been working on a side by side upgrade/migration project going from SQL Server 2000 to SQL Server 2005. I have the two boxes configured but in the upgrade we are also going to have to correct some &#8216;error&#8217; in security. It is because of this fact that I just can&#8217;t migrate the master database and get all of my user associations back working together.</p>

<h2>The Problem</h2>

<p>When we restored the database it contained users and schema that were no longer associated with security logins on the new server. When this happens and you add the Security User with the same name you can&#8217;t associate it with the user permissions on the database. If you do you will get the following error message</p>

<p style="text-align: left; padding-left: 60px; "><strong>User, group, or role &#8216;NewUser&#8217; already exists in the current database. (Microsoft SQL Server, Error: 15023)</strong></p>

<p>This can be corrected if the &#8216;NewUser&#8217; is removed from the security on the specific database, however if the &#8216;NewUser&#8217; owns any schema you will not be able to drop him without dropping the schema and you can&#8217;t drop the schema if the schema is associated with any other database object. You get my point.</p>

<h2>The Solution</h2>

<p>In order to keep the chain I used the ALTER AUTHORIZATION command to change the owner of the &#8216;NewUser&#8217; schema to &#8216;dbo&#8217;. Once the owner of the schema has changed I am free to drop the user and recreate him by associating the database user with the database. After I have recreated the login I am able to run the ALTER AUTHORIZATION command again and change the owner of the &#8216;NewUser&#8217; schema back to the &#8216;NewUser&#8217; that I just created. I have attached the code that I used below as an example.</p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>USE DB1
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>ALTER AUTHORIZATION ON SCHEMA::NewUser TO dbo;
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p style="padding-left: 60px; "><strong>IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N&#8217;NewUser&#8217;)</strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>DROP USER [NewUser]
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>USE [master]
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>ALTER LOGIN [NewUser] WITH DEFAULT_DATABASE=[DB1], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF, NO CREDENTIAL
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>USE [DB1]
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>CREATE USER [NewUser] FOR LOGIN [NewUser]
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>USE [DB1]
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>EXEC sp_addrolemember N&#8217;db_datareader&#8217;, N&#8217;NewUser&#8217;
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>USE DB1
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>&lt;</p>

<p>p style=&#8221;padding-left: 60px; &#8220;><strong>ALTER AUTHORIZATION ON SCHEMA::NewUser TO NewUser;
<span style="font-weight: normal; "><strong>GO</strong></span></strong></p>

<p>There are some things to keep in mind here. It is better if you can restore the master database to restore all of the users. It is also important to know that in doing this the password for the user must either be known or reset. Doing so is not an easy task if you have many database users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/user-and-schema-association-after-restore-on-dr-computer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links of the Week (9/25/2009)</title>
		<link>http://www.jonathanagardner.com/technology/links-of-the-week-9252009.html</link>
		<comments>http://www.jonathanagardner.com/technology/links-of-the-week-9252009.html#comments</comments>
		<pubDate>Fri, 25 Sep 2009 19:56:31 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Project Server]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/?p=271</guid>
		<description><![CDATA[SQL SQL WHERE Clause Optimization &#8211; Query optimization can make or break an application.  Understanding how a WHERE clause can affect a query is very important.  This article helps shed light on that. Creating Dynamic Output in SSIS &#8211; SQL Integration Services is one of SQL Servers most powerful features.  This article will demonstrate how [...]]]></description>
			<content:encoded><![CDATA[<p></p><h2><strong>SQL</strong></h2>

<p><a title="SQL WHERE Clause Optimization" href="http://bit.ly/1GVmmt" target="_blank">SQL WHERE Clause Optimization</a> &#8211; Query optimization can make or break an application.  Understanding how a WHERE clause can affect a query is very important.  This article helps shed light on that.</p>

<p><a title="Creating Dynamic Output in SSIS" href="http://bit.ly/2U4LyA" target="_blank">Creating Dynamic Output in SSIS</a> &#8211; SQL Integration Services is one of SQL Servers most powerful features.  This article will demonstrate how to build dynamic output into a SIS package.</p>

<p><a title="SQL Server Reporting Server Conditional Formatting" href="http://bit.ly/10n5GS" target="_blank">SQL Server Reporting Services Conditional Formatting</a> &#8211; Help information stand out in your reports.</p>

<p><a title="Lessons Learned: Why is my tlog backup huge at 5am" href="http://bit.ly/2Imw5T" target="_blank">Lessons Learned: Why is my tlog backup huge at 5am</a> &#8211; Article explaining what rebuilding index files will do to a logfile backup.</p>

<h2>Microsoft Project and Project Server</h2>

<p><a title="Project Server 2007 Report Pack II" href="http://bit.ly/YSt2g" target="_blank">Project Server 2007 Report Pack II</a> &#8211; Little did I know that Microsoft had written a series of reports for Project Server.  Now I don&#8217;t have to go write my own.  This makes me happy.</p>

<p><a title="Microsoft Project 2010 Demo Videos" href="http://bit.ly/v5Wlu" target="_blank">Microsoft Project 2010 Demo Videos</a> &#8211; As a project manager I spend lots of time dealing with Project and Project Server.  The new apps look great!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/links-of-the-week-9252009.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Technology Links of the Week (9/11/09)</title>
		<link>http://www.jonathanagardner.com/technology/technology-links-of-the-week-91109.html</link>
		<comments>http://www.jonathanagardner.com/technology/technology-links-of-the-week-91109.html#comments</comments>
		<pubDate>Fri, 11 Sep 2009 19:22:53 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/2009/09/11/technology-links-of-the-week-91109/</guid>
		<description><![CDATA[SQL Server Retaining historical index usage statistics for SQL Server Ten Common SQL Programming Mistakes Maximizing work space with SQL Server Management Studio by using separate results tabs SQL Server 2008 R2 Hands-on Lab Apple Mac OS X Snow Leopard: The Complete Guide]]></description>
			<content:encoded><![CDATA[<p></p><p><strong><u>SQL Server</u></strong></p>

<p><a href="http://www.mssqltips.com/tip.asp?tip=1749" target="_blank">Retaining historical index usage statistics for SQL Server</a></p>

<p><a href="http://www.simple-talk.com/sql/t-sql-programming/ten-common-sql-programming-mistakes/" target="_blank">Ten Common SQL Programming Mistakes</a></p>

<p><b><a href="http://www.mssqltips.com/tip.asp?tip=1832" target="_blank">Maximizing work space with SQL Server Management Studio by using separate results tabs</a></b></p>

<p><strong><a href="http://www.brentozar.com/archive/2009/08/sql-server-2008-r2-hands-on-lab/" target="_blank">SQL Server 2008 R2 Hands-on Lab</a></strong></p>

<p><strong><u>Apple</u></strong></p>

<p><a href="http://gizmodo.com/5352889/mac-os-x-snow-leopard-the-complete-guide" target="_blank">Mac OS X Snow Leopard: The Complete Guide</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/technology-links-of-the-week-91109.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Technology Links of the Week (6/29/09)</title>
		<link>http://www.jonathanagardner.com/technology/technology-links-of-the-week-3.html</link>
		<comments>http://www.jonathanagardner.com/technology/technology-links-of-the-week-3.html#comments</comments>
		<pubDate>Mon, 29 Jun 2009 21:25:46 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/2009/06/29/technology-links-of-the-week-3/</guid>
		<description><![CDATA[I have been spending most of my time in SQL Server lately so this weeks Technology Links will be centered around SQL. SQL Server Execute SQL and Bulk Insert Tasks in SSIS Backup Monitoring and Reporting SQL Databases That Have Not Had a Full Backup in x Days Using SQL Server Data Mining Add-Ins for [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I have been spending most of my time in SQL Server lately so this weeks Technology Links will be centered around SQL.</p>

<h3>SQL Server</h3>

<p><a href="http://www.sql-server-performance.com/articles/dba/execute_sql_bulk_insert_tasks_ssis_p1.aspx" target="_blank">Execute SQL and Bulk Insert Tasks in SSIS</a> </p>

<p><a href="http://delicious.com/jonathan.gardner04/?page=2" target="_blank">Backup Monitoring and Reporting</a></p>

<p><a href="http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/comment-page-1/#comment-4058" target="_blank">SQL Databases That Have Not Had a Full Backup in x Days</a></p>

<p><b><a href="http://www.mssqltips.com/tip.asp?tip=1780" target="_blank">Using SQL Server Data Mining Add-Ins for Office 2007 to Predict Database Growth Trends</a></b></p>

<h3>Operations Manager</h3>

<p><a href="http://blogs.technet.com/operationsmgr/archive/2009/04/15/configuring-im-notifications-in-system-center-operations-manager-2007.aspx" target="_blank">Configuring IM Notifications in System Center Operations Manager 2007</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/technology-links-of-the-week-3.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server Integration Services</title>
		<link>http://www.jonathanagardner.com/technology/sql-alerts/sql-server-integration-services.html</link>
		<comments>http://www.jonathanagardner.com/technology/sql-alerts/sql-server-integration-services.html#comments</comments>
		<pubDate>Wed, 03 Jun 2009 12:33:00 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.jonathanagardner.com/?p=179</guid>
		<description><![CDATA[I was recently asked to work on a project where I needed to export data from our accounting database, transform it and then insert it into another database to be accessed by application in our edge network. Having spent most of my days as a &#8216;Jack of All Trades&#8217;, I had yet to dig into [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img style="background-color: white; border: 0px initial initial;" src="http://www.jonathanagardner.com/wp-content/uploads/2009/05/logo-header-sql08-dg.gif" border="0" alt="logo-header-sql08-dg.gif" width="363" height="75" /></p>

<p>I was recently asked to work on a project where I needed to export data from our accounting database, transform it and then insert it into another database to be accessed by application in our edge network. Having spent most of my days as a &#8216;Jack of All Trades&#8217;, I had yet to dig into Integration Services. Through the course of my recent project, I have found that I have sadly missed out.</p>

<p><img src="http://www.jonathanagardner.com/wp-content/uploads/2009/05/ms1410261d2dd52b-9b70-4376-a686-b2d5e46a5d55en-ussql100.gif" border="0" alt="ms141026.1d2dd52b-9b70-4376-a686-b2d5e46a5d55(en-us,SQL.100).gif" width="291" height="272" align="right" />According to Microsoft, Integration Services is &#8216;used to solve complex business problems by copying or downloading files, sending email- messages in response to events, updating data warehouses, cleaning and mining data, and managing SQL Server objects and data.&#8217; What Integration Services really does is bring all of the SQL services together.</p>

<p>As a student of David Allan&#8217;s Getting Things Done and Tim Ferriss&#8217; The 4 Hour Work Week, I am always looking for ways to automate my life. Integration Services allows me to automate administrative tasks that I find myself performing on a regular basis. Actions like bulk data loading, copying/modifying database objects, and moving data from an OLTP into a data warehouse can be easily automated via on demand commands or scheduled jobs.</p>

<p>For readers not familiar with SQL Server Integration Services I would start with information straight from the source. Microsoft provides lots of information and feature outlines on the <a href="http://www.microsoft.com/sqlserver/2008/en/us/integration.aspx">SQL Server website</a>.</p>

<p>Future posts will cover Integration Services in greater detail with examples of specific solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanagardner.com/technology/sql-alerts/sql-server-integration-services.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

