<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>The Wit and Ramblings of David Giard - SQL Server</title>
    <link>http://www.davidgiard.com/</link>
    <description>Demanding rigidly defined areas of doubt and uncertainty</description>
    <language>en-us</language>
    <copyright>David Giard</copyright>
    <lastBuildDate>Tue, 12 Feb 2013 11:56:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>davidgiard@davidgiard.com</managingEditor>
    <webMaster>davidgiard@davidgiard.com</webMaster>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=34bacdec-62fe-4955-b421-57d9332ce8c0</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,34bacdec-62fe-4955-b421-57d9332ce8c0.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,34bacdec-62fe-4955-b421-57d9332ce8c0.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=34bacdec-62fe-4955-b421-57d9332ce8c0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 252</strong>
        </p>
        <p>
          <a href="http://technologyandfriends.com/SubText/archive/2013/02/11/tf252.aspx" target="_blank"> Chris
Woodruff on Data Experience </a>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=34bacdec-62fe-4955-b421-57d9332ce8c0" />
      </body>
      <title>Chris Woodruff on Data Experience</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,34bacdec-62fe-4955-b421-57d9332ce8c0.aspx</guid>
      <link>http://www.davidgiard.com/2013/02/12/ChrisWoodruffOnDataExperience.aspx</link>
      <pubDate>Tue, 12 Feb 2013 11:56:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" /&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 252&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://technologyandfriends.com/SubText/archive/2013/02/11/tf252.aspx" target="_blank"&gt; Chris
Woodruff on Data Experience &lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=34bacdec-62fe-4955-b421-57d9332ce8c0" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,34bacdec-62fe-4955-b421-57d9332ce8c0.aspx</comments>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
      <category>Video</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=818220a7-cbae-4047-8788-aca3d18d1300</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=818220a7-cbae-4047-8788-aca3d18d1300</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week, I demonstrated how <a href="http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx" target="_blank">to
embed code directly into a SQL Server Reporting Service (SSRS) report</a>.
</p>
        <p>
In this article, I will explain how to reference code in an external assembly from
an SSRS report. The basic steps are
</p>
        <ol>
          <li>
Create External Code</li>
          <li>
Create Unit Tests 
</li>
          <li>
Deploy the assembly to the Report Server</li>
          <li>
Add a reference to the assembly</li>
          <li>
Call external functions in Expression Editor</li>
          <li>
Deploy Report</li>
        </ol>
        <h3>Create External Code
</h3>
        <p>
The first step is to create and compile the external code. The project type will be
a Class Library and you will add a public class with a public static method. This
code can be in C#, Visual Basic, or F#. 
<br />
A sample is shown below in Listing 1. 
</p>
        <p>
        </p>
        <pre class="csharpcode">
          <span class="kwrd">using</span> System; <span class="kwrd">namespace</span> ReportFunctions
{ <span class="kwrd">public</span><span class="kwrd">class</span> ReportLib { <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">string</span> FormatAs2Digits(<span class="kwrd">decimal</span>?
input) { <span class="kwrd">if</span> (input == <span class="kwrd">null</span>) <span class="kwrd">return</span><span class="str">"N/A"</span>; <span class="kwrd">else</span><span class="kwrd">return</span> String.Format(<span class="str">"{0:##,##0.00;(##,##0.00)}"</span>,
input); } } }</pre>
Listing 1
<p>
Compile this code in Release mode
</p><h3>Create Unit Tests
</h3><p>
It's a good idea to create unit tests around this code because it can be difficult
to test it on the Report Server. 
<br />
At a minimum, write tests that mimic how you expect to call the function within your
reports.
</p><h3>Deploy Assembly to Report Server
</h3><p>
In order to use the functions, you must deploy the compiled DLL to the report server.
You can either create a Setup  project to create an MSI package or you can simply
copy the DLL to the drive where SQL Server Reporting Services is installed in the
following folder on the SQL Server installation drive:
</p><blockquote><p>
\Program Files\Microsoft SQL Server\<em>Instance_Name</em>\Reporting Services\ReportServer\bin
</p></blockquote><p>
where <em>Instance_Name </em>is the name of the instance of SQL Server on which SSRS
is running.
</p><h3>Add a reference to the assembly
</h3><p>
Open your Report project and open the report that will call the custom function. From
the menu, select <font face="Courier New">Report | Report Properties</font>. Select
the <em>References </em>tab (Fig. 1). 
</p><p><img src="http://davidgiard.com/content/binary/ssrs/Fig1-ReferencesTab.PNG" /><br /><font size="1">Fig. 1 – “Reference” tab of Report Properties</font></p><p>
Browse to select the deployed assembly containing the code you want to call.
</p><p>
After adding the reference, you will need to compile the Report project before you 
can use the assembly functions. To compile the report, select <font face="Courier New">Buld
| Build Solution</font> from the menu.
</p><h3>Call external functions in Expression Editor
</h3><p>
Open an expression editor and call a function in the external assembly. You will need
to include the entire namespace and classname. In our example, this be
</p><p>
An example is shown in Fig. 2.
</p><p><img src="http://davidgiard.com/content/binary/ssrs/Fig2-ExpressionEditor-External.PNG" /><br /><font size="1">Fig. 2 – Expression Editor</font></p><p>
You can test that the expression works by clicking the Preview tab of the report.
</p><h3>Deploy Report
</h3><p>
The final step is to deploy the report. Assuming you have permissions on the Report
Server and the report sever is set in the project properties, the easiest way to deploy
is to right-click the report in the Solution Explorer and select Deploy.
</p><p>
Now you can test the report and the function on the Report Server.
</p><h3>Conclusion
</h3><p>
In this article, we described how to call code in an external assembly from a SQL
Server Reporting Services report.
</p><img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=818220a7-cbae-4047-8788-aca3d18d1300" /></body>
      <title>Calling an External Assembly from SSRS</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</guid>
      <link>http://www.davidgiard.com/2012/09/11/CallingAnExternalAssemblyFromSSRS.aspx</link>
      <pubDate>Tue, 11 Sep 2012 21:20:41 GMT</pubDate>
      <description>&lt;p&gt;
Last week, I demonstrated how &lt;a href="http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx" target="_blank"&gt;to
embed code directly into a SQL Server Reporting Service (SSRS) report&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
In this article, I will explain how to reference code in an external assembly from
an SSRS report. The basic steps are
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Create External Code&lt;/li&gt;
&lt;li&gt;
Create Unit Tests 
&lt;/li&gt;
&lt;li&gt;
Deploy the assembly to the Report Server&lt;/li&gt;
&lt;li&gt;
Add a reference to the assembly&lt;/li&gt;
&lt;li&gt;
Call external functions in Expression Editor&lt;/li&gt;
&lt;li&gt;
Deploy Report&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Create External Code
&lt;/h3&gt;
&lt;p&gt;
The first step is to create and compile the external code. The project type will be
a Class Library and you will add a public class with a public static method. This
code can be in C#, Visual Basic, or F#. 
&lt;br /&gt;
A sample is shown below in Listing 1. 
&lt;/p&gt;
&lt;p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; ReportFunctions
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReportLib { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FormatAs2Digits(&lt;span class="kwrd"&gt;decimal&lt;/span&gt;?
input) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (input == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;N/A&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; String.Format(&lt;span class="str"&gt;&amp;quot;{0:##,##0.00;(##,##0.00)}&amp;quot;&lt;/span&gt;,
input); } } }&lt;/pre&gt;
Listing 1&gt;
&lt;p&gt;
Compile this code in Release mode
&lt;/p&gt;
&lt;h3&gt;Create Unit Tests
&lt;/h3&gt;
&lt;p&gt;
It's a good idea to create unit tests around this code because it can be difficult
to test it on the Report Server. 
&lt;br /&gt;
At a minimum, write tests that mimic how you expect to call the function within your
reports.
&lt;/p&gt;
&lt;h3&gt;Deploy Assembly to Report Server
&lt;/h3&gt;
&lt;p&gt;
In order to use the functions, you must deploy the compiled DLL to the report server.
You can either create a Setup&amp;#160; project to create an MSI package or you can simply
copy the DLL to the drive where SQL Server Reporting Services is installed in the
following folder on the SQL Server installation drive:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
\Program Files\Microsoft SQL Server\&lt;em&gt;Instance_Name&lt;/em&gt;\Reporting Services\ReportServer\bin
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
where &lt;em&gt;Instance_Name &lt;/em&gt;is the name of the instance of SQL Server on which SSRS
is running.
&lt;/p&gt;
&lt;h3&gt;Add a reference to the assembly
&lt;/h3&gt;
&lt;p&gt;
Open your Report project and open the report that will call the custom function. From
the menu, select &lt;font face="Courier New"&gt;Report | Report Properties&lt;/font&gt;. Select
the &lt;em&gt;References &lt;/em&gt;tab (Fig. 1). 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig1-ReferencesTab.PNG" /&gt; 
&lt;br /&gt;
&lt;font size="1"&gt;Fig. 1 – “Reference” tab of Report Properties&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Browse to select the deployed assembly containing the code you want to call.
&lt;/p&gt;
&lt;p&gt;
After adding the reference, you will need to compile the Report project before you&amp;#160;
can use the assembly functions. To compile the report, select &lt;font face="Courier New"&gt;Buld
| Build Solution&lt;/font&gt; from the menu.
&lt;/p&gt;
&lt;h3&gt;Call external functions in Expression Editor
&lt;/h3&gt;
&lt;p&gt;
Open an expression editor and call a function in the external assembly. You will need
to include the entire namespace and classname. In our example, this be
&lt;/p&gt;
&lt;p&gt;
An example is shown in Fig. 2.
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig2-ExpressionEditor-External.PNG" /&gt; 
&lt;br /&gt;
&lt;font size="1"&gt;Fig. 2 – Expression Editor&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
You can test that the expression works by clicking the Preview tab of the report.
&lt;/p&gt;
&lt;h3&gt;Deploy Report
&lt;/h3&gt;
&lt;p&gt;
The final step is to deploy the report. Assuming you have permissions on the Report
Server and the report sever is set in the project properties, the easiest way to deploy
is to right-click the report in the Solution Explorer and select Deploy.
&lt;/p&gt;
&lt;p&gt;
Now you can test the report and the function on the Report Server.
&lt;/p&gt;
&lt;h3&gt;Conclusion
&lt;/h3&gt;
&lt;p&gt;
In this article, we described how to call code in an external assembly from a SQL
Server Reporting Services report.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=818220a7-cbae-4047-8788-aca3d18d1300" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>SSRS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f092759b-06b9-4e82-bbbd-f3aa2e72d43d</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f092759b-06b9-4e82-bbbd-f3aa2e72d43d</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes I find myself applying the same formatting or performing the same task to
many elements within a SQL Server Reporting Services (SSRS) report.
</p>
        <p>
When this happens, I consider writing a reusable function to perform this task or
formatting. Functions can be added directly to an SSRS report.
</p>
        <p>
To add code to an SSRS report, open the report and select Report | Report Properties
from the menu. The <em>Report Properties </em>dialog displays. Select the Code tab
to bring this tab forward (Fig. 1). 
</p>
        <p>
          <img src="http://davidgiard.com/content/binary/ssrs/Fig1-SsrsCodeTab.PNG" />
          <br />
          <strong>
            <font size="1">Fig 1: The Code tab of the SSRS Report Properties dialogue</font>
          </strong>
        </p>
        <p>
This tab contains a single edit box into which you can type Visual Basic code. The
editor is very limited in that you can only use Visual Basic (no C#, F#, or JavaScript),
and it provides no IntelliSense. Still, it does allow you to create functions that
can be called elsewhere within your report. Type your function within this edit box. 
</p>
        <p>
Note: If, like me, you are having trouble writing valid code with the IntelliSense
or other syntax-checking, It might be helpful to create a console application in Visual
Studio and type the same function in order to validate the function's syntax and functionality.
</p>
        <p>
In SSRS, you assign an expression to an object’s property using the Expression Editor
(Fig. 2)
</p>
        <p>
          <img src="http://davidgiard.com/content/binary/ssrs/Fig2-SsrsExpressionEditor.PNG" />
          <br />
          <strong>
            <font size="1">Fig2: The SSRS Expression Editor</font>
          </strong>
        </p>
        <p>
In an Expression editor of any object on the report, you can call the function with
the word "Code", followed by ".", followed by the name of the
function.
</p>
        <p>
For example, I found that I had a number of textboxes that displayed numeric data.
I wanted every number to display with the following rules:
</p>
        <ul>
          <li>
Format the numeric output so exactly 2 digits appear to the right of the decimal point 
</li>
          <li>
Print "N/A" for null values. 
</li>
        </ul>
        <p>
I could accomplish this by doing the following:
</p>
        <ol>
          <li>
Set the formatting of every textbox to "##,##0.00;(##,##0.00)"</li>
          <li>
Change the expression in each textbox to something like: 
<br />
=Iif(IsNothing (Fields!Price), "N/A", Fields!Price)</li>
        </ol>
        <p>
But this is inefficient because one needs to perform the above steps for every textbox
where this change is needed. 
</p>
        <p>
Instead, I created the following function and embedded it into the report:
</p>
        <pre class="csharpcode">
          <span class="kwrd">Public</span>
          <span class="kwrd">Shared</span>
          <span class="kwrd">Function</span> FormatAs2Digits(<span class="kwrd">ByVal</span> input <span class="kwrd">as</span> Nullable(
of <span class="kwrd">decimal</span>)) <span class="kwrd">as</span><span class="kwrd">string</span><span class="kwrd">return</span> Iif(IsNothing
(input), <span class="str">"N/A"</span>, Format(input, <span class="str">"##,##0.00;(##,##0.00)"</span>)) <span class="kwrd">End</span> Function</pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
Then, I could set the expression of each textbox to something similar to the following
</p>
        <pre class="csharpcode">=Code.FormatAs2Digits(Fields!Price)</pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
Be aware that your report runs under a specific user context and that user will likely
have very limited access rights, so your functions will be limited in what that user
context can do. Generally, I only use functions to format data and perform other tasks
encapsulated within the report.
</p>
        <p>
Despite its limitations, an embedded function is an excellent way to create reusable
code and consume it in multiple objects within an SSRS report.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f092759b-06b9-4e82-bbbd-f3aa2e72d43d" />
      </body>
      <title>Embedded Code in an SSRS Report</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</guid>
      <link>http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx</link>
      <pubDate>Fri, 07 Sep 2012 20:19:29 GMT</pubDate>
      <description>&lt;p&gt;
Sometimes I find myself applying the same formatting or performing the same task to
many elements within a SQL Server Reporting Services (SSRS) report.
&lt;/p&gt;
&lt;p&gt;
When this happens, I consider writing a reusable function to perform this task or
formatting. Functions can be added directly to an SSRS report.
&lt;/p&gt;
&lt;p&gt;
To add code to an SSRS report, open the report and select Report | Report Properties
from the menu. The &lt;em&gt;Report Properties &lt;/em&gt;dialog displays. Select the Code tab
to bring this tab forward (Fig. 1). 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig1-SsrsCodeTab.PNG" /&gt; 
&lt;br /&gt;
&lt;strong&gt;&lt;font size="1"&gt;Fig 1: The Code tab of the SSRS Report Properties dialogue&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
This tab contains a single edit box into which you can type Visual Basic code. The
editor is very limited in that you can only use Visual Basic (no C#, F#, or JavaScript),
and it provides no IntelliSense. Still, it does allow you to create functions that
can be called elsewhere within your report. Type your function within this edit box. 
&lt;/p&gt;
&lt;p&gt;
Note: If, like me, you are having trouble writing valid code with the IntelliSense
or other syntax-checking, It might be helpful to create a console application in Visual
Studio and type the same function in order to validate the function's syntax and functionality.
&lt;/p&gt;
&lt;p&gt;
In SSRS, you assign an expression to an object’s property using the Expression Editor
(Fig. 2)
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig2-SsrsExpressionEditor.PNG" /&gt; 
&lt;br /&gt;
&lt;strong&gt;&lt;font size="1"&gt;Fig2: The SSRS Expression Editor&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In an Expression editor of any object on the report, you can call the function with
the word &amp;quot;Code&amp;quot;, followed by &amp;quot;.&amp;quot;, followed by the name of the
function.
&lt;/p&gt;
&lt;p&gt;
For example, I found that I had a number of textboxes that displayed numeric data.
I wanted every number to display with the following rules:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Format the numeric output so exactly 2 digits appear to the right of the decimal point 
&lt;/li&gt;
&lt;li&gt;
Print &amp;quot;N/A&amp;quot; for null values. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I could accomplish this by doing the following:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Set the formatting of every textbox to &amp;quot;##,##0.00;(##,##0.00)&amp;quot;&lt;/li&gt;
&lt;li&gt;
Change the expression in each textbox to something like: 
&lt;br /&gt;
=Iif(IsNothing (Fields!Price), &amp;quot;N/A&amp;quot;, Fields!Price)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
But this is inefficient because one needs to perform the above steps for every textbox
where this change is needed. 
&lt;/p&gt;
&lt;p&gt;
Instead, I created the following function and embedded it into the report:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; FormatAs2Digits(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; input &lt;span class="kwrd"&gt;as&lt;/span&gt; Nullable(
of &lt;span class="kwrd"&gt;decimal&lt;/span&gt;)) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; Iif(IsNothing
(input), &lt;span class="str"&gt;&amp;quot;N/A&amp;quot;&lt;/span&gt;, Format(input, &lt;span class="str"&gt;&amp;quot;##,##0.00;(##,##0.00)&amp;quot;&lt;/span&gt;)) &lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Then, I could set the expression of each textbox to something similar to the following
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;=Code.FormatAs2Digits(Fields!Price)&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Be aware that your report runs under a specific user context and that user will likely
have very limited access rights, so your functions will be limited in what that user
context can do. Generally, I only use functions to format data and perform other tasks
encapsulated within the report.
&lt;/p&gt;
&lt;p&gt;
Despite its limitations, an embedded function is an excellent way to create reusable
code and consume it in multiple objects within an SSRS report.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f092759b-06b9-4e82-bbbd-f3aa2e72d43d" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</comments>
      <category>SQL Server</category>
      <category>SSRS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=a1dc63c0-7034-4fff-8429-1f5ede92a11b</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,a1dc63c0-7034-4fff-8429-1f5ede92a11b.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,a1dc63c0-7034-4fff-8429-1f5ede92a11b.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a1dc63c0-7034-4fff-8429-1f5ede92a11b</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is a video of Jason Follas's <em> Using Geospatial Data With SQL Azure </em> presentation
at the <a href="http://detroitdayofazure.com" target="_blank">2012 Detroit Day of
Azure</a>. 
</p>
        <!--[if IE]><object width="437" height="370" id="viddlerOuter-c1ee5aae" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="//www.viddler.com/player/c1ee5aae/"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="flashVars" value="f=1&openURL=94948893&autoplay=f&loop=0&nologo=0&hd=0"><object id="viddlerInner-c1ee5aae"><video id="viddlerVideo-c1ee5aae" src="//www.viddler.com/file/c1ee5aae/html5mobile?openURL=94948893" type="video/mp4" width="437" height="328" poster="//www.viddler.com/thumbnail/c1ee5aae/" controls="controls" x-webkit-airplay="allow"></video></object></object><![endif]-->
        <!--[if !IE]> <!-->
        <object width="437" height="370" id="viddlerOuter-c1ee5aae" type="application/x-shockwave-flash" data="//www.viddler.com/player/c1ee5aae/">
          <param name="movie" value="//www.viddler.com/player/c1ee5aae/" />
          <param name="allowScriptAccess" value="always" />
          <param name="allowNetworking" value="all" />
          <param name="allowFullScreen" value="true" />
          <param name="flashVars" value="f=1&amp;openURL=94948893&amp;autoplay=f&amp;loop=0&amp;nologo=0&amp;hd=0" />
          <object id="viddlerInner-c1ee5aae">
            <video id="viddlerVideo-c1ee5aae" src="//www.viddler.com/file/c1ee5aae/html5mobile?openURL=94948893" type="video/mp4" width="437" height="328" poster="//www.viddler.com/thumbnail/c1ee5aae/" controls="controls" x-webkit-airplay="allow">
            </video>
          </object>
        </object>
        <!--<![endif]-->
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a1dc63c0-7034-4fff-8429-1f5ede92a11b" />
      </body>
      <title>Day of Azure video: Jason Follas on Geospatial Data With Azure</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,a1dc63c0-7034-4fff-8429-1f5ede92a11b.aspx</guid>
      <link>http://www.davidgiard.com/2012/07/17/DayOfAzureVideoJasonFollasOnGeospatialDataWithAzure.aspx</link>
      <pubDate>Tue, 17 Jul 2012 14:00:00 GMT</pubDate>
      <description>&lt;p&gt;
Here is a video of Jason Follas's &lt;em&gt; Using Geospatial Data With SQL Azure &lt;/em&gt; presentation
at the &lt;a href="http://detroitdayofazure.com" target="_blank"&gt;2012 Detroit Day of
Azure&lt;/a&gt;. 
&lt;/p&gt;
&lt;!--[if IE]&gt;&lt;object width="437" height="370" id="viddlerOuter-c1ee5aae" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"&gt;&lt;param name="movie" value="//www.viddler.com/player/c1ee5aae/"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;param name="allowNetworking" value="all"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="flashVars" value="f=1&amp;openURL=94948893&amp;autoplay=f&amp;loop=0&amp;nologo=0&amp;hd=0"&gt;&lt;object id="viddlerInner-c1ee5aae"&gt;&lt;video id="viddlerVideo-c1ee5aae" src="//www.viddler.com/file/c1ee5aae/html5mobile?openURL=94948893" type="video/mp4" width="437" height="328" poster="//www.viddler.com/thumbnail/c1ee5aae/" controls="controls" x-webkit-airplay="allow"&gt;&lt;/video&gt;&lt;/object&gt;&lt;/object&gt;&lt;![endif]--&gt;
&lt;!--[if !IE]&gt; &lt;!--&gt;
&lt;object width="437" height="370" id="viddlerOuter-c1ee5aae" type="application/x-shockwave-flash" data="//www.viddler.com/player/c1ee5aae/"&gt;
&lt;param name="movie" value="//www.viddler.com/player/c1ee5aae/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowNetworking" value="all"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashVars" value="f=1&amp;amp;openURL=94948893&amp;amp;autoplay=f&amp;amp;loop=0&amp;amp;nologo=0&amp;amp;hd=0"&gt;
&lt;object id="viddlerInner-c1ee5aae"&gt;
&lt;video id="viddlerVideo-c1ee5aae" src="//www.viddler.com/file/c1ee5aae/html5mobile?openURL=94948893" type="video/mp4" width="437" height="328" poster="//www.viddler.com/thumbnail/c1ee5aae/" controls="controls" x-webkit-airplay="allow"&gt;
&lt;/video&gt;
&lt;/object&gt;
&lt;/object&gt;
&lt;!--&lt;![endif]--&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a1dc63c0-7034-4fff-8429-1f5ede92a11b" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,a1dc63c0-7034-4fff-8429-1f5ede92a11b.aspx</comments>
      <category>Azure</category>
      <category>Community</category>
      <category>SQL Server</category>
      <category>Video</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=600474fd-28d9-4dcd-91ec-57d1aca5a8a1</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,600474fd-28d9-4dcd-91ec-57d1aca5a8a1.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,600474fd-28d9-4dcd-91ec-57d1aca5a8a1.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=600474fd-28d9-4dcd-91ec-57d1aca5a8a1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <p>
In .NET applications, Connection Strings are easily stored in and retrieved from a <em>web.config </em>file
or an <em>app.config </em>file. Add a <font face="Consolas">&lt;connectionStrings&gt; </font>section
to the <em>config </em>file, directly within the <font face="Consolas">&lt;configuration&gt;</font> section.
Within the <font face="Consolas">&lt;connectionStrings&gt; </font>section, place an <font face="Consolas">&lt;add&gt;</font> tag
for each connection string you wish to store and retrieve. This <font face="Consolas">&lt;add&gt;</font> tag
contains two important attributes: <em>name</em> and <em>connectionString</em>. The <em>name </em>attribute
will be used to look up an entry, so each <font face="Consolas">&lt;add&gt;</font> tag
should have a unique name. The <em>connectionString </em>attribute contains the connection
string you will use to connect to a database. If your application needs to connect
to a number of different data types, it is worth setting the Provider property as
well. This is the name of a database provider installed on the current machine, that
will allow you to connect to a database. 
<br />
An example is shown below:
</p>
        <pre class="csharpcode">&lt;configuration&gt;
  &lt;connectionStrings&gt;
    &lt;add name=<span class="str">"MyApp_Dev"</span><br />
        connectionString=<span class="str">"Data
Source=Server01;Initial Catalog=AwesomeDB_Dev;Integrated Security=True"</span>/&gt;
&lt;add name=<span class="str">"MyApp_QA"</span><br />
        connectionString=<span class="str">"Data
Source=Server01;Initial Catalog=AwesomeDB_QA;Integrated Security=True"</span>/&gt;
&lt;add name=<span class="str">"MyApp_Prod"</span><br />
        connectionString=<span class="str">"Data
Source=Server01;Initial Catalog=AwesomeDB;Integrated Security=True"</span>/&gt;
&lt;/connectionStrings&gt; &lt;/configuration&gt;</pre>
        <style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
To retrieve a connection string by its associated <em>name </em>attribute, use the
utilities found in the <em>System.Configuration </em>namespace of the System.Configuration
assembly. First, set a reference to <em>System.Assembly </em>by selecting the menu
option Project | Add Reference, selecting the System.Assembly in the Component Name
column of the .NET tab of the Add Reference dialog; and, clicking the OK button. Then,
add the following using statement to the top of your class file.
</p>
        <p>
This namespace contains the static <em>ConfigurationManager</em> class, which exposes
a number of methods for retrieving configuration information. <font face="Courier New">ConfigurationManager.ConnectionStrings </font>returns
a collection containing all connection strings settings in the <em>config </em>file
of the current assembly. Once we have this collection, we can retrieve a single item
by specifying its name. Doing so returns a <em>ConnectionStringSettings</em> object
that contains properties retrieved from a single &lt;add&gt; element of the <em>config </em>file.
The important property is <em>ConnectionString</em>, which can be used with ADO.NET
to connect to a database. Knowing the Provider property may also be useful if your
application connects to different types of data. 
<br />
Sample code is below. 
<br /></p>
        <pre class="csharpcode">ConnectionStringSettingsCollection cssCollection =
    ConfigurationManager.ConnectionStrings;
ConnectionStringSettings devCsSettings = cssCollection[<span class="str">"MyApp_Dev"</span>]; <span class="kwrd">string</span> devCs
= devCsSettings.ConnectionString;</pre>
        <style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=600474fd-28d9-4dcd-91ec-57d1aca5a8a1" />
      </body>
      <title>Reading a Connection String from a CONFIG file</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,600474fd-28d9-4dcd-91ec-57d1aca5a8a1.aspx</guid>
      <link>http://www.davidgiard.com/2012/05/30/ReadingAConnectionStringFromACONFIGFile.aspx</link>
      <pubDate>Wed, 30 May 2012 16:21:00 GMT</pubDate>
      <description>&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
In .NET applications, Connection Strings are easily stored in and retrieved from a &lt;em&gt;web.config &lt;/em&gt;file
or an &lt;em&gt;app.config &lt;/em&gt;file. Add a &lt;font face="Consolas"&gt;&amp;lt;connectionStrings&amp;gt; &lt;/font&gt;section
to the &lt;em&gt;config &lt;/em&gt;file, directly within the &lt;font face="Consolas"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt; section.
Within the &lt;font face="Consolas"&gt;&amp;lt;connectionStrings&amp;gt; &lt;/font&gt;section, place an &lt;font face="Consolas"&gt;&amp;lt;add&amp;gt;&lt;/font&gt; tag
for each connection string you wish to store and retrieve. This &lt;font face="Consolas"&gt;&amp;lt;add&amp;gt;&lt;/font&gt; tag
contains two important attributes: &lt;em&gt;name&lt;/em&gt; and &lt;em&gt;connectionString&lt;/em&gt;. The &lt;em&gt;name &lt;/em&gt;attribute
will be used to look up an entry, so each &lt;font face="Consolas"&gt;&amp;lt;add&amp;gt;&lt;/font&gt; tag
should have a unique name. The &lt;em&gt;connectionString &lt;/em&gt;attribute contains the connection
string you will use to connect to a database. If your application needs to connect
to a number of different data types, it is worth setting the Provider property as
well. This is the name of a database provider installed on the current machine, that
will allow you to connect to a database. 
&lt;br /&gt;
An example is shown below:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&amp;lt;configuration&amp;gt;
  &amp;lt;connectionStrings&amp;gt;
    &amp;lt;add name=&lt;span class="str"&gt;&amp;quot;MyApp_Dev&amp;quot;&lt;/span&gt; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; connectionString=&lt;span class="str"&gt;&amp;quot;Data
Source=Server01;Initial Catalog=AwesomeDB_Dev;Integrated Security=True&amp;quot;&lt;/span&gt;/&amp;gt;
&amp;lt;add name=&lt;span class="str"&gt;&amp;quot;MyApp_QA&amp;quot;&lt;/span&gt; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; connectionString=&lt;span class="str"&gt;&amp;quot;Data
Source=Server01;Initial Catalog=AwesomeDB_QA;Integrated Security=True&amp;quot;&lt;/span&gt;/&amp;gt;
&amp;lt;add name=&lt;span class="str"&gt;&amp;quot;MyApp_Prod&amp;quot;&lt;/span&gt; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; connectionString=&lt;span class="str"&gt;&amp;quot;Data
Source=Server01;Initial Catalog=AwesomeDB;Integrated Security=True&amp;quot;&lt;/span&gt;/&amp;gt;
&amp;lt;/connectionStrings&amp;gt; &amp;lt;/configuration&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
To retrieve a connection string by its associated &lt;em&gt;name &lt;/em&gt;attribute, use the
utilities found in the &lt;em&gt;System.Configuration &lt;/em&gt;namespace of the System.Configuration
assembly. First, set a reference to &lt;em&gt;System.Assembly &lt;/em&gt;by selecting the menu
option Project | Add Reference, selecting the System.Assembly in the Component Name
column of the .NET tab of the Add Reference dialog; and, clicking the OK button. Then,
add the following using statement to the top of your class file.
&lt;/p&gt;
&lt;p&gt;
This namespace contains the static &lt;em&gt;ConfigurationManager&lt;/em&gt; class, which exposes
a number of methods for retrieving configuration information. &lt;font face="Courier New"&gt;ConfigurationManager.ConnectionStrings &lt;/font&gt;returns
a collection containing all connection strings settings in the &lt;em&gt;config &lt;/em&gt;file
of the current assembly. Once we have this collection, we can retrieve a single item
by specifying its name. Doing so returns a &lt;em&gt;ConnectionStringSettings&lt;/em&gt; object
that contains properties retrieved from a single &amp;lt;add&amp;gt; element of the &lt;em&gt;config &lt;/em&gt;file.
The important property is &lt;em&gt;ConnectionString&lt;/em&gt;, which can be used with ADO.NET
to connect to a database. Knowing the Provider property may also be useful if your
application connects to different types of data. 
&lt;br /&gt;
Sample code is below. 
&lt;br /&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;ConnectionStringSettingsCollection cssCollection =
    ConfigurationManager.ConnectionStrings;
ConnectionStringSettings devCsSettings = cssCollection[&lt;span class="str"&gt;&amp;quot;MyApp_Dev&amp;quot;&lt;/span&gt;]; &lt;span class="kwrd"&gt;string&lt;/span&gt; devCs
= devCsSettings.ConnectionString;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=600474fd-28d9-4dcd-91ec-57d1aca5a8a1" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,600474fd-28d9-4dcd-91ec-57d1aca5a8a1.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f52289a1-ad2c-46e0-b14d-5c84ccc438ca</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f52289a1-ad2c-46e0-b14d-5c84ccc438ca.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f52289a1-ad2c-46e0-b14d-5c84ccc438ca.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f52289a1-ad2c-46e0-b14d-5c84ccc438ca</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The SQL Server master database contains many dynamic views that contain information
about the current state of the SQL Server. One such view is <em>dm_os_workers</em>,
which lists all active threads run by SQL Server and information about each thread.
Of particular interest are the error columns: 
<br />
One or more of the following bit columns will return 1 if there is anything is going
wrong with a thread:
</p>
        <ul>
          <li>
is_sick 
</li>
          <li>
is_in_cc_exception 
</li>
          <li>
is_fatal_exception 
</li>
          <li>
is_inside_catch 
</li>
        </ul>
        <p>
One limitation of this view is that it does not retain any history. If you want to
keep a history of threads, you can create a Database to hold that history and the
following SQL to copy the results of <em>dm_os_workers </em>to a table in that database.
The following SQL copies the dm_os_workers view results to the <em>dbo.ThreadsHistory</em> table
in the Instrumentation database.
</p>
        <pre class="csharpcode">
          <span class="kwrd">IF</span>
          <span class="kwrd">NOT</span>
          <span class="kwrd">EXISTS</span> (<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> Instrumentation.sys.objects <span class="kwrd">WHERE</span> object_id
= OBJECT_ID(N<span class="str">'[Instrumentation].[dbo].[ThreadsHistory]'</span>) <span class="kwrd">AND</span> type <span class="kwrd">IN</span> (N<span class="str">'U'</span>)) <span class="kwrd">BEGIN</span><span class="kwrd">SELECT</span> GETDATE() <span class="kwrd">AS</span> TimeLogged,
worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception, is_fatal_exception,
is_inside_catch, is_in_polling_io_completion_routine, context_switch_count, pending_io_count,
pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks, wait_resumed_ms_ticks,
task_bound_ms_ticks, worker_created_ms_ticks, exception_num, exception_severity, exception_address,
locale, affinity, <span class="kwrd">state</span>, start_quantum, end_quantum, last_wait_type,
return_code, quantum_used, max_quantum, boost_count, tasks_processed_count, fiber_address,
task_address, memory_object_address, thread_address, signal_worker_address, scheduler_address,
processor_group <span class="kwrd">INTO</span> [Instrumentation].[dbo].[ThreadsHistory] <span class="kwrd">FROM</span> sys.dm_os_workers <span class="kwrd">WHERE</span> 1=0 <span class="kwrd">END</span><span class="kwrd">DECLARE</span> @TimeNow <span class="kwrd">AS</span> DATETIME <span class="kwrd">SELECT</span> @TimeNow
= GETDATE() INSERT <span class="kwrd">INTO</span> Instrumentation.dbo.ThreadsHistory
( TimeLogged, worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception,
is_fatal_exception, is_inside_catch, is_in_polling_io_completion_routine, context_switch_count,
pending_io_count, pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks,
wait_resumed_ms_ticks, task_bound_ms_ticks, worker_created_ms_ticks, exception_num,
exception_severity, exception_address, locale, affinity, <span class="kwrd">state</span>,
start_quantum, end_quantum, last_wait_type, return_code, quantum_used, max_quantum,
boost_count, tasks_processed_count, fiber_address, task_address, memory_object_address,
thread_address, signal_worker_address, scheduler_address, processor_group ) ( <span class="kwrd">SELECT</span> @TimeNow,
worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception, is_fatal_exception,
is_inside_catch, is_in_polling_io_completion_routine, context_switch_count, pending_io_count,
pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks, wait_resumed_ms_ticks,
task_bound_ms_ticks, worker_created_ms_ticks, exception_num, exception_severity, exception_address,
locale, affinity, <span class="kwrd">state</span>, start_quantum, end_quantum, last_wait_type,
return_code, quantum_used, max_quantum, boost_count, tasks_processed_count, fiber_address,
task_address, memory_object_address, thread_address, signal_worker_address, scheduler_address,
processor_group <span class="kwrd">FROM</span> sys.dm_os_workers )</pre>
        <style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
You can use SQL Agent to schedule a job that runs this every 60 seconds (or however
frequently you want) to keep a history of the threads being generated by SQL. This
history can tell you if threads are generating exception and if thread counts are
increasing. 
<br /><hr /><font size="1">Steve Latsch contributed to this article.</font><img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f52289a1-ad2c-46e0-b14d-5c84ccc438ca" /></body>
      <title>Tracking Thread History in SQL Server 2010</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f52289a1-ad2c-46e0-b14d-5c84ccc438ca.aspx</guid>
      <link>http://www.davidgiard.com/2012/05/16/TrackingThreadHistoryInSQLServer2010.aspx</link>
      <pubDate>Wed, 16 May 2012 14:05:00 GMT</pubDate>
      <description>&lt;p&gt;
The SQL Server master database contains many dynamic views that contain information
about the current state of the SQL Server. One such view is &lt;em&gt;dm_os_workers&lt;/em&gt;,
which lists all active threads run by SQL Server and information about each thread.
Of particular interest are the error columns: 
&lt;br /&gt;
One or more of the following bit columns will return 1 if there is anything is going
wrong with a thread:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
is_sick 
&lt;/li&gt;
&lt;li&gt;
is_in_cc_exception 
&lt;/li&gt;
&lt;li&gt;
is_fatal_exception 
&lt;/li&gt;
&lt;li&gt;
is_inside_catch 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
One limitation of this view is that it does not retain any history. If you want to
keep a history of threads, you can create a Database to hold that history and the
following SQL to copy the results of &lt;em&gt;dm_os_workers &lt;/em&gt;to a table in that database.
The following SQL copies the dm_os_workers view results to the &lt;em&gt;dbo.ThreadsHistory&lt;/em&gt; table
in the Instrumentation database.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Instrumentation.sys.objects &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; object_id
= OBJECT_ID(N&lt;span class="str"&gt;'[Instrumentation].[dbo].[ThreadsHistory]'&lt;/span&gt;) &lt;span class="kwrd"&gt;AND&lt;/span&gt; type &lt;span class="kwrd"&gt;IN&lt;/span&gt; (N&lt;span class="str"&gt;'U'&lt;/span&gt;)) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; GETDATE() &lt;span class="kwrd"&gt;AS&lt;/span&gt; TimeLogged,
worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception, is_fatal_exception,
is_inside_catch, is_in_polling_io_completion_routine, context_switch_count, pending_io_count,
pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks, wait_resumed_ms_ticks,
task_bound_ms_ticks, worker_created_ms_ticks, exception_num, exception_severity, exception_address,
locale, affinity, &lt;span class="kwrd"&gt;state&lt;/span&gt;, start_quantum, end_quantum, last_wait_type,
return_code, quantum_used, max_quantum, boost_count, tasks_processed_count, fiber_address,
task_address, memory_object_address, thread_address, signal_worker_address, scheduler_address,
processor_group &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [Instrumentation].[dbo].[ThreadsHistory] &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.dm_os_workers &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; 1=0 &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @TimeNow &lt;span class="kwrd"&gt;AS&lt;/span&gt; DATETIME &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; @TimeNow
= GETDATE() INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; Instrumentation.dbo.ThreadsHistory
( TimeLogged, worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception,
is_fatal_exception, is_inside_catch, is_in_polling_io_completion_routine, context_switch_count,
pending_io_count, pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks,
wait_resumed_ms_ticks, task_bound_ms_ticks, worker_created_ms_ticks, exception_num,
exception_severity, exception_address, locale, affinity, &lt;span class="kwrd"&gt;state&lt;/span&gt;,
start_quantum, end_quantum, last_wait_type, return_code, quantum_used, max_quantum,
boost_count, tasks_processed_count, fiber_address, task_address, memory_object_address,
thread_address, signal_worker_address, scheduler_address, processor_group ) ( &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; @TimeNow,
worker_address, status, is_preemptive, is_fiber, is_sick, is_in_cc_exception, is_fatal_exception,
is_inside_catch, is_in_polling_io_completion_routine, context_switch_count, pending_io_count,
pending_io_byte_count, pending_io_byte_average, wait_started_ms_ticks, wait_resumed_ms_ticks,
task_bound_ms_ticks, worker_created_ms_ticks, exception_num, exception_severity, exception_address,
locale, affinity, &lt;span class="kwrd"&gt;state&lt;/span&gt;, start_quantum, end_quantum, last_wait_type,
return_code, quantum_used, max_quantum, boost_count, tasks_processed_count, fiber_address,
task_address, memory_object_address, thread_address, signal_worker_address, scheduler_address,
processor_group &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.dm_os_workers )&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
You can use SQL Agent to schedule a job that runs this every 60 seconds (or however
frequently you want) to keep a history of the threads being generated by SQL. This
history can tell you if threads are generating exception and if thread counts are
increasing. 
&lt;br /&gt;
&lt;hr /&gt;
&lt;font size="1"&gt;Steve Latsch contributed to this article.&lt;/font&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f52289a1-ad2c-46e0-b14d-5c84ccc438ca" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f52289a1-ad2c-46e0-b14d-5c84ccc438ca.aspx</comments>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=d2fe1c98-3ecb-4366-b245-8bce04b3f12f</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,d2fe1c98-3ecb-4366-b245-8bce04b3f12f.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,d2fe1c98-3ecb-4366-b245-8bce04b3f12f.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d2fe1c98-3ecb-4366-b245-8bce04b3f12f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
SQL Injection  is one of the most frequently-exploited vulnerabilities in the
software world. It refers to user-entered data making its way into commands sent to
back-end systems. It is common because so many developers are unaware of the risk
and how to mitigate it.
</p>
        <p>
Most of the applications I work with read from and write to a relational database,
such as Microsoft SQL Server.  I frequently run across ADO.NET code like the
following:
</p>
        <pre class="csharpcode">
          <span class="kwrd">string</span> lastName = <span class="str">"'Adams'"</span>; <span class="kwrd">string</span> sql
= <span class="str">"Select * from dbo.Customer where LastName = '"</span> +
lastName + <span class="str">"'"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Bad Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } }</pre>
        <style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
This code is designed to call a stored procedure like the following:
</p>
        <pre class="csharpcode">
          <span class="kwrd">CREATE</span>
          <span class="kwrd">PROCEDURE</span> [dbo].[GetCustomersByFirstName]
@FirstName NVARCHAR(50) <span class="kwrd">AS</span><span class="kwrd">BEGIN</span><span class="rem">--
SET NOCOUNT ON added to prevent extra result sets from</span><span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span>; <span class="kwrd">SELECT</span> Id,
FirstName, LastName <span class="kwrd">FROM</span> dbo.Customer <span class="kwrd">WHERE</span> FirstName
= @FirstName <span class="kwrd">ORDER</span><span class="kwrd">BY</span> Id <span class="kwrd">END</span> GO</pre>
        <style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
This method of code has several disadvantages 
</p>
        <ol>
          <li>
This code is not optimal because SQL Server does not have a chance to reuse a cached
query plan unless the user happens to send the exact same text into SQL Server. 
</li>
          <li>
The string concatenation opens the system to SQL Injection attacks. 
</li>
        </ol>
        <p>
A SQL Injection Attack is an attempt by an unscrupulous user to pass malicious commands
to a database. In the above example, imagine that the variable x was provided by a
user inputting text into a text box on a web age. An evil user might type something
like 
</p>
        <pre class="csharpcode">
          <span class="str">"Smith';DROP TABLE Customer;//"</span>
        </pre>
        <style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <br />
If that code runs with sufficient permissions, it would wreak havoc on your database.
The following query would be passed to SQL Server. <pre class="csharpcode"><span class="kwrd">Select</span> * <span class="kwrd">from</span> dbo.Customer <span class="kwrd">where</span> LastName
= <span class="str">'Smith'</span>;<span class="kwrd">DROP</span><span class="kwrd">Table</span><span class="kwrd">Customer</span>;//'</pre><style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style><p>
Clearly, dropping the customer table is not what your code is intended to do.
</p><p>
Many of you will read the above example and decide that you are safe because 
</p><ol><li>
Your web code runs under a context with insufficient privileges to drop a table; and 
</li><li>
You are validating all user inputs to ensure a user cannot enter anything bad. 
</li></ol><p>
There are problems with this reasoning.
</p><ol><li>
A clever hacker can sometimes trick a user into running code under elevated privileges.
Often there are multiple steps to an attack. 
</li><li>
Even if you have caught every possible injection possibility in your user interface,
you cannot guarantee that every call to this API will be made only from your UI for
all eternity. You may open up the API to the public or you may subcontract writing
a mobile application that calls this API or you may hire a new programmer who doesn't
know better. 
</li></ol><p>
The point is that you need to check security at every level of your application. And
part of checking security is to not trust your inputs.
</p><p>
A far better approach than concatenating strings to form a SQL statement is to create
parameter instances; set the value of each parameter; and add these parameters to
a <em>Parameters </em>collection.
</p><p>
The code below shows how to do this.
</p><pre class="csharpcode"><span class="kwrd">string</span> lastName = <span class="str">"Adams"</span>; <span class="kwrd">string</span> sql
= <span class="str">"Select * from dbo.Customer where LastName = @LastName"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlParameter lnParam = cmd.CreateParameter();
lnParam.ParameterName = <span class="str">"@LastName"</span>; lnParam.Value
= lastName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Good Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } Console.WriteLine();</pre><p><style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
Pass an unexpected parameter here and it will no t be executed on the end of the query
because SQL Server is expecting a parameter for a specific use.
</p><p>
The same pattern works if I want to pass in a dynamic string of SQL. Passing Parameter
instances is more secure than concatenating SQL and passing that string to SQL Server.
</p><p>
Below is a console application that uses the vulnerable string concatenation method
to call SQL Server via ADO.NET
</p><pre class="csharpcode"><span class="kwrd">using</span> System; <span class="kwrd">using</span> System.Configuration; <span class="kwrd">using</span> System.Data.SqlClient; <span class="kwrd">namespace</span> PassingSql_WrongWay
{ <span class="kwrd">class</span> Program { <span class="kwrd">static</span><span class="kwrd">void</span> Main(<span class="kwrd">string</span>[]
args) { CallSqlQuery(); CallStoredProc(); Console.ReadLine(); } <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">void</span> CallSqlQuery()
{ <span class="kwrd">string</span> lastName = <span class="str">"'Adams'"</span>; <span class="rem">//string
lastName = "Adams';DROP TABLE dbo.ExtraTable;--";</span><span class="kwrd">string</span> sql
= <span class="str">"Select * from dbo.Customer where LastName = '"</span> +
lastName + <span class="str">"'"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Bad Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } } Console.WriteLine(); } <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">void</span> CallStoredProc()
{ <span class="kwrd">string</span> firstName = <span class="str">"James"</span>; <span class="kwrd">string</span> sql
= <span class="str">"EXEC GetCustomersByFirstName '"</span> + firstName
+ <span class="str">"'"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Bad Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } Console.WriteLine(); } }
} }</pre><p>
Below is a similar console app, using the more secure parameters pattern
</p><pre class="csharpcode"><span class="kwrd">using</span> System; <span class="kwrd">using</span> System.Configuration; <span class="kwrd">using</span> System.Data.SqlClient; <span class="kwrd">namespace</span> PassingSql_RightWay
{ <span class="kwrd">class</span> Program { <span class="kwrd">static</span><span class="kwrd">void</span> Main(<span class="kwrd">string</span>[]
args) { CallSqlQuery(); CallStoredProc(); Console.ReadLine(); } <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">void</span> CallSqlQuery()
{ <span class="kwrd">string</span> lastName = <span class="str">"Adams"</span>; <span class="rem">//string
lastName = "Adams;DROP TABLE dbo.ExtraTable;--";</span><span class="kwrd">string</span> sql
= <span class="str">"Select * from dbo.Customer where LastName = @LastName"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlParameter lnParam = cmd.CreateParameter();
lnParam.ParameterName = <span class="str">"@LastName"</span>; lnParam.Value
= lastName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Good Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } Console.WriteLine(); } } <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">void</span> CallStoredProc()
{ <span class="kwrd">string</span> firstName = <span class="str">"James"</span>; <span class="kwrd">string</span> storedProcName
= <span class="str">"GetCustomersByFirstName"</span>; <span class="kwrd">string</span> connString
= ConfigurationManager.ConnectionStrings[<span class="str">"LocalConn"</span>].ConnectionString; <span class="kwrd">using</span> (var
conn = <span class="kwrd">new</span> SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = storedProcName; cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter lnParam = cmd.CreateParameter(); lnParam.ParameterName = <span class="str">"@FirstName"</span>;
lnParam.Value = firstName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); <span class="kwrd">while</span> (reader.Read())
{ Console.WriteLine(<span class="str">"Good Name: {0} {1}"</span>, reader[<span class="str">"FirstName"</span>],
reader[<span class="str">"LastName"</span>]); } Console.WriteLine(); } }
} }</pre><p><style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
If you wish to use the above code, create a new database named <em>TestData </em>and
run the following SQL DDL to create the database objects.
</p><pre class="csharpcode"><span class="kwrd">USE</span> [TestData] <span class="kwrd">GO</span> /****** <span class="kwrd">Object</span>: <span class="kwrd">Table</span> [dbo].[ExtraTable] <span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">CREATE</span><span class="kwrd">TABLE</span> [dbo].[ExtraTable](
[foo] [<span class="kwrd">nchar</span>](10) <span class="kwrd">NULL</span>, [bar]
[<span class="kwrd">nchar</span>](10) <span class="kwrd">NULL</span> ) <span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>] <span class="kwrd">GO</span> /****** <span class="kwrd">Object</span>: <span class="kwrd">Table</span> [dbo].[Customer] <span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">CREATE</span><span class="kwrd">TABLE</span> [dbo].[Customer](
[Id] [<span class="kwrd">int</span>] <span class="kwrd">IDENTITY</span>(1,1) <span class="kwrd">NOT</span><span class="kwrd">NULL</span>,
[FirstName] [nvarchar](50) <span class="kwrd">NULL</span>, [LastName] [nvarchar](50) <span class="kwrd">NOT</span><span class="kwrd">NULL</span> ) <span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>] <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'George'</span>, <span class="str">'Washington'</span>) <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'John'</span>, <span class="str">'Adams'</span>) <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'Thomas'</span>, <span class="str">'Jefferson'</span>) <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'James'</span>, <span class="str">'Madison'</span>) <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'James'</span>, <span class="str">'Monroe'</span>) <span class="kwrd">GO</span> INSERT <span class="kwrd">INTO</span> dbo.Customer
(FirstName, LastName) <span class="kwrd">VALUES</span> (<span class="str">'John Quincy'</span>, <span class="str">'Adams'</span>) <span class="kwrd">GO</span> /****** <span class="kwrd">Object</span>:
StoredProcedure [dbo].[GetCustomersByFirstName] <span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span><span class="kwrd">GO</span><span class="kwrd">CREATE</span><span class="kwrd">PROCEDURE</span> [dbo].[GetCustomersByFirstName]
@FirstName NVARCHAR(50) <span class="kwrd">AS</span><span class="kwrd">BEGIN</span><span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span>; <span class="kwrd">SELECT</span> Id,
FirstName, LastName <span class="kwrd">FROM</span> dbo.Customer <span class="kwrd">WHERE</span> FirstName
= @FirstName <span class="kwrd">ORDER</span><span class="kwrd">BY</span> Id <span class="kwrd">END</span><span class="kwrd">GO</span></pre><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style><p><style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
With a little bit of thought and a few lines of code, you can significantly reduce
the risk of SQL injection in your ADO.NET code.
</p><img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=d2fe1c98-3ecb-4366-b245-8bce04b3f12f" /></body>
      <title>Passing Parameters to SQL Server</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,d2fe1c98-3ecb-4366-b245-8bce04b3f12f.aspx</guid>
      <link>http://www.davidgiard.com/2012/04/12/PassingParametersToSQLServer.aspx</link>
      <pubDate>Thu, 12 Apr 2012 23:13:00 GMT</pubDate>
      <description>&lt;p&gt;
SQL Injection&amp;#160; is one of the most frequently-exploited vulnerabilities in the
software world. It refers to user-entered data making its way into commands sent to
back-end systems. It is common because so many developers are unaware of the risk
and how to mitigate it.
&lt;/p&gt;
&lt;p&gt;
Most of the applications I work with read from and write to a relational database,
such as Microsoft SQL Server.&amp;#160; I frequently run across ADO.NET code like the
following:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; lastName = &lt;span class="str"&gt;&amp;quot;'Adams'&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; sql
= &lt;span class="str"&gt;&amp;quot;Select * from dbo.Customer where LastName = '&amp;quot;&lt;/span&gt; +
lastName + &lt;span class="str"&gt;&amp;quot;'&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Bad Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } }&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
This code is designed to call a stored procedure like the following:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROCEDURE&lt;/span&gt; [dbo].[GetCustomersByFirstName]
@FirstName NVARCHAR(50) &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="rem"&gt;--
SET NOCOUNT ON added to prevent extra result sets from&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; NOCOUNT &lt;span class="kwrd"&gt;ON&lt;/span&gt;; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; Id,
FirstName, LastName &lt;span class="kwrd"&gt;FROM&lt;/span&gt; dbo.Customer &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; FirstName
= @FirstName &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; Id &lt;span class="kwrd"&gt;END&lt;/span&gt; GO&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
This method of code has several disadvantages 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
This code is not optimal because SQL Server does not have a chance to reuse a cached
query plan unless the user happens to send the exact same text into SQL Server. 
&lt;/li&gt;
&lt;li&gt;
The string concatenation opens the system to SQL Injection attacks. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
A SQL Injection Attack is an attempt by an unscrupulous user to pass malicious commands
to a database. In the above example, imagine that the variable x was provided by a
user inputting text into a text box on a web age. An evil user might type something
like 
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;&amp;quot;Smith';DROP TABLE Customer;//&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;br /&gt;
If that code runs with sufficient permissions, it would wreak havoc on your database.
The following query would be passed to SQL Server. &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; dbo.Customer &lt;span class="kwrd"&gt;where&lt;/span&gt; LastName
= &lt;span class="str"&gt;'Smith'&lt;/span&gt;;&lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;Table&lt;/span&gt; &lt;span class="kwrd"&gt;Customer&lt;/span&gt;;//'&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Clearly, dropping the customer table is not what your code is intended to do.
&lt;/p&gt;
&lt;p&gt;
Many of you will read the above example and decide that you are safe because 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Your web code runs under a context with insufficient privileges to drop a table; and 
&lt;/li&gt;
&lt;li&gt;
You are validating all user inputs to ensure a user cannot enter anything bad. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
There are problems with this reasoning.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
A clever hacker can sometimes trick a user into running code under elevated privileges.
Often there are multiple steps to an attack. 
&lt;/li&gt;
&lt;li&gt;
Even if you have caught every possible injection possibility in your user interface,
you cannot guarantee that every call to this API will be made only from your UI for
all eternity. You may open up the API to the public or you may subcontract writing
a mobile application that calls this API or you may hire a new programmer who doesn't
know better. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The point is that you need to check security at every level of your application. And
part of checking security is to not trust your inputs.
&lt;/p&gt;
&lt;p&gt;
A far better approach than concatenating strings to form a SQL statement is to create
parameter instances; set the value of each parameter; and add these parameters to
a &lt;em&gt;Parameters &lt;/em&gt;collection.
&lt;/p&gt;
&lt;p&gt;
The code below shows how to do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; lastName = &lt;span class="str"&gt;&amp;quot;Adams&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; sql
= &lt;span class="str"&gt;&amp;quot;Select * from dbo.Customer where LastName = @LastName&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlParameter lnParam = cmd.CreateParameter();
lnParam.ParameterName = &lt;span class="str"&gt;&amp;quot;@LastName&amp;quot;&lt;/span&gt;; lnParam.Value
= lastName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Good Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } Console.WriteLine();&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
Pass an unexpected parameter here and it will no t be executed on the end of the query
because SQL Server is expecting a parameter for a specific use.
&lt;/p&gt;
&lt;p&gt;
The same pattern works if I want to pass in a dynamic string of SQL. Passing Parameter
instances is more secure than concatenating SQL and passing that string to SQL Server.
&lt;/p&gt;
&lt;p&gt;
Below is a console application that uses the vulnerable string concatenation method
to call SQL Server via ADO.NET
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.SqlClient; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; PassingSql_WrongWay
{ &lt;span class="kwrd"&gt;class&lt;/span&gt; Program { &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[]
args) { CallSqlQuery(); CallStoredProc(); Console.ReadLine(); } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallSqlQuery()
{ &lt;span class="kwrd"&gt;string&lt;/span&gt; lastName = &lt;span class="str"&gt;&amp;quot;'Adams'&amp;quot;&lt;/span&gt;; &lt;span class="rem"&gt;//string
lastName = &amp;quot;Adams';DROP TABLE dbo.ExtraTable;--&amp;quot;;&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; sql
= &lt;span class="str"&gt;&amp;quot;Select * from dbo.Customer where LastName = '&amp;quot;&lt;/span&gt; +
lastName + &lt;span class="str"&gt;&amp;quot;'&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Bad Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } } Console.WriteLine(); } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallStoredProc()
{ &lt;span class="kwrd"&gt;string&lt;/span&gt; firstName = &lt;span class="str"&gt;&amp;quot;James&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; sql
= &lt;span class="str"&gt;&amp;quot;EXEC GetCustomersByFirstName '&amp;quot;&lt;/span&gt; + firstName
+ &lt;span class="str"&gt;&amp;quot;'&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Bad Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } Console.WriteLine(); } }
} }&lt;/pre&gt;
&lt;p&gt;
Below is a similar console app, using the more secure parameters pattern
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.SqlClient; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; PassingSql_RightWay
{ &lt;span class="kwrd"&gt;class&lt;/span&gt; Program { &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[]
args) { CallSqlQuery(); CallStoredProc(); Console.ReadLine(); } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallSqlQuery()
{ &lt;span class="kwrd"&gt;string&lt;/span&gt; lastName = &lt;span class="str"&gt;&amp;quot;Adams&amp;quot;&lt;/span&gt;; &lt;span class="rem"&gt;//string
lastName = &amp;quot;Adams;DROP TABLE dbo.ExtraTable;--&amp;quot;;&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; sql
= &lt;span class="str"&gt;&amp;quot;Select * from dbo.Customer where LastName = @LastName&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlParameter lnParam = cmd.CreateParameter();
lnParam.ParameterName = &lt;span class="str"&gt;&amp;quot;@LastName&amp;quot;&lt;/span&gt;; lnParam.Value
= lastName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Good Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } Console.WriteLine(); } } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallStoredProc()
{ &lt;span class="kwrd"&gt;string&lt;/span&gt; firstName = &lt;span class="str"&gt;&amp;quot;James&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; storedProcName
= &lt;span class="str"&gt;&amp;quot;GetCustomersByFirstName&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;string&lt;/span&gt; connString
= ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;&amp;quot;LocalConn&amp;quot;&lt;/span&gt;].ConnectionString; &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connString)) { conn.Open(); var
cmd = conn.CreateCommand(); cmd.CommandText = storedProcName; cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter lnParam = cmd.CreateParameter(); lnParam.ParameterName = &lt;span class="str"&gt;&amp;quot;@FirstName&amp;quot;&lt;/span&gt;;
lnParam.Value = firstName; cmd.Parameters.Add(lnParam); SqlDataReader reader = cmd.ExecuteReader(); &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
{ Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Good Name: {0} {1}&amp;quot;&lt;/span&gt;, reader[&lt;span class="str"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;],
reader[&lt;span class="str"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;]); } Console.WriteLine(); } }
} }&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
If you wish to use the above code, create a new database named &lt;em&gt;TestData &lt;/em&gt;and
run the following SQL DDL to create the database objects.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; [TestData] &lt;span class="kwrd"&gt;GO&lt;/span&gt; /****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;: &lt;span class="kwrd"&gt;Table&lt;/span&gt; [dbo].[ExtraTable] &lt;span class="kwrd"&gt;SET&lt;/span&gt; ANSI_NULLS &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; QUOTED_IDENTIFIER &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[ExtraTable](
[foo] [&lt;span class="kwrd"&gt;nchar&lt;/span&gt;](10) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;, [bar]
[&lt;span class="kwrd"&gt;nchar&lt;/span&gt;](10) &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;] &lt;span class="kwrd"&gt;GO&lt;/span&gt; /****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;: &lt;span class="kwrd"&gt;Table&lt;/span&gt; [dbo].[Customer] &lt;span class="kwrd"&gt;SET&lt;/span&gt; ANSI_NULLS &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; QUOTED_IDENTIFIER &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[Customer](
[Id] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1,1) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
[FirstName] [nvarchar](50) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;, [LastName] [nvarchar](50) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;] &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'George'&lt;/span&gt;, &lt;span class="str"&gt;'Washington'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'John'&lt;/span&gt;, &lt;span class="str"&gt;'Adams'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'Thomas'&lt;/span&gt;, &lt;span class="str"&gt;'Jefferson'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'James'&lt;/span&gt;, &lt;span class="str"&gt;'Madison'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'James'&lt;/span&gt;, &lt;span class="str"&gt;'Monroe'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; dbo.Customer
(FirstName, LastName) &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="str"&gt;'John Quincy'&lt;/span&gt;, &lt;span class="str"&gt;'Adams'&lt;/span&gt;) &lt;span class="kwrd"&gt;GO&lt;/span&gt; /****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;:
StoredProcedure [dbo].[GetCustomersByFirstName] &lt;span class="kwrd"&gt;SET&lt;/span&gt; ANSI_NULLS &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; QUOTED_IDENTIFIER &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt; &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROCEDURE&lt;/span&gt; [dbo].[GetCustomersByFirstName]
@FirstName NVARCHAR(50) &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; NOCOUNT &lt;span class="kwrd"&gt;ON&lt;/span&gt;; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; Id,
FirstName, LastName &lt;span class="kwrd"&gt;FROM&lt;/span&gt; dbo.Customer &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; FirstName
= @FirstName &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; Id &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
With a little bit of thought and a few lines of code, you can significantly reduce
the risk of SQL injection in your ADO.NET code.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=d2fe1c98-3ecb-4366-b245-8bce04b3f12f" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,d2fe1c98-3ecb-4366-b245-8bce04b3f12f.aspx</comments>
      <category>.Net</category>
      <category>C#</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=c182bdce-9f3d-43e3-95a3-b42e3d8bd114</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,c182bdce-9f3d-43e3-95a3-b42e3d8bd114.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,c182bdce-9f3d-43e3-95a3-b42e3d8bd114.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c182bdce-9f3d-43e3-95a3-b42e3d8bd114</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
SQL Server 2008 R2 provides some new tools to help deploy database schemas.
</p>
        <p>
Compiled code and database schemas are frequently dependent on one another and must
therefore be deployed simultaneously to a given environment. If a developer writes
code that accesses a new table, that table must be available when the code runs. If
the code is deployed and run before the table is deployed to the database, a runtime
error occurs and the user experience will be unsatisfactory.
</p>
        <p>
In the past, Microsoft has released tools to help developers manage the deployment
of database schema changes. Visual Studio Database Edition (aka “Data Dude”) was bundled
into Visual Studio 2010. But these tools are geared toward developers – not to DBAs.
Most DBAs don’t work in Visual Studio. And in large enterprise applications, it is
the DBAs who are managing the deployment of the database schemas. Without tools, this
coordination requires a lot of manual steps. 
</p>
        <p>
SQL Server 2008 R2 includes support for Data Tier Applications. A Data Tier Application
(mysteriously abbreviated “DAC”) is a package containing instructions for deploying
a database schema. DBAs and developers can use SQL Server Management Studio to create
“DACPAC” files for a given database. They can then use that DACPAC file to create
or update a database with an existing schema.
</p>
        <p>
DAC does not support all database objects. Standard objects, such as tables, columns,
views, indexes are supported. Security objects such as users roles and logins are
supported. Extended stored procedures and full text searches are not supported. The
list of supported items is similar to the list of items supported in SQL Azure.
</p>
        <p>
To create a DAC in SQL Server 2008 R2, launch SQL Server Management Studio, connect
to a server, and expand the <em>Databases </em>node. Right-click the name of the database
you want to deploy and select <font face="Courier New">Tasks | Extract Data Tier Application… </font>from
the context menu. The <em>Extract Data Tier Application </em>wizard launches and an
introduction window (Figure 1) displays. 
</p>
        <p align="center">
          <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb.png" width="244" height="227" />
          </a>
          <br />
          <strong>Figure 1</strong>
        </p>
        <p>
Click the <em>Next </em>button. The <em>Set Properties </em>screen (Figure 2) displays. 
</p>
        <p align="center">
          <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_3.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_3.png" width="244" height="227" />
          </a>
          <br />
          <strong>Figure 2</strong>
        </p>
        <p>
At the <em>Application Name </em>field, enter a name for this DAC.
</p>
        <p>
At the <em>Version </em>field, enter a version number. SQL Server does not auto-increment
version numbers, so you will need to manage this yourself. It’s a good idea to keep
major and minor versions of database schemas in sync with the version of the application
that consumes them.
</p>
        <p>
At the <em>Description </em>field, you may optionally enter a brief description of
the schema.
</p>
        <p>
At the <em>Save to DAC package file </em>field, enter the full path (including file
name) where you want to store the deployment file. You may click the <em>Browse </em>button
to select a folder. If you enter the name of a file that already exists, you must
check the <em>Overwrite existing file </em>checkbox in order to proceed.
</p>
        <p>
Click the <em>Next </em>button to perform a validation. The validation checks if DAC
can handle all objects in the database. When the validation is complete, the <em>Validation </em>screen
(Figure 3) displays. This screen displays items up to three sets of items: Items that
can be deployed with DAC are displayed beneath a green <em>Check </em>icon; items
that are not supported are displayed under a red <em>X </em>icon; and items that are
supported, but rely on unsupported items are displayed under a yellow <em>Exclamation </em>icon.
</p>
        <p align="center">
          <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_4.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_4.png" width="244" height="227" />
          </a>
          <br />
          <strong>Figure 3</strong>
        </p>
        <p>
Supported items present no problem to DAC. 
</p>
        <p>
Unsupported items appear as errors. Unfortunately, you will not be allowed to proceed
until these items are removed from the database. Fortunately, the wizard is non-modal,
so you can minimize it and switch back to Management Studio to remove these items
before re-running the Validation.
</p>
        <p>
Click the <em>Next</em> button to start building the DAC package. 
</p>
        <p>
When complete, the Build Package screen (Figure 4) displays, indicating success or
listing problems that occurred.
</p>
        <p align="center">
          <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_5.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_5.png" width="244" height="227" />
          </a>
          <br />
          <strong>Figure 4</strong>
        </p>
        <p>
Click the <em>Finish </em>button to close the wizard. A file with the extension DACPAC
is created.
</p>
        <p>
Deploying the Schema in a DAC
</p>
        <p>
After creating a DAC, you can use SQL Server Management Studio to deploy the DAC’s
schema to a new database. To begin, launch SQL Server Management Studio, expand the <em>Management </em>node,
and right-click the <em>Data-tier applications </em>node. From the context menu, select <font face="Courier New">Deploy
Data-tier application</font>. The The <em>Introduction </em>screen (Figure 5) of the <em>Deploy
Data-tier application </em>wizard displays.
</p>
        <p align="center">
          <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_6.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_6.png" width="244" height="227" />
          </a>
          <br />
          <strong>Figure 5</strong>
        </p>
        <blockquote>
          <p>
Click the <em>Next </em>button to display the <em>Select Package </em>screen (Figure
6). 
</p>
          <p align="center">
            <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_7.png">
              <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_7.png" width="244" height="227" />
            </a>
            <br />
            <strong>Figure 6</strong>
          </p>
          <p>
Click the <em>Browse </em>button and select the DACPAC file created above. Click Open.
Click the Next button to display the <em>Update Configuration </em>screen (Figure
7). 
</p>
          <p align="center">
            <a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_8.png">
              <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_8.png" width="244" height="227" />
            </a>
            <br />
            <strong>Figure 7</strong>
            <br />
          </p>
          <p>
At the <em>Name </em>field, enter a name for the database you wish to create. This
field defaults to the name of the database from which the DAC originated. If you are
running this deployment on the same server instance on which you created the DACPAC,
this will cause a conflict and SQL Server will notify you with a red exclamation icon
next to the <em>Name </em>field.
</p>
          <p>
Click <em>Next </em>to begin the deployment. When the deployment completes, the <em>Summary </em>screen
(Figure 8) displays.
</p>
          <p>
You should notice the new database appears beneath the <em>Database </em>node and
the DAC is registered and appears beneath the <em>Management \ Data-tier applications </em>node.
You may need to refresh these nodes in order to view them.
</p>
          <p>
Note that the new database contains no objects – only database objects, such as tables,
views, stored procedures, and users.
</p>
          <p>
In this article, we discussed Data-tier applications and described how to use SQL
Server Management Studio to create and deploy a DACPAC file.
</p>
        </blockquote>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=c182bdce-9f3d-43e3-95a3-b42e3d8bd114" />
      </body>
      <title>SQL Server Data Tier Applications</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,c182bdce-9f3d-43e3-95a3-b42e3d8bd114.aspx</guid>
      <link>http://www.davidgiard.com/2010/11/23/SQLServerDataTierApplications.aspx</link>
      <pubDate>Tue, 23 Nov 2010 11:55:00 GMT</pubDate>
      <description>&lt;p&gt;
SQL Server 2008 R2 provides some new tools to help deploy database schemas.
&lt;/p&gt;
&lt;p&gt;
Compiled code and database schemas are frequently dependent on one another and must
therefore be deployed simultaneously to a given environment. If a developer writes
code that accesses a new table, that table must be available when the code runs. If
the code is deployed and run before the table is deployed to the database, a runtime
error occurs and the user experience will be unsatisfactory.
&lt;/p&gt;
&lt;p&gt;
In the past, Microsoft has released tools to help developers manage the deployment
of database schema changes. Visual Studio Database Edition (aka “Data Dude”) was bundled
into Visual Studio 2010. But these tools are geared toward developers – not to DBAs.
Most DBAs don’t work in Visual Studio. And in large enterprise applications, it is
the DBAs who are managing the deployment of the database schemas. Without tools, this
coordination requires a lot of manual steps. 
&lt;/p&gt;
&lt;p&gt;
SQL Server 2008 R2 includes support for Data Tier Applications. A Data Tier Application
(mysteriously abbreviated “DAC”) is a package containing instructions for deploying
a database schema. DBAs and developers can use SQL Server Management Studio to create
“DACPAC” files for a given database. They can then use that DACPAC file to create
or update a database with an existing schema.
&lt;/p&gt;
&lt;p&gt;
DAC does not support all database objects. Standard objects, such as tables, columns,
views, indexes are supported. Security objects such as users roles and logins are
supported. Extended stored procedures and full text searches are not supported. The
list of supported items is similar to the list of items supported in SQL Azure.
&lt;/p&gt;
&lt;p&gt;
To create a DAC in SQL Server 2008 R2, launch SQL Server Management Studio, connect
to a server, and expand the &lt;em&gt;Databases &lt;/em&gt;node. Right-click the name of the database
you want to deploy and select &lt;font face="Courier New"&gt;Tasks | Extract Data Tier Application… &lt;/font&gt;from
the context menu. The &lt;em&gt;Extract Data Tier Application &lt;/em&gt;wizard launches and an
introduction window (Figure 1) displays. 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 1&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Click the &lt;em&gt;Next &lt;/em&gt;button. The &lt;em&gt;Set Properties &lt;/em&gt;screen (Figure 2) displays. 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_3.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 2&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
At the &lt;em&gt;Application Name &lt;/em&gt;field, enter a name for this DAC.
&lt;/p&gt;
&lt;p&gt;
At the &lt;em&gt;Version &lt;/em&gt;field, enter a version number. SQL Server does not auto-increment
version numbers, so you will need to manage this yourself. It’s a good idea to keep
major and minor versions of database schemas in sync with the version of the application
that consumes them.
&lt;/p&gt;
&lt;p&gt;
At the &lt;em&gt;Description &lt;/em&gt;field, you may optionally enter a brief description of
the schema.
&lt;/p&gt;
&lt;p&gt;
At the &lt;em&gt;Save to DAC package file &lt;/em&gt;field, enter the full path (including file
name) where you want to store the deployment file. You may click the &lt;em&gt;Browse &lt;/em&gt;button
to select a folder. If you enter the name of a file that already exists, you must
check the &lt;em&gt;Overwrite existing file &lt;/em&gt;checkbox in order to proceed.
&lt;/p&gt;
&lt;p&gt;
Click the &lt;em&gt;Next &lt;/em&gt;button to perform a validation. The validation checks if DAC
can handle all objects in the database. When the validation is complete, the &lt;em&gt;Validation &lt;/em&gt;screen
(Figure 3) displays. This screen displays items up to three sets of items: Items that
can be deployed with DAC are displayed beneath a green &lt;em&gt;Check &lt;/em&gt;icon; items
that are not supported are displayed under a red &lt;em&gt;X &lt;/em&gt;icon; and items that are
supported, but rely on unsupported items are displayed under a yellow &lt;em&gt;Exclamation &lt;/em&gt;icon.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_4.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 3&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Supported items present no problem to DAC. 
&lt;/p&gt;
&lt;p&gt;
Unsupported items appear as errors. Unfortunately, you will not be allowed to proceed
until these items are removed from the database. Fortunately, the wizard is non-modal,
so you can minimize it and switch back to Management Studio to remove these items
before re-running the Validation.
&lt;/p&gt;
&lt;p&gt;
Click the &lt;em&gt;Next&lt;/em&gt; button to start building the DAC package. 
&lt;/p&gt;
&lt;p&gt;
When complete, the Build Package screen (Figure 4) displays, indicating success or
listing problems that occurred.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_5.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_5.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 4&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Click the &lt;em&gt;Finish &lt;/em&gt;button to close the wizard. A file with the extension DACPAC
is created.
&lt;/p&gt;
&lt;p&gt;
Deploying the Schema in a DAC
&lt;/p&gt;
&lt;p&gt;
After creating a DAC, you can use SQL Server Management Studio to deploy the DAC’s
schema to a new database. To begin, launch SQL Server Management Studio, expand the &lt;em&gt;Management &lt;/em&gt;node,
and right-click the &lt;em&gt;Data-tier applications &lt;/em&gt;node. From the context menu, select &lt;font face="Courier New"&gt;Deploy
Data-tier application&lt;/font&gt;. The The &lt;em&gt;Introduction &lt;/em&gt;screen (Figure 5) of the &lt;em&gt;Deploy
Data-tier application &lt;/em&gt;wizard displays.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_6.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 5&lt;/strong&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Click the &lt;em&gt;Next &lt;/em&gt;button to display the &lt;em&gt;Select Package &lt;/em&gt;screen (Figure
6). 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_7.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 6&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Click the &lt;em&gt;Browse &lt;/em&gt;button and select the DACPAC file created above. Click Open.
Click the Next button to display the &lt;em&gt;Update Configuration &lt;/em&gt;screen (Figure
7). 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.davidgiard.com/content/binary/SQL-Server-Data-Tier-Applications_7CAE/image_thumb_8.png" width="244" height="227" /&gt;&lt;/a&gt; 
&lt;br /&gt;
&lt;strong&gt;Figure 7&lt;/strong&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
At the &lt;em&gt;Name &lt;/em&gt;field, enter a name for the database you wish to create. This
field defaults to the name of the database from which the DAC originated. If you are
running this deployment on the same server instance on which you created the DACPAC,
this will cause a conflict and SQL Server will notify you with a red exclamation icon
next to the &lt;em&gt;Name &lt;/em&gt;field.
&lt;/p&gt;
&lt;p&gt;
Click &lt;em&gt;Next &lt;/em&gt;to begin the deployment. When the deployment completes, the &lt;em&gt;Summary &lt;/em&gt;screen
(Figure 8) displays.
&lt;/p&gt;
&lt;p&gt;
You should notice the new database appears beneath the &lt;em&gt;Database &lt;/em&gt;node and
the DAC is registered and appears beneath the &lt;em&gt;Management \ Data-tier applications &lt;/em&gt;node.
You may need to refresh these nodes in order to view them.
&lt;/p&gt;
&lt;p&gt;
Note that the new database contains no objects – only database objects, such as tables,
views, stored procedures, and users.
&lt;/p&gt;
&lt;p&gt;
In this article, we discussed Data-tier applications and described how to use SQL
Server Management Studio to create and deploy a DACPAC file.
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=c182bdce-9f3d-43e3-95a3-b42e3d8bd114" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,c182bdce-9f3d-43e3-95a3-b42e3d8bd114.aspx</comments>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f782bf30-de17-42ed-a2ce-4049ee8de380</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f782bf30-de17-42ed-a2ce-4049ee8de380.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f782bf30-de17-42ed-a2ce-4049ee8de380.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f782bf30-de17-42ed-a2ce-4049ee8de380</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 89</strong>
        </p>
        <p>
In this interview, Dane Morgridege describes the Entity Framework - an object relational
mapping tool from Microsoft. 
</p>
        <object id="viddler_2fdcb370" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370">
          <param name="_cx" value="11562" />
          <param name="_cy" value="9789" />
          <param name="FlashVars" value="" />
          <param name="Movie" value="http://www.viddler.com/player/2fdcb370/" />
          <param name="Src" value="http://www.viddler.com/player/2fdcb370/" />
          <param name="WMode" value="Window" />
          <param name="Play" value="-1" />
          <param name="Loop" value="-1" />
          <param name="Quality" value="High" />
          <param name="SAlign" value="" />
          <param name="Menu" value="-1" />
          <param name="Base" value="" />
          <param name="AllowScriptAccess" value="always" />
          <param name="Scale" value="ShowAll" />
          <param name="DeviceFont" value="0" />
          <param name="EmbedMovie" value="0" />
          <param name="BGColor" value="" />
          <param name="SWRemote" value="" />
          <param name="MovieData" value="" />
          <param name="SeamlessTabbing" value="1" />
          <param name="Profile" value="0" />
          <param name="ProfileAddress" value="" />
          <param name="ProfilePort" value="0" />
          <param name="AllowNetworking" value="all" />
          <param name="AllowFullScreen" value="true" />
          <embed height="370" width="437" name="viddler_2fdcb370" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.viddler.com/player/2fdcb370/">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f782bf30-de17-42ed-a2ce-4049ee8de380" />
      </body>
      <title>Dane Morgridge on The Entity Framework</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f782bf30-de17-42ed-a2ce-4049ee8de380.aspx</guid>
      <link>http://www.davidgiard.com/2010/05/24/DaneMorgridgeOnTheEntityFramework.aspx</link>
      <pubDate>Mon, 24 May 2010 10:18:40 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 89&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this interview, Dane Morgridege describes the Entity Framework - an object relational
mapping tool from Microsoft. 
&lt;/p&gt;
&lt;object id=viddler_2fdcb370 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=370&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9789"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/player/2fdcb370/"&gt;
&lt;param name="Src" value="http://www.viddler.com/player/2fdcb370/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value=""&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed height="370" width="437" name="viddler_2fdcb370" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.viddler.com/player/2fdcb370/"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f782bf30-de17-42ed-a2ce-4049ee8de380" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f782bf30-de17-42ed-a2ce-4049ee8de380.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=a2949eb8-dd73-42a0-9726-434f40b6b500</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,a2949eb8-dd73-42a0-9726-434f40b6b500.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,a2949eb8-dd73-42a0-9726-434f40b6b500.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a2949eb8-dd73-42a0-9726-434f40b6b500</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 75</strong>
        </p>
        <p>
Sam Corder is the founder of the <a href="http://github.com/samus/mongodb-csharp">MongoDB-CSharp
open source project</a> In this interview, he describes the use of <a href="http://mongodb.org">MongoDB</a> and
other document database 
</p>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler_4a78eb52">
          <param name="movie" value="http://www.viddler.com/player/4a78eb52/" />
          <param name="allowScriptAccess" value="always" />
          <param name="allowFullScreen" value="true" />
          <embed src="http://www.viddler.com/player/4a78eb52/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_4a78eb52">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a2949eb8-dd73-42a0-9726-434f40b6b500" />
      </body>
      <title>Sam Corder on MongoDB</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,a2949eb8-dd73-42a0-9726-434f40b6b500.aspx</guid>
      <link>http://www.davidgiard.com/2010/03/01/SamCorderOnMongoDB.aspx</link>
      <pubDate>Mon, 01 Mar 2010 16:52:13 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 75&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Sam Corder is the founder of the &lt;a href="http://github.com/samus/mongodb-csharp"&gt;MongoDB-CSharp
open source project&lt;/a&gt; In this interview, he describes the use of &lt;a href="http://mongodb.org"&gt;MongoDB&lt;/a&gt; and
other document database 
&lt;/p&gt;
&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler_4a78eb52"&gt;
&lt;param name="movie" value="http://www.viddler.com/player/4a78eb52/" /&gt;
&lt;param name="allowScriptAccess" value="always" /&gt;
&lt;param name="allowFullScreen" value="true" /&gt;&lt;embed src="http://www.viddler.com/player/4a78eb52/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_4a78eb52"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a2949eb8-dd73-42a0-9726-434f40b6b500" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,a2949eb8-dd73-42a0-9726-434f40b6b500.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=1d67514d-42cd-448c-ba01-9d477746ba36</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,1d67514d-42cd-448c-ba01-9d477746ba36.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,1d67514d-42cd-448c-ba01-9d477746ba36.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1d67514d-42cd-448c-ba01-9d477746ba36</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When writing .Net code (or code in any language for that matter) that updates a database,
you need to be cognizant of the fact that it takes a finite amount of time to connect
to a database and process any commands sent to the database. 
</p>
        <p>
ADO.Net permits you to set a TimeOut value on a Connection object and on a Command
object. 
</p>
        <p>
The Command TimeOut property allows you to configure how long a command waits to successfully
complete execution of a query. By default, a Command object will timeout after 30
seconds
</p>
        <p>
It’s important to strike a good balance when setting timeout values. 
</p>
        <p>
Sometimes we expect a database action to take a long time and we want to give it time
to complete before we pull the rug out, so to speak.
</p>
        <p>
On the other hand, if a problem prevents a command from executing properly, it's useful
to know this sooner so our application can handle it.
</p>
        <p>
Changing a command timeout is simple. The Command object exposes a read/write ConnectionTimeout
property. Set it to the number of seconds you wish the comand to wait on executing
before aborting.
</p>
        <p>
After the Command TimeOut period, if the command has not completed, an exception is
thrown. However, the database server does not know this, so the command will continue
to execute on the server - your application just won't know the results.
</p>
        <p>
The Connection TimeOut is the amount of time the Connection will spend attempting
to connect to a database before giving up and throwing an exception. The default Connection
Timeout value is 15 seconds. On a slow network, it may take longer to connect, so
you may wish to increase this value. However, if the application is unable to connect
to the database - if the server is unavailable, for example - it's best to find this
out sooner rather than later.
</p>
        <p>
Changing the Connection Timeout is less obvious than changing the Command Timeout.
The Connection class exposes a ConnectionTimeout property; But this property is read-only,
so you cannot use it to change the timeout. To change a timeout, you must modify the
connection string. Add or update the following to your connection string:<br />
    Connection Timeout=XXX<br />
where XXX is the number of seconds to wait for a connection to remain open before
aborting all pending operations on that connection.
</p>
        <p>
In your applications, it is important to strike the right balance when setting timeout
properties.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1d67514d-42cd-448c-ba01-9d477746ba36" />
      </body>
      <title>TimeOuts in ADO.Net</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,1d67514d-42cd-448c-ba01-9d477746ba36.aspx</guid>
      <link>http://www.davidgiard.com/2009/12/10/TimeOutsInADONet.aspx</link>
      <pubDate>Thu, 10 Dec 2009 15:25:03 GMT</pubDate>
      <description>&lt;p&gt;
When writing .Net code (or code in any language for that matter) that updates a database,
you need to be cognizant of the fact that it takes a finite amount of time to connect
to a database and process any commands sent to the database. 
&lt;/p&gt;
&lt;p&gt;
ADO.Net permits you to set a TimeOut value on a Connection object and on a Command
object. 
&lt;/p&gt;
&lt;p&gt;
The Command TimeOut property allows you to configure how long a command waits to successfully
complete execution of a query. By default, a Command object will timeout after 30
seconds
&lt;/p&gt;
&lt;p&gt;
It’s important to strike a good balance when setting timeout values. 
&lt;/p&gt;
&lt;p&gt;
Sometimes we expect a database action to take a long time and we want to give it time
to complete before we pull the rug out, so to speak.
&lt;/p&gt;
&lt;p&gt;
On the other hand, if a problem prevents a command from executing properly, it's useful
to know this sooner so our application can handle it.
&lt;/p&gt;
&lt;p&gt;
Changing a command timeout is simple. The Command object exposes a read/write ConnectionTimeout
property. Set it to the number of seconds you wish the comand to wait on executing
before aborting.
&lt;/p&gt;
&lt;p&gt;
After the Command TimeOut period, if the command has not completed, an exception is
thrown. However, the database server does not know this, so the command will continue
to execute on the server - your application just won't know the results.
&lt;/p&gt;
&lt;p&gt;
The Connection TimeOut is the amount of time the Connection will spend attempting
to connect to a database before giving up and throwing an exception. The default Connection
Timeout value is 15 seconds. On a slow network, it may take longer to connect, so
you may wish to increase this value. However, if the application is unable to connect
to the database - if the server is unavailable, for example - it's best to find this
out sooner rather than later.
&lt;/p&gt;
&lt;p&gt;
Changing the Connection Timeout is less obvious than changing the Command Timeout.
The Connection class exposes a ConnectionTimeout property; But this property is read-only,
so you cannot use it to change the timeout. To change a timeout, you must modify the
connection string. Add or update the following to your connection string:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Connection Timeout=XXX&lt;br&gt;
where XXX is the number of seconds to wait for a connection to remain open before
aborting all pending operations on that connection.
&lt;/p&gt;
&lt;p&gt;
In your applications, it is important to strike the right balance when setting timeout
properties.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1d67514d-42cd-448c-ba01-9d477746ba36" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,1d67514d-42cd-448c-ba01-9d477746ba36.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=4ad43afb-3502-4113-b8fe-7833d263fe33</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,4ad43afb-3502-4113-b8fe-7833d263fe33.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,4ad43afb-3502-4113-b8fe-7833d263fe33.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4ad43afb-3502-4113-b8fe-7833d263fe33</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 53</strong>
        </p>
        <p>
          <a target="_blank" href="http://jbknet.blogspot.com/">Joe Kunk</a> is writing a chapter
covering XTraReports for Paul Kimmel's upcoming DevExpress tools book. In this interview,
Joe describes XTraReports and how to use it.
</p>
        <object id="viddler_204f3d4" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370">
          <param name="_cx" value="11562" />
          <param name="_cy" value="9789" />
          <param name="FlashVars" value="" />
          <param name="Movie" value="http://www.viddler.com/player/204f3d4/" />
          <param name="Src" value="http://www.viddler.com/player/204f3d4/" />
          <param name="WMode" value="Window" />
          <param name="Play" value="-1" />
          <param name="Loop" value="-1" />
          <param name="Quality" value="High" />
          <param name="SAlign" value="" />
          <param name="Menu" value="-1" />
          <param name="Base" value="" />
          <param name="AllowScriptAccess" value="always" />
          <param name="Scale" value="ShowAll" />
          <param name="DeviceFont" value="0" />
          <param name="EmbedMovie" value="0" />
          <param name="BGColor" value="" />
          <param name="SWRemote" value="" />
          <param name="MovieData" value="" />
          <param name="SeamlessTabbing" value="1" />
          <param name="Profile" value="0" />
          <param name="ProfileAddress" value="" />
          <param name="ProfilePort" value="0" />
          <param name="AllowNetworking" value="all" />
          <param name="AllowFullScreen" value="true" />
          <embed src="http://www.viddler.com/player/204f3d4/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_204f3d4">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=4ad43afb-3502-4113-b8fe-7833d263fe33" />
      </body>
      <title>Joe Kunk on DevExpress XTraReports</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,4ad43afb-3502-4113-b8fe-7833d263fe33.aspx</guid>
      <link>http://www.davidgiard.com/2009/09/23/JoeKunkOnDevExpressXTraReports.aspx</link>
      <pubDate>Wed, 23 Sep 2009 04:10:51 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 53&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a target=_blank href="http://jbknet.blogspot.com/"&gt;Joe Kunk&lt;/a&gt; is writing a chapter
covering XTraReports for Paul Kimmel's upcoming DevExpress tools book. In this interview,
Joe describes XTraReports and how to use it.
&lt;/p&gt;
&lt;object id=viddler_204f3d4 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=370&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9789"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/player/204f3d4/"&gt;
&lt;param name="Src" value="http://www.viddler.com/player/204f3d4/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value=""&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/player/204f3d4/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_204f3d4"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=4ad43afb-3502-4113-b8fe-7833d263fe33" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,4ad43afb-3502-4113-b8fe-7833d263fe33.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=b94ee586-ed6d-4559-b945-f339b21c173e</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,b94ee586-ed6d-4559-b945-f339b21c173e.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,b94ee586-ed6d-4559-b945-f339b21c173e.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b94ee586-ed6d-4559-b945-f339b21c173e</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 52</strong>
        </p>
        <p>
Often, an application experiences a bottleneck retrieving and delivering data from
a database. In this interfview, <a target="_blank" href="http://facility9.com/">Jeremiah
Peschka</a> discusses ways to troubleshoot performance issues within a database.<br /></p>
        <object id="viddler_7b8c3b65" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370">
          <param name="_cx" value="11562" />
          <param name="_cy" value="9789" />
          <param name="FlashVars" value="" />
          <param name="Movie" value="http://www.viddler.com/player/7b8c3b65/" />
          <param name="Src" value="http://www.viddler.com/player/7b8c3b65/" />
          <param name="WMode" value="Window" />
          <param name="Play" value="-1" />
          <param name="Loop" value="-1" />
          <param name="Quality" value="High" />
          <param name="SAlign" value="" />
          <param name="Menu" value="-1" />
          <param name="Base" value="" />
          <param name="AllowScriptAccess" value="always" />
          <param name="Scale" value="ShowAll" />
          <param name="DeviceFont" value="0" />
          <param name="EmbedMovie" value="0" />
          <param name="BGColor" value="" />
          <param name="SWRemote" value="" />
          <param name="MovieData" value="" />
          <param name="SeamlessTabbing" value="1" />
          <param name="Profile" value="0" />
          <param name="ProfileAddress" value="" />
          <param name="ProfilePort" value="0" />
          <param name="AllowNetworking" value="all" />
          <param name="AllowFullScreen" value="true" />
          <embed src="http://www.viddler.com/player/7b8c3b65/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_7b8c3b65">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=b94ee586-ed6d-4559-b945-f339b21c173e" />
      </body>
      <title>Jeremiah Peschka on Troubleshooting SQL Performance</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,b94ee586-ed6d-4559-b945-f339b21c173e.aspx</guid>
      <link>http://www.davidgiard.com/2009/09/21/JeremiahPeschkaOnTroubleshootingSQLPerformance.aspx</link>
      <pubDate>Mon, 21 Sep 2009 11:29:45 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 52&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Often, an application experiences a bottleneck retrieving and delivering data from
a database. In this interfview, &lt;a target=_blank href="http://facility9.com/"&gt;Jeremiah
Peschka&lt;/a&gt; discusses ways to troubleshoot performance issues within a database.&lt;br&gt;
&lt;/p&gt;
&lt;object id=viddler_7b8c3b65 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=370&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9789"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/player/7b8c3b65/"&gt;
&lt;param name="Src" value="http://www.viddler.com/player/7b8c3b65/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value=""&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/player/7b8c3b65/" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_7b8c3b65"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=b94ee586-ed6d-4559-b945-f339b21c173e" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,b94ee586-ed6d-4559-b945-f339b21c173e.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=0a4c1c0e-22d0-42ce-ae40-86ce986d0139</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,0a4c1c0e-22d0-42ce-ae40-86ce986d0139.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,0a4c1c0e-22d0-42ce-ae40-86ce986d0139.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0a4c1c0e-22d0-42ce-ae40-86ce986d0139</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        </p>
        <p>
This series of articles provides an introduction to relational databases in general
and Microsoft SQL Server in particular.
</p>
        <p>
          <a href="http://www.davidgiard.com/2009/02/24/SQL101Part1WhatIsADatabase.aspx">Part
1: What is a Database?</a>
        </p>
        <p>
          <a href="http://www.davidgiard.com/2009/02/26/SQL101Part2Relationships.aspx">Part
2: Relationships</a>
        </p>
        <p>
          <a href="http://www.davidgiard.com/2009/03/10/SQL101Part3SelectingDataFromATable.aspx">Part
3: Selecting data from a table</a>
        </p>
        <p>
          <a href="http://www.davidgiard.com/2009/03/12/SQL101Part4AggregatingData.aspx">Part
4: Aggregating data</a>
        </p>
        <p>
          <a href="http://www.davidgiard.com/2009/03/21/SQL101Part5Joins.aspx">Part 5: Joins</a>
        </p>
        <p>
          <a href="http://www.davidgiard.com/2009/03/27/SQL101Part6InsertsUpdatesAndDeletes.aspx">Part
6: Inserts, Updates and Deletes</a>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=0a4c1c0e-22d0-42ce-ae40-86ce986d0139" />
      </body>
      <title>SQL 101</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,0a4c1c0e-22d0-42ce-ae40-86ce986d0139.aspx</guid>
      <link>http://www.davidgiard.com/2009/08/31/SQL101.aspx</link>
      <pubDate>Mon, 31 Aug 2009 12:04:07 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt;
&lt;/p&gt;
&lt;p&gt;
This series of articles provides an introduction to relational databases in general
and Microsoft SQL Server in particular.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/02/24/SQL101Part1WhatIsADatabase.aspx"&gt;Part
1: What is a Database?&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/02/26/SQL101Part2Relationships.aspx"&gt;Part
2: Relationships&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/03/10/SQL101Part3SelectingDataFromATable.aspx"&gt;Part
3: Selecting data from a table&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/03/12/SQL101Part4AggregatingData.aspx"&gt;Part
4: Aggregating data&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/03/21/SQL101Part5Joins.aspx"&gt;Part 5: Joins&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.davidgiard.com/2009/03/27/SQL101Part6InsertsUpdatesAndDeletes.aspx"&gt;Part
6: Inserts, Updates and Deletes&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=0a4c1c0e-22d0-42ce-ae40-86ce986d0139" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,0a4c1c0e-22d0-42ce-ae40-86ce986d0139.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=dc972245-3c24-4824-8a7b-d96693eec0bf</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,dc972245-3c24-4824-8a7b-d96693eec0bf.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,dc972245-3c24-4824-8a7b-d96693eec0bf.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=dc972245-3c24-4824-8a7b-d96693eec0bf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 45</strong>
        </p>
        <p>
In this interview, <a href="http://jessicammoss.blogspot.com/" target="_blank">Jessica
Moss</a> describes SQL Server Integration Services (SSIS): What it is; how it works;
and how to get started learning and using it.
</p>
        <object id="viddler_6b773566" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="348">
          <param name="_cx" value="11562" />
          <param name="_cy" value="9207" />
          <param name="FlashVars" value="" />
          <param name="Movie" value="http://www.viddler.com/simple/6b773566/" />
          <param name="Src" value="http://www.viddler.com/simple/6b773566/" />
          <param name="WMode" value="Window" />
          <param name="Play" value="-1" />
          <param name="Loop" value="-1" />
          <param name="Quality" value="High" />
          <param name="SAlign" value="LT" />
          <param name="Menu" value="-1" />
          <param name="Base" value="" />
          <param name="AllowScriptAccess" value="always" />
          <param name="Scale" value="ShowAll" />
          <param name="DeviceFont" value="0" />
          <param name="EmbedMovie" value="0" />
          <param name="BGColor" value="" />
          <param name="SWRemote" value="" />
          <param name="MovieData" value="" />
          <param name="SeamlessTabbing" value="1" />
          <param name="Profile" value="0" />
          <param name="ProfileAddress" value="" />
          <param name="ProfilePort" value="0" />
          <param name="AllowNetworking" value="all" />
          <param name="AllowFullScreen" value="true" />
          <embed src="http://www.viddler.com/simple/6b773566/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_6b773566">
          </embed>
        </object>
        <p>
          <font size="1">7 mins, 48 secs </font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=dc972245-3c24-4824-8a7b-d96693eec0bf" />
      </body>
      <title>Jessica Moss on SSIS</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,dc972245-3c24-4824-8a7b-d96693eec0bf.aspx</guid>
      <link>http://www.davidgiard.com/2009/08/28/JessicaMossOnSSIS.aspx</link>
      <pubDate>Fri, 28 Aug 2009 08:12:57 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 45&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this interview, &lt;a href="http://jessicammoss.blogspot.com/" target=_blank&gt;Jessica
Moss&lt;/a&gt; describes SQL Server Integration Services (SSIS): What it is; how it works;
and how to get started learning and using it.
&lt;/p&gt;
&lt;object id=viddler_6b773566 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=348&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9207"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/simple/6b773566/"&gt;
&lt;param name="Src" value="http://www.viddler.com/simple/6b773566/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value="LT"&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/simple/6b773566/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_6b773566"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;p&gt;
&lt;font size=1&gt;7 mins, 48 secs &lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=dc972245-3c24-4824-8a7b-d96693eec0bf" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,dc972245-3c24-4824-8a7b-d96693eec0bf.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=cc9543d6-1493-4c5c-8b04-b1dd3d77e069</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,cc9543d6-1493-4c5c-8b04-b1dd3d77e069.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,cc9543d6-1493-4c5c-8b04-b1dd3d77e069.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cc9543d6-1493-4c5c-8b04-b1dd3d77e069</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 32</strong>
        </p>
        <p>
In this video, author and speaker <a href="http://finsel.com" target="_blank">Josef
Finsel</a> describes moving databases to "The Cloud" using Azure Table storage. 
You can read more of his thoughts on the subject at <a href="http://azuredba.com/blog.aspx" target="_blank">http://azuredba.com/blog.aspx</a></p>
        <p>
          <object id="viddler_182e135f" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="348">
            <param name="_cx" value="11562" />
            <param name="_cy" value="9207" />
            <param name="FlashVars" value="" />
            <param name="Movie" value="http://www.viddler.com/simple/182e135f/" />
            <param name="Src" value="http://www.viddler.com/simple/182e135f/" />
            <param name="WMode" value="Window" />
            <param name="Play" value="-1" />
            <param name="Loop" value="-1" />
            <param name="Quality" value="High" />
            <param name="SAlign" value="LT" />
            <param name="Menu" value="-1" />
            <param name="Base" value="" />
            <param name="AllowScriptAccess" value="always" />
            <param name="Scale" value="ShowAll" />
            <param name="DeviceFont" value="0" />
            <param name="EmbedMovie" value="0" />
            <param name="BGColor" value="" />
            <param name="SWRemote" value="" />
            <param name="MovieData" value="" />
            <param name="SeamlessTabbing" value="1" />
            <param name="Profile" value="0" />
            <param name="ProfileAddress" value="" />
            <param name="ProfilePort" value="0" />
            <param name="AllowNetworking" value="all" />
            <param name="AllowFullScreen" value="true" />
            <embed src="http://www.viddler.com/simple/182e135f/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_182e135f">
            </embed>
          </object>
        </p>
        <p>
          <font size="1">11 mins, 9 secs</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cc9543d6-1493-4c5c-8b04-b1dd3d77e069" />
      </body>
      <title>Josef Finsel on Azure Table Storage</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,cc9543d6-1493-4c5c-8b04-b1dd3d77e069.aspx</guid>
      <link>http://www.davidgiard.com/2009/07/08/JosefFinselOnAzureTableStorage.aspx</link>
      <pubDate>Wed, 08 Jul 2009 11:46:42 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 32&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this video, author and speaker &lt;a href="http://finsel.com" target=_blank&gt;Josef
Finsel&lt;/a&gt; describes moving databases to "The Cloud" using Azure Table storage.&amp;nbsp;
You can read more of his thoughts on the subject at &lt;a href="http://azuredba.com/blog.aspx" target=_blank&gt;http://azuredba.com/blog.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;object id=viddler_182e135f classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=348&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9207"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/simple/182e135f/"&gt;
&lt;param name="Src" value="http://www.viddler.com/simple/182e135f/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value="LT"&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/simple/182e135f/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_182e135f"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;11 mins, 9 secs&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cc9543d6-1493-4c5c-8b04-b1dd3d77e069" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,cc9543d6-1493-4c5c-8b04-b1dd3d77e069.aspx</comments>
      <category>Azure</category>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 31</strong>
        </p>
        <p>
In this interview, <a href="http://www.thinqlinq.com/" target="_blank">Jim Wooley</a> discusses
the relevance of stored procedures and best practices for accessing a database.
</p>
        <p>
          <object id="viddler_ce93ee6d" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="348">
            <param name="_cx" value="11562" />
            <param name="_cy" value="9207" />
            <param name="FlashVars" value="" />
            <param name="Movie" value="http://www.viddler.com/simple/ce93ee6d/" />
            <param name="Src" value="http://www.viddler.com/simple/ce93ee6d/" />
            <param name="WMode" value="Window" />
            <param name="Play" value="-1" />
            <param name="Loop" value="-1" />
            <param name="Quality" value="High" />
            <param name="SAlign" value="LT" />
            <param name="Menu" value="-1" />
            <param name="Base" value="" />
            <param name="AllowScriptAccess" value="always" />
            <param name="Scale" value="ShowAll" />
            <param name="DeviceFont" value="0" />
            <param name="EmbedMovie" value="0" />
            <param name="BGColor" value="" />
            <param name="SWRemote" value="" />
            <param name="MovieData" value="" />
            <param name="SeamlessTabbing" value="1" />
            <param name="Profile" value="0" />
            <param name="ProfileAddress" value="" />
            <param name="ProfilePort" value="0" />
            <param name="AllowNetworking" value="all" />
            <param name="AllowFullScreen" value="true" />
            <embed src="http://www.viddler.com/simple/ce93ee6d/" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_ce93ee6d" width="437" height="348">
            </embed>
          </object>
        </p>
        <p>
13 mins, 32 secs 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f" />
      </body>
      <title>Jim Wooley on Stored Procedures and Data Access</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f.aspx</guid>
      <link>http://www.davidgiard.com/2009/07/05/JimWooleyOnStoredProceduresAndDataAccess.aspx</link>
      <pubDate>Sun, 05 Jul 2009 23:16:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 31&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this interview, &lt;a href="http://www.thinqlinq.com/" target=_blank&gt;Jim Wooley&lt;/a&gt; discusses
the relevance of stored procedures and best practices for accessing a database.
&lt;/p&gt;
&lt;p&gt;
&lt;object id=viddler_ce93ee6d classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=348&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9207"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/simple/ce93ee6d/"&gt;
&lt;param name="Src" value="http://www.viddler.com/simple/ce93ee6d/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value="LT"&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/simple/ce93ee6d/" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_ce93ee6d" width="437" height="348"&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;p&gt;
13 mins, 32 secs 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,ca2ebf38-9bc6-4fb7-9437-2335c32a4b9f.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=6257f4a8-134a-4f18-9372-7c38ed4c7219</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,6257f4a8-134a-4f18-9372-7c38ed4c7219.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,6257f4a8-134a-4f18-9372-7c38ed4c7219.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6257f4a8-134a-4f18-9372-7c38ed4c7219</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        <div style="BORDER-RIGHT: thin solid; BORDER-TOP: thin solid; MARGIN: 5px; BORDER-LEFT: thin solid; WIDTH: 80%; BORDER-BOTTOM: thin solid; BACKGROUND-COLOR: silver">
          <p>
NOTE: 
</p>
          <p>
For demos in this article, we will use a table named Customer that contains the following
columns: 
</p>
          <table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border="1">
            <tbody>
              <tr>
                <td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left">
                  <font size="1">Name </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left">
                  <font size="1">Data Type </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">FirstName</font>
                </td>
                <td>
                  <font size="1">nvarchar(50)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">LastName</font>
                </td>
                <td>
                  <font size="1">nvarchar(50)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">StreetAddress</font>
                </td>
                <td>
                  <font size="1">nvarchar(255)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">City</font>
                </td>
                <td>
                  <font size="1">nvarchar(255)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">State</font>
                </td>
                <td>
                  <font size="1">char(2)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">ZipCode</font>
                </td>
                <td>
                  <font size="1">nvarchar(10)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">TotalSales</font>
                </td>
                <td>
                  <font size="1">decimal(18,2)</font>
                </td>
              </tr>
            </tbody>
          </table>
          <p>
In addition, I created a primary key on the CustID column and set it to autoincrement
by setting the following properties: 
</p>
          <table style="MARGIN-LEFT: 40px" border="0">
            <tbody>
              <tr>
                <td>
Is Identity 
</td>
                <td>
Yes 
</td>
              </tr>
              <tr>
                <td>
Identity Seed 
</td>
                <td>
1 
</td>
              </tr>
              <tr>
                <td>
Identity Seed 
</td>
                <td>
1 
</td>
              </tr>
            </tbody>
          </table>
          <p>
Afer adding a couple rows to the table, the data looks like this. 
</p>
          <table border="1">
            <tbody>
              <tr>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">CustID </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">FirstName </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">LastName </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">StreetAddress </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">City </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">State </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">ZipCode </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">TotalSales </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">1</font>
                </td>
                <td>
                  <font size="1">Steve</font>
                </td>
                <td>
                  <font size="1">Smith</font>
                </td>
                <td>
                  <font size="1">900 Belle St</font>
                </td>
                <td>
                  <font size="1">Detroit</font>
                </td>
                <td>
                  <font size="1">MI</font>
                </td>
                <td>
                  <font size="1">48888</font>
                </td>
                <td>
                  <font size="1">5000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">2</font>
                </td>
                <td>
                  <font size="1">Ryan</font>
                </td>
                <td>
                  <font size="1">Miller</font>
                </td>
                <td>
                  <font size="1">1 Shutout Ct</font>
                </td>
                <td>
                  <font size="1">Buffalo</font>
                </td>
                <td>
                  <font size="1">NY</font>
                </td>
                <td>
                  <font size="1">32323</font>
                </td>
                <td>
                  <font size="1">250.00</font>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <p>
We can use the INSERT command to add a new row to this table. The syntax of the INSERT
command is 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> [TableName]
    (     [Column List]     ) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VALUES</span>     (
    [Values List]     ) </span>
        </pre>
        <p>
We can insert a row for a new Customer - Brad Van Pelt - with the following code. 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> Customer
    (     FirstName,     LastName,
    StreetAddress,     City,     State,
    ZipCode,     TotalSales     ) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VALUES</span>     (
    <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Brad'</span>,
    <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Van
Pelt'</span>,     <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'99
Linebaker Ln'</span>,     <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Owosso'</span>,
    <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'MI'</span>,
    <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'47777'</span>,
    4000     ) </span>
        </pre>
        <p>
Notice that each column name in the first set of parentheses matches a value in the
second set of parentheses: 'Brad' with <i>FirstName</i>, 'Van Pelt' with <i>LastName</i> and
so on. Notice also that we did not provide a value for the <i>CustID</i> column. This
is because <i>CustID</i> is an identity column and, therefore, gets populated with
an incremented number when a new row is added. 
</p>
        <p>
After executing the above INSERT statement, our data should look like this: 
</p>
        <table border="1">
          <tbody>
            <tr>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">CustID </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">FirstName </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">LastName </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">StreetAddress </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">City </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">State </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">ZipCode </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">TotalSales </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">1</font>
              </td>
              <td>
                <font size="1">Steve</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
              <td>
                <font size="1">900 Belle St</font>
              </td>
              <td>
                <font size="1">Detroit</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">48888</font>
              </td>
              <td>
                <font size="1">5000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">2</font>
              </td>
              <td>
                <font size="1">Ryan</font>
              </td>
              <td>
                <font size="1">Miller</font>
              </td>
              <td>
                <font size="1">1 Shutout Ct</font>
              </td>
              <td>
                <font size="1">Buffalo</font>
              </td>
              <td>
                <font size="1">NY</font>
              </td>
              <td>
                <font size="1">32323</font>
              </td>
              <td>
                <font size="1">250.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">3</font>
              </td>
              <td>
                <font size="1">Brad</font>
              </td>
              <td>
                <font size="1">Van Pelt</font>
              </td>
              <td>
                <font size="1">99 Linebaker Ln</font>
              </td>
              <td>
                <font size="1">Owosso</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">47777</font>
              </td>
              <td>
                <font size="1">4000.00</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
In this article, we showed how to use T-SQL's INSERT, UPDATE, and DELETE commands
to modify the data in a table. 
</p>
        <p>
The new customer was automatically assigned a <i>CustID</i> value of 3. Because this
value uniquely identifies the newly-added row, we can use it to find and update that
row. The syntax to update a row in SQL Server is 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> [Table]
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> [Column1]
= [New Value 1],         [Column2] = [New
Value 2],         [Column3] = [New Value 3],
        etc...     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> [Filter
Condition] </span>
        </pre>
        <p>
Only rows that match the filter condition will be updated and only those columns specified
in the SET clause will be updated.  We will use the following command to update
the <i>StreetAddress</i>, <i>City</i>, <i>State</i> and <i>ZipCdoe</i> columns of
Customer 3:
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> Customer
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> StreetAddress
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'100
Safety St'</span>,         City=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'New
York'</span>,         State=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'NY'</span>         ZipCode=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'01111'</span>     <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> CustID
= 3 </span>
        </pre>
        <p>
After executing the above UPDATE command, our data should like this:
</p>
        <table border="1">
          <tbody>
            <tr>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>CustID </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>FirstName </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>LastName </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>StreetAddress </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>City </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>State </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>ZipCode </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>TotalSales</strong>
                </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">1</font>
              </td>
              <td>
                <font size="1">Steve</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
              <td>
                <font size="1">900 Belle St</font>
              </td>
              <td>
                <font size="1">Detroit</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">48888</font>
              </td>
              <td>
                <font size="1">5000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">2</font>
              </td>
              <td>
                <font size="1">Ryan</font>
              </td>
              <td>
                <font size="1">Miller</font>
              </td>
              <td>
                <font size="1">1 Shutout Ct</font>
              </td>
              <td>
                <font size="1">Buffalo</font>
              </td>
              <td>
                <font size="1">NY</font>
              </td>
              <td>
                <font size="1">32323</font>
              </td>
              <td>
                <font size="1">250.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">3</font>
              </td>
              <td>
                <font size="1">Brad</font>
              </td>
              <td>
                <font size="1">Van Pelt</font>
              </td>
              <td>
                <font size="1">100 Safety St</font>
              </td>
              <td>
                <font size="1">New York</font>
              </td>
              <td>
                <font size="1">NY</font>
              </td>
              <td>
                <font size="1">01111</font>
              </td>
              <td>
                <font size="1">4000.00</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
We use the DELETE command to delete rows in a SQL Server table. The DELETE syntax
is 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DELETE</span> Customer
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> CustID
= 3 </span>
        </pre>
        <p>
The following code will delete Customer 3 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DELETE</span> Customer
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> CustID
= 3 </span>
        </pre>
        <p>
After executing the above DELETE command, our data will look like this: 
</p>
        <table border="1">
          <tbody>
            <tr>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>CustID </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>FirstName </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>LastName </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>StreetAddress </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>City </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>State </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>ZipCode </strong>
                </font>
              </td>
              <td style="COLOR: black; BACKGROUND-COLOR: white">
                <font size="1">
                  <strong>TotalSales</strong>
                </font>
              </td>
            </tr>
            <tr>
              <td>
                <font color="#000000" size="1">1</font>
              </td>
              <td>
                <font color="#000000" size="1">Steve</font>
              </td>
              <td>
                <font color="#000000" size="1">Smith</font>
              </td>
              <td>
                <font color="#000000" size="1">900 Belle St</font>
              </td>
              <td>
                <font color="#000000" size="1">Detroit</font>
              </td>
              <td>
                <font color="#000000" size="1">MI</font>
              </td>
              <td>
                <font color="#000000" size="1">48888</font>
              </td>
              <td>
                <font color="#000000" size="1">5000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font color="#000000" size="1">2</font>
              </td>
              <td>
                <font color="#000000" size="1">Ryan</font>
              </td>
              <td>
                <font color="#000000" size="1">Miller</font>
              </td>
              <td>
                <font color="#000000" size="1">1 Shutout Ct</font>
              </td>
              <td>
                <font color="#000000" size="1">Buffalo</font>
              </td>
              <td>
                <font color="#000000" size="1">NY</font>
              </td>
              <td>
                <font color="#000000" size="1">32323</font>
              </td>
              <td>
                <font color="#000000" size="1">250.00</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
In this article, we showed how to use the INSERT, UPDATE and DELETE commands to modify
data in a SQL Server table. 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=6257f4a8-134a-4f18-9372-7c38ed4c7219" />
      </body>
      <title>SQL 101 - Part 6: Inserts, Updates and Deletes</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,6257f4a8-134a-4f18-9372-7c38ed4c7219.aspx</guid>
      <link>http://www.davidgiard.com/2009/03/27/SQL101Part6InsertsUpdatesAndDeletes.aspx</link>
      <pubDate>Fri, 27 Mar 2009 04:18:46 GMT</pubDate>
      <description>&lt;img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;div style="BORDER-RIGHT: thin solid; BORDER-TOP: thin solid; MARGIN: 5px; BORDER-LEFT: thin solid; WIDTH: 80%; BORDER-BOTTOM: thin solid; BACKGROUND-COLOR: silver"&gt;
&lt;p&gt;
NOTE: 
&lt;/p&gt;
&lt;p&gt;
For demos in this article, we will use a table named Customer that contains the following
columns: 
&lt;/p&gt;
&lt;table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Name &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Data Type &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;FirstName&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(50)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;LastName&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(50)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;StreetAddress&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(255)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;City&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(255)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;State&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;char(2)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;ZipCode&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(10)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;TotalSales&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;decimal(18,2)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
In addition, I created a primary key on the CustID column and set it to autoincrement
by setting the following properties: 
&lt;/p&gt;
&lt;table style="MARGIN-LEFT: 40px" border=0&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
Is Identity 
&lt;/td&gt;
&lt;td&gt;
Yes 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Identity Seed 
&lt;/td&gt;
&lt;td&gt;
1 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Identity Seed 
&lt;/td&gt;
&lt;td&gt;
1 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Afer adding a couple rows to the table, the data looks like this. 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;TotalSales &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ryan&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Miller&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1 Shutout Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Buffalo&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;32323&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;250.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;
We can use the INSERT command to add a new row to this table. The syntax of the INSERT
command is 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; [TableName]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Column List] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VALUES&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Values List] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
We can insert a row for a new Customer - Brad Van Pelt - with the following code. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;( &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StreetAddress, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;City, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ZipCode, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TotalSales &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VALUES&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Brad'&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Van
Pelt'&lt;/span&gt;, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'99
Linebaker Ln'&lt;/span&gt;, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Owosso'&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'MI'&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'47777'&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4000 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
Notice that each column name in the first set of parentheses matches a value in the
second set of parentheses: 'Brad' with &lt;i&gt;FirstName&lt;/i&gt;, 'Van Pelt' with &lt;i&gt;LastName&lt;/i&gt; and
so on. Notice also that we did not provide a value for the &lt;i&gt;CustID&lt;/i&gt; column. This
is because &lt;i&gt;CustID&lt;/i&gt; is an identity column and, therefore, gets populated with
an incremented number when a new row is added. 
&lt;/p&gt;
&lt;p&gt;
After executing the above INSERT statement, our data should look like this: 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;TotalSales &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ryan&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Miller&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1 Shutout Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Buffalo&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;32323&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;250.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Brad&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Van Pelt&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;99 Linebaker Ln&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Owosso&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;47777&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;4000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
In this article, we showed how to use T-SQL's INSERT, UPDATE, and DELETE commands
to modify the data in a table. 
&lt;/p&gt;
&lt;p&gt;
The new customer was automatically assigned a &lt;i&gt;CustID&lt;/i&gt; value of 3. Because this
value uniquely identifies the newly-added row, we can use it to find and update that
row. The syntax to update a row in SQL Server is 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; [Table]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; [Column1]
= [New Value 1], &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Column2] = [New
Value 2], &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Column3] = [New Value 3],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;etc... &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; [Filter
Condition] &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
Only rows that match the filter condition will be updated and only those columns specified
in the SET clause will be updated.&amp;nbsp; We will use the following command to update
the &lt;i&gt;StreetAddress&lt;/i&gt;, &lt;i&gt;City&lt;/i&gt;, &lt;i&gt;State&lt;/i&gt; and &lt;i&gt;ZipCdoe&lt;/i&gt; columns of
Customer 3:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; StreetAddress
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'100
Safety St'&lt;/span&gt;, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;City=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'New
York'&lt;/span&gt;, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'NY'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ZipCode=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'01111'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; CustID
= 3 &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
After executing the above UPDATE command, our data should like this:
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;CustID &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;FirstName &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;LastName &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;StreetAddress &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;City &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;State &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;ZipCode &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;TotalSales&lt;/strong&gt; &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ryan&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Miller&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1 Shutout Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Buffalo&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;32323&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;250.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Brad&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Van Pelt&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;100 Safety St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;New York&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;01111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;4000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
We use the DELETE command to delete rows in a SQL Server table. The DELETE syntax
is 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DELETE&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; CustID
= 3 &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
The following code will delete Customer 3 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DELETE&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; CustID
= 3 &lt;/span&gt; &lt;/pre&gt;
&lt;p&gt;
After executing the above DELETE command, our data will look like this: 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;CustID &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;FirstName &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;LastName &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;StreetAddress &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;City &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;State &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;ZipCode &lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;&lt;strong&gt;TotalSales&lt;/strong&gt; &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Ryan&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Miller&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;1 Shutout Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;Buffalo&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;32323&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font color=#000000 size=1&gt;250.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
In this article, we showed how to use the INSERT, UPDATE and DELETE commands to modify
data in a SQL Server table. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=6257f4a8-134a-4f18-9372-7c38ed4c7219" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,6257f4a8-134a-4f18-9372-7c38ed4c7219.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=75aef884-d213-4aa0-93e4-d045721d876e</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,75aef884-d213-4aa0-93e4-d045721d876e.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,75aef884-d213-4aa0-93e4-d045721d876e.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=75aef884-d213-4aa0-93e4-d045721d876e</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        <div style="BORDER-RIGHT: thin solid; BORDER-TOP: thin solid; MARGIN: 5px; BORDER-LEFT: thin solid; WIDTH: 80%; BORDER-BOTTOM: thin solid; BACKGROUND-COLOR: silver">
          <p>
NOTE: 
</p>
          <p>
For demos in this article, we will use three tables: Customer, SalesOrder and OrderLine.  
</p>
          <p>
The structure of the Customer table is:
</p>
          <table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border="1">
            <tbody>
              <tr>
                <td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left">
                  <font size="1">Name </font>
                </td>
                <td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left">
                  <font size="1">Data Type </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">CustID</font>
                </td>
                <td>
                  <font size="1">int</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">FirstName</font>
                </td>
                <td>
                  <font size="1">nvarchar(50)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">LastName</font>
                </td>
                <td>
                  <font size="1">nvarchar(50)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">StreetAddress</font>
                </td>
                <td>
                  <font size="1">nvarchar(255)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">City </font>
                </td>
                <td>
                  <font size="1">nvarchar(255) </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">State</font>
                </td>
                <td>
                  <font size="1">char(2)</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">ZipCode </font>
                </td>
                <td>
                  <font size="1">nvarchar(10)</font>
                </td>
              </tr>
            </tbody>
          </table>
          <p>
The Customer table contains the following data. 
</p>
          <table border="1">
            <tbody>
              <tr>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">CustID </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">FirstName </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">LastName </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">StreetAddress </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">City </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">State </font>
                </td>
                <td class="style1" style="COLOR: black; BACKGROUND-COLOR: white">
                  <font size="1">ZipCode </font>
                </td>
              </tr>
              <tr>
                <td class="style1">
                  <font size="1">1</font>
                </td>
                <td class="style1">
                  <font size="1">David</font>
                </td>
                <td class="style1">
                  <font size="1">Giard</font>
                </td>
                <td class="style1">
                  <font size="1">123 Oxford Ct</font>
                </td>
                <td class="style1">
                  <font size="1">Erlanger</font>
                </td>
                <td class="style1">
                  <font size="1">KY</font>
                </td>
                <td class="style1">
                  <font size="1">40111</font>
                </td>
              </tr>
              <tr>
                <td class="style1">
                  <font size="1">2</font>
                </td>
                <td class="style1">
                  <font size="1">Magic</font>
                </td>
                <td class="style1">
                  <font size="1">Johnson</font>
                </td>
                <td class="style1">
                  <font size="1">456 Hollywood Blvd</font>
                </td>
                <td class="style1">
                  <font size="1">Lansing</font>
                </td>
                <td class="style1">
                  <font size="1">MI</font>
                </td>
                <td class="style1">
                  <font size="1">45222</font>
                </td>
              </tr>
              <tr>
                <td class="style1">
                  <font size="1">3</font>
                </td>
                <td class="style1">
                  <font size="1">Bubba</font>
                </td>
                <td class="style1">
                  <font size="1">Smith</font>
                </td>
                <td class="style1">
                  <font size="1">789 Killbubbakill St</font>
                </td>
                <td class="style1">
                  <font size="1">Baltimore</font>
                </td>
                <td class="style1">
                  <font size="1">MD</font>
                </td>
                <td class="style1">
                  <font size="1">10111</font>
                </td>
              </tr>
            </tbody>
          </table>
          <br />
The structure of the SalesOrder table is<br /><table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border="1"><tbody><tr><td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"><font size="1">Name </font></td><td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"><font size="1">Data Type </font></td></tr><tr><td><font size="1">OrderID</font></td><td><font size="1">int</font></td></tr><tr><td><font size="1">CustID</font></td><td><font size="1">int</font></td></tr><tr><td><font size="1">OrderDate</font></td><td><font size="1">datetime</font></td></tr></tbody></table><p>
The SalesOrder table contains the following data. 
</p><table border="1"><tbody><tr><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">OrderID</font></td><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">CustID </font></td><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">OrderDate</font></td></tr><tr><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">2009-03-01</font></td></tr><tr><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">2009-03-02</font></td></tr><tr><td class="style1"><font size="1">3</font></td><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">2009-03-07</font></td></tr><tr><td class="style1"><font size="1">4</font></td><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">2009-03-14</font></td></tr><tr><td class="style1"><font size="1">5</font></td><td class="style1"><font size="1">3</font></td><td class="style1"><font size="1">2009-03-21</font></td></tr></tbody></table><br />
The structure of the OrderLine table is<br /><table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border="1"><tbody><tr><td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"><font size="1">Name </font></td><td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"><font size="1">Data Type </font></td></tr><tr><td><font size="1">OrderID</font></td><td><font size="1">int</font></td></tr><tr><td><font size="1">LineNumber</font></td><td><font size="1">int</font></td></tr><tr><td><font size="1">ProductName</font></td><td><font size="1">nvarchar(255)</font></td></tr><tr><td><font size="1">Quantity</font></td><td><font size="1">int</font></td></tr></tbody></table><br />
The OrderLine table contains the following data   
<br /><table border="1"><tbody><tr><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">OrderID</font></td><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">LineNumber</font></td><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">ProductName</font></td><td class="style1" style="COLOR: black; BACKGROUND-COLOR: white"><font size="1">Quantity</font></td></tr><tr><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">Widget</font></td><td class="style1"><font size="1">7</font></td></tr><tr><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">Super Widget</font></td><td class="style1"><font size="1">4</font></td></tr><tr><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">Widget</font></td><td class="style1"><font size="1">5</font></td></tr><tr><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">Super Widget</font></td><td class="style1"><font size="1">3</font></td></tr><tr><td class="style1"><font size="1">3</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">Widget</font></td><td class="style1"><font size="1">2</font></td></tr><tr><td class="style1"><font size="1">4</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">Super Widget</font></td><td class="style1"><font size="1">3</font></td></tr><tr><td class="style1"><font size="1">5</font></td><td class="style1"><font size="1">1</font></td><td class="style1"><font size="1">Widget</font></td><td class="style1"><font size="1">6</font></td></tr><tr><td class="style1"><font size="1">5</font></td><td class="style1"><font size="1">2</font></td><td class="style1"><font size="1">Super Widget</font></td><td class="style1"><font size="1">1</font></td></tr></tbody></table><br /></div>
        <p>
In a previous article, I explained how we can (and often should) split a table into
multiple tables in order to eliminate data redundancy - a process known as "normalization".
</p>
        <p>
In this article, I'll explain how to retrieve related data from multiple tables and
return them in a single result set.
</p>
        <p>
Recall from the Normalization article that - in order to relate to tables - we add
a key to each table.  The Primary key in the parent table is a column that is
unique for each row and, therefore, servers to uniquely identify a row.  The
child table contains a foreign key which is the same value as a Primary key in the
parent table, so it points to a given row in the parent.
</p>
        <p>
To retrieve data from multiple tables into a single result set, we do something called
a "JOIN".  In SQL, there are two ways to JOIN tables:
</p>
        <ul>
          <li>
Using the JOIN keyword 
</li>
          <li>
Adding the join condition on a WHERE clause</li>
        </ul>
        <h3>JOIN keyword
</h3>
        <p>
The syntax for joining tables with the JOIN keyword is
</p>
        <p>
The syntax for joining tables with the JOIN keyword is
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT
[List of Columns]<br />
    FROM [Table 1] 
<br />
    JOIN [Table 2]<br />
        ON [Join Condition]</span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"> </span>
          </span>For
example, to retrieve the Name, SalesOrder Date and SalesOrder Amount of each customer
in our sample tables, use the following query:
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>         FirstName,
        LastName,         OrderDate
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer
    <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> SalesOrder
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> Customer.CustID
= SalesOrder.CustID</span>
        </pre>
        <p>
Notice that we need to prefix the CustID column name with the table name in our filter
condition.  This is because the CustID column name is not unique.  We need
to tell SQL to which column we are referring.
</p>
        <p>
The results of this query are
</p>
        <table style="FONT-SIZE: x-small" border="1">
          <tbody>
            <tr style="FONT-SIZE: x-small">
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">FirstName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">LastName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">OrderDate</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-01</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-02</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-07</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">Magic</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Johnson</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-14</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">Bubba</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Smith</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-21</font>
              </td>
            </tr>
          </tbody>
        </table>
        <h3>WHERE clause
</h3>
        <p>
The syntax for joining two tables with the WHERE clause is
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT
[List of Columns]<br />
    FROM [Table 1], [Table 2] 
<br />
    WHERE [Join Condition] </span>
          </span>
        </p>
        <p>
The syntax to return the same result set as above is
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>
            <br />
        FirstName, 
<br />
        LastName, 
<br />
        OrderDate 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer,
SalesOrder 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Customer.CustID
= SalesOrder.CustID</span>
        </p>
        <p>
Recall that the WHERE clause is also used to filter your result set.  In fact,
you can use it for both filtering and joining.  The following two queries yield
the same results (showing only those records that match customer 1.
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>
            <br />
        FirstName, 
<br />
        LastName, 
<br />
        OrderDate 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer 
<br />
    <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> SalesOrder 
<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> Customer.CustID
= SalesOrder.CustID 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Customer.CustID
= 1</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>
            <br />
        FirstName, 
<br />
        LastName, 
<br />
        OrderDate 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer,
SalesOrder 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Customer.CustID
= SalesOrder.CustID 
<br />
        <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> Customer.CustID
= 1</span>
        </p>
        <p>
Here is the result set for either of the above two queries:
</p>
        <table style="FONT-SIZE: x-small" border="1">
          <tbody>
            <tr style="FONT-SIZE: x-small">
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">FirstName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">LastName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">OrderDate</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-01</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-02</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-07</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
You can use these same techniques to join more than two tables. Here is the syntax
to add the OrderLine table to our queries
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>
            <br />
        SalesOrder.OrderID, 
<br />
        FirstName, 
<br />
        LastName, 
<br />
        OrderDate,<br />
        ProductName,<br />
        Quantity<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer 
<br />
    <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> SalesOrder 
<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> Customer.CustID
= SalesOrder.CustID 
<br />
    <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> OrderLine 
<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> SalesOrder.OrderID
= OrderLine.OrderID</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span>
            <br />
        SalesOrder.OrderID, 
<br />
        FirstName, 
<br />
        LastName, 
<br />
        OrderDate,<br />
        ProductName,<br />
        Quantity<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Customer,
SalesOrder, OrderLine<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> Customer.CustID
= SalesOrder.CustID 
<br />
        <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> SalesOrder.OrderID
= OrderLine.OrderID</span>
        </p>
        <p>
Here is the result set of either of these 3-table queries
</p>
        <table style="FONT-SIZE: x-small" border="1">
          <tbody>
            <tr style="FONT-SIZE: x-small">
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">OrderID</font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">FirstName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">LastName </font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">OrderDate</font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">ProductName</font>
              </td>
              <td class="style1" style="COLOR: white; BACKGROUND-COLOR: gray">
                <font size="1">Quantity</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">1</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-01</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">7</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">1</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-01</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Super Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">4</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">2</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-02</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">5</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">2</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-02</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Super Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">3</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">3</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">David</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Giard</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-07</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">4</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Magic</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Johnson</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-14</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Super Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">3</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">5</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Bubba</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Smith</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-21</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">6</font>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <font color="#000000" size="1">5</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Bubba</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Smith</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">2009-03-21</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">Super Widget</font>
              </td>
              <td class="style1">
                <font color="#000000" size="1">1</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
I prefer to use the JOIN keyword syntax when joining tables together because it is
more clear what part of the query is a filter and what part of a query is a join.  
</p>
        <p>
In this article, we showed the ways to use SQL Server to join multiple tables into
a single result set.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=75aef884-d213-4aa0-93e4-d045721d876e" />
      </body>
      <title>SQL 101 - Part 5: Joins</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,75aef884-d213-4aa0-93e4-d045721d876e.aspx</guid>
      <link>http://www.davidgiard.com/2009/03/21/SQL101Part5Joins.aspx</link>
      <pubDate>Sat, 21 Mar 2009 22:31:36 GMT</pubDate>
      <description>&lt;img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;div style="BORDER-RIGHT: thin solid; BORDER-TOP: thin solid; MARGIN: 5px; BORDER-LEFT: thin solid; WIDTH: 80%; BORDER-BOTTOM: thin solid; BACKGROUND-COLOR: silver"&gt;
&lt;p&gt;
NOTE: 
&lt;/p&gt;
&lt;p&gt;
For demos in this article, we will use three tables: Customer, SalesOrder and OrderLine.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The structure of the Customer table is:
&lt;/p&gt;
&lt;table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Name &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Data Type &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;CustID&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;FirstName&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(50)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;LastName&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(50)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;StreetAddress&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(255)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(255) &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;State&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;char(2)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(10)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
The Customer table contains the following data. 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;123 Oxford Ct&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Erlanger&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;KY&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;40111&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;456 Hollywood Blvd&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;45222&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;789 Killbubbakill St&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Baltimore&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;MD&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;10111&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;
The structure of the SalesOrder table is&lt;br&gt;
&lt;table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Name &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Data Type &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;OrderID&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;CustID&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;OrderDate&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;datetime&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
The SalesOrder table contains the following data. 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;OrderID&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;OrderDate&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2009-03-01&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2009-03-02&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2009-03-07&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2009-03-14&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2009-03-21&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;
The structure of the OrderLine table is&lt;br&gt;
&lt;table style="BORDER-RIGHT: white thin solid; BORDER-TOP: white thin solid; BORDER-LEFT: white thin solid; WIDTH: 57%; COLOR: white; BORDER-BOTTOM: white thin solid; BACKGROUND-COLOR: gray; TEXT-ALIGN: left" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Name &lt;/font&gt;&lt;/td&gt;
&lt;td style="COLOR: black; BACKGROUND-COLOR: white; TEXT-ALIGN: left"&gt;
&lt;font size=1&gt;Data Type &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;OrderID&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;LineNumber&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;ProductName&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;nvarchar(255)&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Quantity&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;int&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;
The OrderLine table contains the following data&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;OrderID&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;LineNumber&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;ProductName&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: black; BACKGROUND-COLOR: white"&gt;
&lt;font size=1&gt;Quantity&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;7&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;6&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;p&gt;
In a previous article, I explained how we can (and often should) split a table into
multiple tables in order to eliminate data redundancy - a process known as "normalization".
&lt;/p&gt;
&lt;p&gt;
In this article, I'll explain how to retrieve related data from multiple tables and
return them in a single result set.
&lt;/p&gt;
&lt;p&gt;
Recall from the Normalization article that - in order to relate to tables - we add
a key to each table.&amp;nbsp; The Primary key in the parent table is a column that is
unique for each row and, therefore, servers to uniquely identify a row.&amp;nbsp; The
child table contains a foreign key which is the same value as a Primary key in the
parent table, so it points to a given row in the parent.
&lt;/p&gt;
&lt;p&gt;
To retrieve data from multiple tables into a single result set, we do something called
a "JOIN".&amp;nbsp; In SQL, there are two ways to JOIN tables:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Using the JOIN keyword 
&lt;li&gt;
Adding the join condition on a WHERE clause&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;JOIN keyword
&lt;/h3&gt;
&lt;p&gt;
The syntax for joining tables with the JOIN keyword is
&lt;/p&gt;
&lt;p&gt;
The syntax for joining tables with the JOIN keyword is
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT
[List of Columns]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM [Table 1] 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JOIN [Table 2]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON [Join Condition]&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;For
example, to retrieve the Name, SalesOrder Date and SalesOrder Amount of each customer
in our sample tables, use the following query:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; SalesOrder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; Customer.CustID
= SalesOrder.CustID&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Notice that we need to prefix the CustID column name with the table name in our filter
condition.&amp;nbsp; This is because the CustID column name is not unique.&amp;nbsp; We need
to tell SQL to which column we are referring.
&lt;/p&gt;
&lt;p&gt;
The results of this query are
&lt;/p&gt;
&lt;table style="FONT-SIZE: x-small" border=1&gt;
&lt;tbody&gt;
&lt;tr style="FONT-SIZE: x-small"&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;OrderDate&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-01&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-02&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-07&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-14&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-21&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;WHERE clause
&lt;/h3&gt;
&lt;p&gt;
The syntax for joining two tables with the WHERE clause is
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT
[List of Columns]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM [Table 1], [Table 2] 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE [Join Condition] &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
The syntax to return the same result set as above is
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer,
SalesOrder 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Customer.CustID
= SalesOrder.CustID&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Recall that the WHERE clause is also used to filter your result set.&amp;nbsp; In fact,
you can use it for both filtering and joining.&amp;nbsp; The following two queries yield
the same results (showing only those records that match customer 1.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; SalesOrder 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; Customer.CustID
= SalesOrder.CustID 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Customer.CustID
= 1&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer,
SalesOrder 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Customer.CustID
= SalesOrder.CustID 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; Customer.CustID
= 1&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Here is the result set for either of the above two queries:
&lt;/p&gt;
&lt;table style="FONT-SIZE: x-small" border=1&gt;
&lt;tbody&gt;
&lt;tr style="FONT-SIZE: x-small"&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;OrderDate&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-01&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-02&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-07&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
You can use these same techniques to join more than two tables. Here is the syntax
to add the OrderLine table to our queries
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SalesOrder.OrderID, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductName,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Quantity&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; SalesOrder 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; Customer.CustID
= SalesOrder.CustID 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; OrderLine 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; SalesOrder.OrderID
= OrderLine.OrderID&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SalesOrder.OrderID, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OrderDate,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductName,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Quantity&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Customer,
SalesOrder, OrderLine&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; Customer.CustID
= SalesOrder.CustID 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; SalesOrder.OrderID
= OrderLine.OrderID&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Here is the result set of either of these 3-table queries
&lt;/p&gt;
&lt;table style="FONT-SIZE: x-small" border=1&gt;
&lt;tbody&gt;
&lt;tr style="FONT-SIZE: x-small"&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;OrderID&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;OrderDate&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;ProductName&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1 style="COLOR: white; BACKGROUND-COLOR: gray"&gt;
&lt;font size=1&gt;Quantity&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-01&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;7&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-01&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-02&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-02&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-07&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-14&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-21&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;6&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;2009-03-21&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;Super Widget&lt;/font&gt;&lt;/td&gt;
&lt;td class=style1&gt;
&lt;font color=#000000 size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
I prefer to use the JOIN keyword syntax when joining tables together because it is
more clear what part of the query is a filter and what part of a query is a join.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In this article, we showed the ways to use SQL Server to join multiple tables into
a single result set.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=75aef884-d213-4aa0-93e4-d045721d876e" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,75aef884-d213-4aa0-93e4-d045721d876e.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=2c88dcbd-fcb2-41a0-8b77-e51c8941d429</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,2c88dcbd-fcb2-41a0-8b77-e51c8941d429.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,2c88dcbd-fcb2-41a0-8b77-e51c8941d429.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2c88dcbd-fcb2-41a0-8b77-e51c8941d429</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        <div style="BORDER-BOTTOM: thin solid; BORDER-LEFT: thin solid; BACKGROUND-COLOR: silver; MARGIN: 5px; WIDTH: 80%; BORDER-TOP: thin solid; BORDER-RIGHT: thin solid">
          <p>
NOTE: 
</p>
          <p>
For demos in this article, we will use a table named Customer that contains 7 columns: 
</p>
          <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
            <tbody>
              <tr>
                <td style="TEXT-ALIGN: left; BACKGROUND-COLOR: white; COLOR: black">
Name 
</td>
                <td style="TEXT-ALIGN: left; BACKGROUND-COLOR: white; COLOR: black">
Data Type 
</td>
              </tr>
              <tr>
                <td>
FirstName</td>
                <td>
nvarchar(50)</td>
              </tr>
              <tr>
                <td>
LastName</td>
                <td>
nvarchar(50)</td>
              </tr>
              <tr>
                <td>
StreetAddress</td>
                <td>
nvarchar(255)</td>
              </tr>
              <tr>
                <td>
City</td>
                <td>
nvarchar(255)</td>
              </tr>
              <tr>
                <td>
State</td>
                <td>
char(2)</td>
              </tr>
              <tr>
                <td>
ZipCode</td>
                <td>
nvarchar(10)</td>
              </tr>
              <tr>
                <td>
TotalSales</td>
                <td>
money</td>
              </tr>
            </tbody>
          </table>
          <p>
Afer adding a few rows to the table, the data looks like this. 
</p>
          <table border="1">
            <tbody>
              <tr>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">CustID </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">FirstName </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">LastName </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">StreetAddress </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">City </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">State </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">ZipCode </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="2">TotalSales </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">1</font>
                </td>
                <td>
                  <font size="2">David</font>
                </td>
                <td>
                  <font size="2">Giard</font>
                </td>
                <td>
                  <font size="2">123 Oxford Ct</font>
                </td>
                <td>
                  <font size="2">Erlanger</font>
                </td>
                <td>
                  <font size="2">KY</font>
                </td>
                <td>
                  <font size="2">40111</font>
                </td>
                <td>
                  <font size="2">500.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">2</font>
                </td>
                <td>
                  <font size="2">Magic</font>
                </td>
                <td>
                  <font size="2">Johnson</font>
                </td>
                <td>
                  <font size="2">456 Hollywood Blvd</font>
                </td>
                <td>
                  <font size="2">Lansing</font>
                </td>
                <td>
                  <font size="2">MI</font>
                </td>
                <td>
                  <font size="2">45222</font>
                </td>
                <td>
                  <font size="2">1500.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">3</font>
                </td>
                <td>
                  <font size="2">Bubba</font>
                </td>
                <td>
                  <font size="2">Smith</font>
                </td>
                <td>
                  <font size="2">789 Killbubbakill St</font>
                </td>
                <td>
                  <font size="2">Baltimore</font>
                </td>
                <td>
                  <font size="2">MD</font>
                </td>
                <td>
                  <font size="2">10111</font>
                </td>
                <td>
                  <font size="2">1000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">4</font>
                </td>
                <td>
                  <font size="2">Ron</font>
                </td>
                <td>
                  <font size="2">Mason</font>
                </td>
                <td>
                  <font size="2">501 E Grand River Ave</font>
                </td>
                <td>
                  <font size="2">Lansing</font>
                </td>
                <td>
                  <font size="2">MI</font>
                </td>
                <td>
                  <font size="2">45333</font>
                </td>
                <td>
                  <font size="2">2000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">5</font>
                </td>
                <td>
                  <font size="2">Steve</font>
                </td>
                <td>
                  <font size="2">Smith</font>
                </td>
                <td>
                  <font size="2">900 Belle St</font>
                </td>
                <td>
                  <font size="2">Detroit</font>
                </td>
                <td>
                  <font size="2">MI</font>
                </td>
                <td>
                  <font size="2">48888</font>
                </td>
                <td>
                  <font size="2">5000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">6</font>
                </td>
                <td>
                  <font size="2">Ryan</font>
                </td>
                <td>
                  <font size="2">Miller</font>
                </td>
                <td>
                  <font size="2">1 Shutout Ct</font>
                </td>
                <td>
                  <font size="2">Buffalo</font>
                </td>
                <td>
                  <font size="2">NY</font>
                </td>
                <td>
                  <font size="2">32323</font>
                </td>
                <td>
                  <font size="2">250.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="2">7</font>
                </td>
                <td>
                  <font size="2">Brad</font>
                </td>
                <td>
                  <font size="2">Van Pelt</font>
                </td>
                <td>
                  <font size="2">99 Linebaker Ln</font>
                </td>
                <td>
                  <font size="2">Owosso</font>
                </td>
                <td>
                  <font size="2">MI</font>
                </td>
                <td>
                  <font size="2">47777</font>
                </td>
                <td>
                  <font size="2">4000.00</font>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <p>
In the last article in this series, I expleined the basic functionality of the SELECT
statement. I showed how to select columns from a table and sort or filter the results. 
</p>
        <p>
In this article, I'll show some more things you can do with the SELECT statemnts. 
</p>
        <p>
Sometimes we want our results to aggregate data. When aggregating data, we use functions
that consolidate multiple rows and return the result of this aggregate function applied
to many rows. The most common aggregate functions I use that SQL Server supports are: 
</p>
        <table border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font size="2">Function </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font size="2">Descripiton</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="2">MAX </font>
              </td>
              <td>
                <font size="2">The maximum value of a column across all included rows </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="2">MIN </font>
              </td>
              <td>
                <font size="2">The minimum value of a column across all included rows </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="2">SUM </font>
              </td>
              <td>
                <font size="2">The sum of all values in a column across all included rows </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="2">AVG </font>
              </td>
              <td>
                <font size="2">The arithmetic average of all values in a column across all included
rows </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="2">COUNT </font>
              </td>
              <td>
                <font size="2">The number of included rows</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
The MIN, MAX, SUM, and AVG functions accept a parameter - the name of the column on
which to calculate these values. The column must hold a numeric data type, such as
an INT, FLOAT or MONEY. 
</p>
        <p>
You may pass a column name as a parameter to the COUNT function but it doesn't matter
which column because - in SQL Server - every column appears exactly once in each row
and the COUNT function is used to count rows. By convention, we pass "*" as the parameter
to the COUNT aggregate function to represent all rows. 
</p>
        <p>
A few examples will help clarify this. Since our table contains only one numeric column
- <i>TotalSales</i> - we will use this in most of our aggregate functions. 
</p>
        <p>
The following query returns the maximum value of the <i>TotalSales</i> column. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">MAX</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> MaxSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <p>
Here are the results - one row with one column containing the highest numerical value
in the <i>TotalSales</i> column. 
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
MaxSales</td>
            </tr>
            <tr>
              <td align="middle">
5000.00</td>
            </tr>
          </tbody>
        </table>
        <p>
Similarly, the following query returns the sum of all values in the <i>TotalSales</i> column. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <p>
This returns 14,750 which is the sum of 1000 + 1500 + 1000 + 2000 + 5000 + 250 + 4000 
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
SumSales</td>
            </tr>
            <tr>
              <td align="middle">
14750.00</td>
            </tr>
          </tbody>
        </table>
        <p>
We can filter before applying an aggregate function. If we only want to sum of <i>TotalSales</i> for
customers in michigan, we simply add a WHERE clause to our query. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHERE</span> State
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'MI'</span></span>
        </pre>
        <p>
This returns 12,500, which is 1500 + 2000 + 5000 + 4000, or the sum of the <i>TotalSales</i> column
for only those customers in Michigan. 
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
SumSales</td>
            </tr>
            <tr>
              <td align="middle">
12500.00</td>
            </tr>
          </tbody>
        </table>
        <p>
As mentioned before, we do not need to specify a particular column for the COUNT function. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">COUNT</span> (*) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> NumCusts
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <p>
returns the a row and column containing number 7, which is how many rows are in our
table. 
</p>
        <p>
So far, each query we have written has returned only one row. Often, however, we want
to calculate an aggregation for each distinct value in a column or columns. We can
do this by adding a GROUP BY clause to the query. For example, we may want to see
the SUM of <i>TotalSales</i> for each state. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         State,
        <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">GROUP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> State </span>
        </pre>
        <p>
The above query returns a row for each distinct value in the State column and calculates
the sum of <i>TotalSales</i> of all rows corresponding to that state.
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
State</td>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
SumSales</td>
            </tr>
            <tr>
              <td align="middle">
 KY</td>
              <td align="middle">
500.00</td>
            </tr>
            <tr>
              <td align="middle">
MD</td>
              <td align="middle">
1000.00</td>
            </tr>
            <tr>
              <td align="middle">
MI</td>
              <td align="middle">
12500.00</td>
            </tr>
            <tr>
              <td align="middle">
NY</td>
              <td align="middle">
500.00</td>
            </tr>
          </tbody>
        </table>
        <p>
It's important to note that, when using the GROUP BY clause, you cannot return a column
that is not part of the grouping. So 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         State,
        City,         <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">GROUP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> State </span>
        </pre>
        <p>
results in an error because we are trying to return the city column, but we are not
grouping on that column. Because a given state can have multiple cities, SQL does
not know which one to display for the row returned. 
</p>
        <p>
You can group on multiple columns as in the following query 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         State,
        City,         <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">GROUP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> State,
City </span>
        </pre>
        <p>
In this case, we get a row with a sum for each combination of state and city. 
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
State</td>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
City</td>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
SumSales</td>
            </tr>
            <tr>
              <td align="middle">
 KY</td>
              <td align="middle">
Erlanger</td>
              <td align="middle">
500.00</td>
            </tr>
            <tr>
              <td align="middle">
MD</td>
              <td align="middle">
Baltimore</td>
              <td align="middle">
1000.00</td>
            </tr>
            <tr>
              <td align="middle">
MI</td>
              <td align="middle">
Lansing</td>
              <td align="middle">
1500.00</td>
            </tr>
            <tr>
              <td align="middle">
MI</td>
              <td align="middle">
Okemos</td>
              <td align="middle">
2000.00</td>
            </tr>
            <tr>
              <td align="middle">
MI</td>
              <td align="middle">
Owosso</td>
              <td align="middle">
4000.00</td>
            </tr>
            <tr>
              <td align="middle">
NY</td>
              <td align="middle">
Buffalo</td>
              <td align="middle">
250.00</td>
            </tr>
          </tbody>
        </table>
        <p>
By using the GROUP BY clause on a large table, we may end up with so many rows that
it becomes difficult to find relevant data. Sometimes, we are only interested in those
times when the aggregate value exceeds some threshhold. In these cases, it would be
nice to only show aggregate rows that exceed that threshhold. This sounds like a good
place to use a filter. Unfortunately, we cannot use the WHERE clause to accomplish
this task because the WHERE clause filters data before the aggregation. We have to
wait until after calculating the aggregate values becuase it is the aggregate values
on which we want to filter. The HAVING clause is used to filter on aggregate values. 
</p>
        <p>
We can run our query to get the <i>TotalSales</i> sum for each state, but show only
those states that have total sales of more than 2000, using the following query 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         State,
        <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> SumSales
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">GROUP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> State
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">HAVING</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUM</span> (TotalSales)
&gt;= 1000 </span>
        </pre>
        <p>
In this case, we don't see the row for Kentucky and New York because they had total
sales summing less than $1000 
</p>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border="1">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
State</td>
              <td style="BACKGROUND-COLOR: white; COLOR: black" align="middle">
SumSales</td>
            </tr>
            <tr>
              <td align="middle">
MD</td>
              <td align="middle">
1000.00</td>
            </tr>
            <tr>
              <td align="middle">
MI</td>
              <td align="middle">
112500.00</td>
            </tr>
          </tbody>
        </table>
        <p>
In this article, we showed how to use T-SQL's grouping and aggregate functions to
return summary data from a database. 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=2c88dcbd-fcb2-41a0-8b77-e51c8941d429" />
      </body>
      <title>SQL 101 - Part 4: Aggregating data</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,2c88dcbd-fcb2-41a0-8b77-e51c8941d429.aspx</guid>
      <link>http://www.davidgiard.com/2009/03/12/SQL101Part4AggregatingData.aspx</link>
      <pubDate>Thu, 12 Mar 2009 14:17:07 GMT</pubDate>
      <description>&lt;img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;div style="BORDER-BOTTOM: thin solid; BORDER-LEFT: thin solid; BACKGROUND-COLOR: silver; MARGIN: 5px; WIDTH: 80%; BORDER-TOP: thin solid; BORDER-RIGHT: thin solid"&gt;
&lt;p&gt;
NOTE: 
&lt;/p&gt;
&lt;p&gt;
For demos in this article, we will use a table named Customer that contains 7 columns: 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="TEXT-ALIGN: left; BACKGROUND-COLOR: white; COLOR: black"&gt;
Name 
&lt;/td&gt;
&lt;td style="TEXT-ALIGN: left; BACKGROUND-COLOR: white; COLOR: black"&gt;
Data Type 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
nvarchar(50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
LastName&lt;/td&gt;
&lt;td&gt;
nvarchar(50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
nvarchar(255)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
City&lt;/td&gt;
&lt;td&gt;
nvarchar(255)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
State&lt;/td&gt;
&lt;td&gt;
char(2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
ZipCode&lt;/td&gt;
&lt;td&gt;
nvarchar(10)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
TotalSales&lt;/td&gt;
&lt;td&gt;
money&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Afer adding a few rows to the table, the data looks like this. 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;TotalSales &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;123 Oxford Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Erlanger&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;KY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;40111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;500.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;456 Hollywood Blvd&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;45222&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;1500.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;789 Killbubbakill St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Baltimore&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;MD&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;10111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;1000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;501 E Grand River Ave&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;45333&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;2000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;6&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Ryan&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Miller&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;1 Shutout Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Buffalo&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;NY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;32323&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;250.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;7&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Brad&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Van Pelt&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;99 Linebaker Ln&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;Owosso&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;47777&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;4000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;
In the last article in this series, I expleined the basic functionality of the SELECT
statement. I showed how to select columns from a table and sort or filter the results. 
&lt;/p&gt;
&lt;p&gt;
In this article, I'll show some more things you can do with the SELECT statemnts. 
&lt;/p&gt;
&lt;p&gt;
Sometimes we want our results to aggregate data. When aggregating data, we use functions
that consolidate multiple rows and return the result of this aggregate function applied
to many rows. The most common aggregate functions I use that SQL Server supports are: 
&lt;/p&gt;
&lt;table border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;Function &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=2&gt;Descripiton&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;MAX &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;The maximum value of a column across all included rows &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;MIN &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;The minimum value of a column across all included rows &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;SUM &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;The sum of all values in a column across all included rows &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;AVG &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;The arithmetic average of all values in a column across all included
rows &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=2&gt;COUNT &lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=2&gt;The number of included rows&lt;/font&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
The MIN, MAX, SUM, and AVG functions accept a parameter - the name of the column on
which to calculate these values. The column must hold a numeric data type, such as
an INT, FLOAT or MONEY. 
&lt;/p&gt;
&lt;p&gt;
You may pass a column name as a parameter to the COUNT function but it doesn't matter
which column because - in SQL Server - every column appears exactly once in each row
and the COUNT function is used to count rows. By convention, we pass "*" as the parameter
to the COUNT aggregate function to represent all rows. 
&lt;/p&gt;
&lt;p&gt;
A few examples will help clarify this. Since our table contains only one numeric column
- &lt;i&gt;TotalSales&lt;/i&gt; - we will use this in most of our aggregate functions. 
&lt;/p&gt;
&lt;p&gt;
The following query returns the maximum value of the &lt;i&gt;TotalSales&lt;/i&gt; column. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;MAX&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; MaxSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Here are the results - one row with one column containing the highest numerical value
in the &lt;i&gt;TotalSales&lt;/i&gt; column. 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
MaxSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
5000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Similarly, the following query returns the sum of all values in the &lt;i&gt;TotalSales&lt;/i&gt; column. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
This returns 14,750 which is the sum of 1000 + 1500 + 1000 + 2000 + 5000 + 250 + 4000 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
SumSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
14750.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
We can filter before applying an aggregate function. If we only want to sum of &lt;i&gt;TotalSales&lt;/i&gt; for
customers in michigan, we simply add a WHERE clause to our query. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHERE&lt;/span&gt; State
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'MI'&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
This returns 12,500, which is 1500 + 2000 + 5000 + 4000, or the sum of the &lt;i&gt;TotalSales&lt;/i&gt; column
for only those customers in Michigan. 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
SumSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
12500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
As mentioned before, we do not need to specify a particular column for the COUNT function. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;COUNT&lt;/span&gt; (*) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; NumCusts
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
returns the a row and column containing number 7, which is how many rows are in our
table. 
&lt;/p&gt;
&lt;p&gt;
So far, each query we have written has returned only one row. Often, however, we want
to calculate an aggregation for each distinct value in a column or columns. We can
do this by adding a GROUP BY clause to the query. For example, we may want to see
the SUM of &lt;i&gt;TotalSales&lt;/i&gt; for each state. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;GROUP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; State &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The above query returns a row for each distinct value in the State column and calculates
the sum of &lt;i&gt;TotalSales&lt;/i&gt; of all rows corresponding to that state.
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
State&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
SumSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
&amp;nbsp;KY&lt;/td&gt;
&lt;td align=middle&gt;
500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MD&lt;/td&gt;
&lt;td align=middle&gt;
1000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MI&lt;/td&gt;
&lt;td align=middle&gt;
12500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
NY&lt;/td&gt;
&lt;td align=middle&gt;
500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
It's important to note that, when using the GROUP BY clause, you cannot return a column
that is not part of the grouping. So 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;City, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;GROUP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; State &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
results in an error because we are trying to return the city column, but we are not
grouping on that column. Because a given state can have multiple cities, SQL does
not know which one to display for the row returned. 
&lt;/p&gt;
&lt;p&gt;
You can group on multiple columns as in the following query 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;City, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;GROUP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; State,
City &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
In this case, we get a row with a sum for each combination of state and city. 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
State&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
City&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
SumSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
&amp;nbsp;KY&lt;/td&gt;
&lt;td align=middle&gt;
Erlanger&lt;/td&gt;
&lt;td align=middle&gt;
500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MD&lt;/td&gt;
&lt;td align=middle&gt;
Baltimore&lt;/td&gt;
&lt;td align=middle&gt;
1000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MI&lt;/td&gt;
&lt;td align=middle&gt;
Lansing&lt;/td&gt;
&lt;td align=middle&gt;
1500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MI&lt;/td&gt;
&lt;td align=middle&gt;
Okemos&lt;/td&gt;
&lt;td align=middle&gt;
2000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MI&lt;/td&gt;
&lt;td align=middle&gt;
Owosso&lt;/td&gt;
&lt;td align=middle&gt;
4000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
NY&lt;/td&gt;
&lt;td align=middle&gt;
Buffalo&lt;/td&gt;
&lt;td align=middle&gt;
250.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
By using the GROUP BY clause on a large table, we may end up with so many rows that
it becomes difficult to find relevant data. Sometimes, we are only interested in those
times when the aggregate value exceeds some threshhold. In these cases, it would be
nice to only show aggregate rows that exceed that threshhold. This sounds like a good
place to use a filter. Unfortunately, we cannot use the WHERE clause to accomplish
this task because the WHERE clause filters data before the aggregation. We have to
wait until after calculating the aggregate values becuase it is the aggregate values
on which we want to filter. The HAVING clause is used to filter on aggregate values. 
&lt;/p&gt;
&lt;p&gt;
We can run our query to get the &lt;i&gt;TotalSales&lt;/i&gt; sum for each state, but show only
those states that have total sales of more than 2000, using the following query 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;State,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; SumSales
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;GROUP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; State
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;HAVING&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUM&lt;/span&gt; (TotalSales)
&amp;gt;= 1000 &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
In this case, we don't see the row for Kentucky and New York because they had total
sales summing less than $1000 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 150px; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid" border=1&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
State&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black" align=middle&gt;
SumSales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MD&lt;/td&gt;
&lt;td align=middle&gt;
1000.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=middle&gt;
MI&lt;/td&gt;
&lt;td align=middle&gt;
112500.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
In this article, we showed how to use T-SQL's grouping and aggregate functions to
return summary data from a database. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=2c88dcbd-fcb2-41a0-8b77-e51c8941d429" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,2c88dcbd-fcb2-41a0-8b77-e51c8941d429.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=54a5b741-5a68-4d55-bc41-1fab2f33490a</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,54a5b741-5a68-4d55-bc41-1fab2f33490a.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,54a5b741-5a68-4d55-bc41-1fab2f33490a.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=54a5b741-5a68-4d55-bc41-1fab2f33490a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Saturday April 4 at the Robert C. Pew Grand Rapids Campus of Grand Valley State Universityin
Grand Rapids, Shane Jordan and I will be delivering a session on the basics of SQL
Server.  This will cover many of the same topics as the <em>Back To Basics: SQL
101 </em>series I have writton on this blog.
</p>
        <p>
The session is part of the West Michigan .Net University event.  You can get
more informaiton and register at <a href="http://www.dayofdotnet.org/WestMichiganDotNetU/">http://www.dayofdotnet.org/WestMichiganDotNetU/</a></p>
        <p>
          <img alt="West Michigan .Net University" src="http://www.dayofdotnet.org/WestMichiganDotNetU/images/Site-Badge-I.gif" />
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=54a5b741-5a68-4d55-bc41-1fab2f33490a" />
      </body>
      <title>'SQL 101' at West Michigan .Net University</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,54a5b741-5a68-4d55-bc41-1fab2f33490a.aspx</guid>
      <link>http://www.davidgiard.com/2009/03/11/SQL101AtWestMichiganNetUniversity.aspx</link>
      <pubDate>Wed, 11 Mar 2009 14:59:10 GMT</pubDate>
      <description>&lt;p&gt;
Saturday April 4 at the Robert C. Pew Grand Rapids Campus of Grand Valley State Universityin
Grand Rapids, Shane Jordan and I will be delivering a session on the basics of SQL
Server.&amp;nbsp; This will cover many of the same topics as the &lt;em&gt;Back To Basics: SQL
101&amp;nbsp;&lt;/em&gt;series I have writton on this blog.
&lt;/p&gt;
&lt;p&gt;
The session is part of the West Michigan .Net University event.&amp;nbsp; You can get
more informaiton and register at &lt;a href="http://www.dayofdotnet.org/WestMichiganDotNetU/"&gt;http://www.dayofdotnet.org/WestMichiganDotNetU/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="West Michigan .Net University" src="http://www.dayofdotnet.org/WestMichiganDotNetU/images/Site-Badge-I.gif"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=54a5b741-5a68-4d55-bc41-1fab2f33490a" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,54a5b741-5a68-4d55-bc41-1fab2f33490a.aspx</comments>
      <category>Back To Basics</category>
      <category>Public Speaking</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=e319538e-1502-490c-870c-1a0bfc912bb7</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,e319538e-1502-490c-870c-1a0bfc912bb7.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,e319538e-1502-490c-870c-1a0bfc912bb7.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e319538e-1502-490c-870c-1a0bfc912bb7</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        <div style="BORDER-BOTTOM: thin solid; BORDER-LEFT: thin solid; BACKGROUND-COLOR: silver; MARGIN: 5px; WIDTH: 80%; BORDER-TOP: thin solid; BORDER-RIGHT: thin solid">
          <p>
NOTE: 
</p>
          <p>
For demos in this article, we will use a table named Customer that contains the
followong columns: 
</p>
          <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid">
            <tbody>
              <tr>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
Name</td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
Data Type</td>
              </tr>
              <tr>
                <td>
FirstName</td>
                <td>
nvarchar(50)</td>
              </tr>
              <tr>
                <td>
LastName</td>
                <td>
nvarchar(50)</td>
              </tr>
              <tr>
                <td>
StreetAddress</td>
                <td>
nvarchar(255)</td>
              </tr>
              <tr>
                <td>
 City</td>
                <td>
nvarchar(255)</td>
              </tr>
              <tr>
                <td>
State</td>
                <td>
char(2)</td>
              </tr>
              <tr>
                <td>
 ZipCode</td>
                <td>
nvarchar(10)</td>
              </tr>
              <tr>
                <td>
TotalSales</td>
                <td>
money</td>
              </tr>
            </tbody>
          </table>
          <p>
Afer adding a few rows to the table, the data looks like this. 
</p>
          <table>
            <tbody>
              <tr>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">CustID </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">FirstName </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">LastName </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">StreetAddress </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">City </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">State </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">ZipCode </font>
                </td>
                <td style="BACKGROUND-COLOR: white; COLOR: black">
                  <font size="1">TotalSales </font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">1</font>
                </td>
                <td>
                  <font size="1">David</font>
                </td>
                <td>
                  <font size="1">Giard</font>
                </td>
                <td>
                  <font size="1">123 Oxford Ct</font>
                </td>
                <td>
                  <font size="1">Erlanger</font>
                </td>
                <td>
                  <font size="1">KY</font>
                </td>
                <td>
                  <font size="1">40111</font>
                </td>
                <td>
                  <font size="1">1000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">2</font>
                </td>
                <td>
                  <font size="1">Magic</font>
                </td>
                <td>
                  <font size="1">Johnson</font>
                </td>
                <td>
                  <font size="1">456 Hollywood Blvd</font>
                </td>
                <td>
                  <font size="1">Lansing</font>
                </td>
                <td>
                  <font size="1">MI</font>
                </td>
                <td>
                  <font size="1">45222</font>
                </td>
                <td>
                  <font size="1">1500.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">3</font>
                </td>
                <td>
                  <font size="1">Bubba</font>
                </td>
                <td>
                  <font size="1">Smith</font>
                </td>
                <td>
                  <font size="1">789 Killbubbakill St</font>
                </td>
                <td>
                  <font size="1">Baltimore</font>
                </td>
                <td>
                  <font size="1">MD</font>
                </td>
                <td>
                  <font size="1">10111</font>
                </td>
                <td>
                  <font size="1">1000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">4</font>
                </td>
                <td>
                  <font size="1">Ron</font>
                </td>
                <td>
                  <font size="1">Mason</font>
                </td>
                <td>
                  <font size="1">501 E Grand River Ave</font>
                </td>
                <td>
                  <font size="1">Okemos</font>
                </td>
                <td>
                  <font size="1">MI</font>
                </td>
                <td>
                  <font size="1">45333</font>
                </td>
                <td>
                  <font size="1">2000.00</font>
                </td>
              </tr>
              <tr>
                <td>
                  <font size="1">5</font>
                </td>
                <td>
                  <font size="1">Steve</font>
                </td>
                <td>
                  <font size="1">Smith</font>
                </td>
                <td>
                  <font size="1">900 Belle St</font>
                </td>
                <td>
                  <font size="1">Detroit</font>
                </td>
                <td>
                  <font size="1">MI</font>
                </td>
                <td>
                  <font size="1">48888</font>
                </td>
                <td>
                  <font size="1">5000.00</font>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <p>
Retrieving data is one of the most common tasks performed on a relational database. 
</p>
        <p>
Fortunately, SQL Server includes a language that allows users (and programs) to retrieve
the data they want. This language is called Structured Query Language. It is usually
abbreviated "SQL" and often pronounced "SEE-kwuhl". 
</p>
        <p>
Getting data from a database is known as querying the database. The code to retrieve
that data is a query. When this code is written in SQL (as most of my queries are),
it is known as a SQL query. 
</p>
        <p>
The basic syntax for a SQL query that retrieves data from a single table is 
</p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT
[List of Columns]<br />
    FROM [Table Name] 
<br />
    WHERE [Filter Condition] 
<br />
    ORDER BY [Sort column or columns] </span>
          </span>
        </p>
        <p>
In SQL, line breaks and extra spaces are not important. The language parser is smart
enough to figure out when a statement or command ends, so I usually try to format
my SQL statements to make them easy to read. 
</p>
        <p>
Only the <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT </span></span>and
FROM parts of the query are required, so let's start with those. 
</p>
        <p>
EvenEven though the "SELECT" keyword typically comes first in this type of query,
I'll start by explaining the "FROM" keyword. When getting data from only one table,
follow the keyword FROM with the name of that table. For example, the clause 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <p>
indicates that we are getting data from a table named Customer. We'll talk later about
how to get data from multiple tables in the same query. 
</p>
        <p>
It is possible to provide an alias for a table by following the table name with a
space, and the alias. For example 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
cust</span>
        </pre>
        <p>
The above SQL clause says that we will get data from the Customer table, but that
we will use the string “cust” to refer to this table elsewhere in our query. 
</p>
        <p>
This is useful in the following situations 
</p>
        <ul>
          <li>
You want to provide a shorter name for the table in order to avoid retyping a long
name elsewhere in the query 
</li>
          <li>
You want to avoid ambiguity when listing the same table name twice in the FROM clause. 
</li>
        </ul>
        <p>
SELECT is the first keyword of this type of query and tells SQL Server that we want
to retrieve data from the database. The word "SELECT" is followed by a list of columns
that the query will return. If the column list contains duplicate column names (as
when you are getting data from two different tables and they each have a column with
the same name), you should precede the column name with the table name or alias. 
</p>
        <p>
You can also use the special character "*" in place of (or in addition to) the list
of column names in order to return all columns in the tables. 
</p>
        <p>
The following query returns all columns and rows in the Customer table. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span> *
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">CustID </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">FirstName </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">LastName </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">StreetAddress </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">City </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">State </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font color="#000000" size="1">ZipCode </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font size="1">
                  <font color="#000000">TotalSales</font>
                </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">1</font>
              </td>
              <td>
                <font size="1">David</font>
              </td>
              <td>
                <font size="1">Giard</font>
              </td>
              <td>
                <font size="1">123 Oxford Ct</font>
              </td>
              <td>
                <font size="1">Erlanger</font>
              </td>
              <td>
                <font size="1">KY</font>
              </td>
              <td>
                <font size="1">40111</font>
              </td>
              <td>
                <font size="1">1000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">2</font>
              </td>
              <td>
                <font size="1">Magic</font>
              </td>
              <td>
                <font size="1">Johnson</font>
              </td>
              <td>
                <font size="1">456 Hollywood Blvd</font>
              </td>
              <td>
                <font size="1">Lansing</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">45222</font>
              </td>
              <td>
                <font size="1">1500.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">3</font>
              </td>
              <td>
                <font size="1">Bubba</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
              <td>
                <font size="1">789 Killbubbakill St</font>
              </td>
              <td>
                <font size="1">Baltimore</font>
              </td>
              <td>
                <font size="1">MD</font>
              </td>
              <td>
                <font size="1">10111</font>
              </td>
              <td>
                <font size="1">1000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">4</font>
              </td>
              <td>
                <font size="1">Ron</font>
              </td>
              <td>
                <font size="1">Mason</font>
              </td>
              <td>
                <font size="1">501 E Grand River Ave</font>
              </td>
              <td>
                <font size="1">Okemos</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">45333</font>
              </td>
              <td>
                <font size="1">2000.00</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">5</font>
              </td>
              <td>
                <font size="1">Steve</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
              <td>
                <font size="1">900 Belle St</font>
              </td>
              <td>
                <font size="1">Detroit</font>
              </td>
              <td>
                <font size="1">MI</font>
              </td>
              <td>
                <font size="1">48888</font>
              </td>
              <td>
                <font size="1">5000.00</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
We can return onWe can return only the FirstName and LastName columns from the Customer
table with the following table 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         FirstName,
        LastName     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer </span>
        </pre>
        <table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid">
          <tbody>
            <tr>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font size="1">FirstName </font>
              </td>
              <td style="BACKGROUND-COLOR: white; COLOR: black">
                <font size="1">LastName </font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">David</font>
              </td>
              <td>
                <font size="1">Giard</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">Magic</font>
              </td>
              <td>
                <font size="1">Johnson</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">Bubba</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">Ron</font>
              </td>
              <td>
                <font size="1">Mason</font>
              </td>
            </tr>
            <tr>
              <td>
                <font size="1">Steve</font>
              </td>
              <td>
                <font size="1">Smith</font>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
In the queries above, it is possible to qualify the column names, explicitly indicating
that they are from the Customer table. Of course, in this case it is unnecessary because
the column names are unique within the Customer table. The following examples qualify
the column names and returns the same data. 
</p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <br />
        Customer.FirstName, 
<br />
        Customer.LastName 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer</span>
        </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <br />
        cu.FirstName, 
<br />
        cu.LastName 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer
cu</span>
        </p>
        <p>
By default, each column returned by the query retains the name of the corresponding
column in the source table. you want to change the name of a If you want to change
the name of a column in the query, alias that column by appending the keyword " AS
" followed by the alias you want. For example 
</p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>
            <br />
        FirstName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> FirstNm, 
<br />
        LastName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">AS</span> LastNm 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer</span>
        </p>
This will return the following output 
<table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"><tbody><tr><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">FirstNm </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">LastNm </font></td></tr><tr><td><font size="1">David</font></td><td><font size="1">Giard</font></td></tr><tr><td><font size="1">Magic</font></td><td><font size="1">Johnson</font></td></tr><tr><td><font size="1">Bubba</font></td><td><font size="1">Smith</font></td></tr><tr><td><font size="1">Ron</font></td><td><font size="1">Mason</font></td></tr><tr><td><font size="1">Steve</font></td><td><font size="1">Smith</font></td></tr></tbody></table><p>
If wIf we want to sort the output we can add the ORDER BY clause to our query. The
syntax for this clause is 
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ORDER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span></span>[List
of Columns on which to sort] 
</p><p>
For example, we can sort our output on Last Name by changing our query to 
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span><br />
        FirstName, 
<br />
        LastName 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ORDER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> LastName </span></p><table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"><tbody><tr><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">FirstName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">LastName </font></td></tr><tr><td><font size="1">David</font></td><td><font size="1">Giard</font></td></tr><tr><td><font size="1">Magic</font></td><td><font size="1">Johnson</font></td></tr><tr><td><font size="1">Steve</font></td><td><font size="1">Smith</font></td></tr><tr><td><font size="1">Bubba</font></td><td><font size="1">Smith</font></td></tr><tr><td><font size="1">Ron</font></td><td><font size="1">Mason</font></td></tr></tbody></table><p>
We can add more columns to the list of sort columns if we separate each with a comma.
The second column is only appropriate in our sort if two rows have identical values
for the first column. 
</p><p>
For example 
</p><p>
SELECT FirstNameFor example 
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span><br />
        FirstName, 
<br />
        LastName 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> Customer 
<br />
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ORDER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span> LastName,
FirstName</span></p><table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"><tbody><tr><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">FirstName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">LastName </font></td></tr><tr><td><font size="1">David</font></td><td><font size="1">Giard</font></td></tr><tr><td><font size="1">Magic</font></td><td><font size="1">Johnson</font></td></tr><tr><td><font size="1">Bubba</font></td><td><font size="1">Smith</font></td></tr><tr><td><font size="1">Steve</font></td><td><font size="1">Smith</font></td></tr><tr><td><font size="1">Ron</font></td><td><font size="1">Mason</font></td></tr></tbody></table><p>
The above result set contains 2 rows with the last name "Smith".  These two rows
were sorted in order of their FirstName column.
</p><p>
In many cases, we may not want to return eIn many cases, we may not want to return
every row in a table. We can use the WHERE clause to filter data. The syntax of the
WHERE clause is 
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">   WHERE</span></span>[Filter
Condition]
</p><p>
The Filter condition is a Boolean expression, meaning it evaluates to either TRUE
or FALSE for every row. The query will return only those rows for which this condition
evaluates to TRUE. 
</p><p>
For example, if we want to get only those customers in Michigan we can use the query 
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span> * <br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">   FROM</span> Customer <br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">   WHERE</span> State
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'MI'</span></span></p><table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"><tbody><tr><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">CustID</font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">FirstName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">LastName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">StreetAddress </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">City </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">State </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">ZipCode </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">TotalSales </font></td></tr><tr><td><font size="1">2</font></td><td><font size="1">Magic</font></td><td><font size="1">Johnson</font></td><td><font size="1">456 Hollywood Blvd</font></td><td><font size="1">Lansing</font></td><td><font size="1">MI</font></td><td><font size="1">45222</font></td><td><font size="1">1500.00</font></td></tr><tr><td><font size="1">4</font></td><td><font size="1">Ron</font></td><td><font size="1">Mason</font></td><td><font size="1">501 E Grand River Ave</font></td><td><font size="1">Okemos</font></td><td><font size="1">MI</font></td><td><font size="1">45333</font></td><td><font size="1">2000.00</font></td></tr><tr><td><font size="1">5</font></td><td><font size="1">Steve</font></td><td><font size="1">Smith</font></td><td><font size="1">900 Belle St</font></td><td><font size="1">Detroit</font></td><td><font size="1">MI</font></td><td><font size="1">48888</font></td><td><font size="1">5000.00</font></td></tr></tbody></table><p>
This query only returned those rows that match our filter condition.
</p><p>
Of course, we can combine several of these clauses as in the following
</p><p><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT 
<br />
        cu.FirstName, 
<br />
        cu.LastName,<br />
        cu.State AS ResidencyState<br />
    FROM Customer cu 
<br />
    WHERE cu.State = <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'MI'</span><br />
    ORDER BY cu.LastName</span></span></p>
which returns the following results 
<table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"><tbody><tr><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">FirstName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">LastName </font></td><td style="BACKGROUND-COLOR: white; COLOR: black"><font size="1">ResidencyState </font></td></tr><tr><td><font size="1">Magic</font></td><td><font size="1">Johnson</font></td><td><font size="1">MI</font></td></tr><tr><td><font size="1">Ron</font></td><td><font size="1">Mason</font></td><td><font size="1">MI</font></td></tr><tr><td><font size="1">Steve</font></td><td><font size="1">Smith</font></td><td><font size="1">MI</font></td></tr></tbody></table><p>
As you can see, we can use the SELECT commmand to retrieve data from a table in a
database and customize the way that data comes back.  We've just scratched the
surface of this command.  In the next article, we'll look at more options of
the SELECT command 
</p><img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=e319538e-1502-490c-870c-1a0bfc912bb7" /></body>
      <title>SQL 101 - Part 3: Selecting data from a table</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,e319538e-1502-490c-870c-1a0bfc912bb7.aspx</guid>
      <link>http://www.davidgiard.com/2009/03/10/SQL101Part3SelectingDataFromATable.aspx</link>
      <pubDate>Tue, 10 Mar 2009 16:36:54 GMT</pubDate>
      <description>&lt;img alt="Back To Basics" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;div style="BORDER-BOTTOM: thin solid; BORDER-LEFT: thin solid; BACKGROUND-COLOR: silver; MARGIN: 5px; WIDTH: 80%; BORDER-TOP: thin solid; BORDER-RIGHT: thin solid"&gt;
&lt;p&gt;
NOTE: 
&lt;/p&gt;
&lt;p&gt;
For demos in this article, we will use a table named Customer that contains&amp;nbsp;the
followong&amp;nbsp;columns: 
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
Name&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
Data Type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
nvarchar(50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
LastName&lt;/td&gt;
&lt;td&gt;
nvarchar(50)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
nvarchar(255)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&amp;nbsp;City&lt;/td&gt;
&lt;td&gt;
nvarchar(255)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
State&lt;/td&gt;
&lt;td&gt;
char(2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&amp;nbsp;ZipCode&lt;/td&gt;
&lt;td&gt;
nvarchar(10)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
TotalSales&lt;/td&gt;
&lt;td&gt;
money&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Afer adding a few rows to the table, the data looks like this. 
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;TotalSales &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;123 Oxford Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Erlanger&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;KY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;40111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;456 Hollywood Blvd&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45222&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1500.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;789 Killbubbakill St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Baltimore&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MD&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;10111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;501 E Grand River Ave&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Okemos&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45333&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;2000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;
Retrieving data is one of the most common tasks performed on a relational database. 
&lt;/p&gt;
&lt;p&gt;
Fortunately, SQL Server includes a language that allows users (and programs) to retrieve
the data they want. This language is called Structured Query Language. It is usually
abbreviated "SQL" and often pronounced "SEE-kwuhl". 
&lt;/p&gt;
&lt;p&gt;
Getting data from a database is known as querying the database. The code to retrieve
that data is a query. When this code is written in SQL (as most of my queries are),
it is known as a SQL query. 
&lt;/p&gt;
&lt;p&gt;
The basic syntax for a SQL query that retrieves data from a single table is 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT
[List of Columns]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM [Table Name] 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE [Filter Condition] 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ORDER BY [Sort column or columns] &lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
In SQL, line breaks and extra spaces are not important. The language parser is smart
enough to figure out when a statement or command ends, so I usually try to format
my SQL statements to make them easy to read. 
&lt;/p&gt;
&lt;p&gt;
Only the &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT &lt;/span&gt;&lt;/span&gt;and
FROM parts of the query are required, so let's start with those. 
&lt;/p&gt;
&lt;p&gt;
EvenEven though the "SELECT" keyword typically comes first in this type of query,
I'll start by explaining the "FROM" keyword. When getting data from only one table,
follow the keyword FROM with the name of that table. For example, the clause 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
indicates that we are getting data from a table named Customer. We'll talk later about
how to get data from multiple tables in the same query. 
&lt;/p&gt;
&lt;p&gt;
It is possible to provide an alias for a table by following the table name with a
space, and the alias. For example 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
cust&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The above SQL clause says that we will get data from the Customer table, but that
we will use the string “cust” to refer to this table elsewhere in our query. 
&lt;/p&gt;
&lt;p&gt;
This is useful in the following situations 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
You want to provide a shorter name for the table in order to avoid retyping a long
name elsewhere in the query 
&lt;li&gt;
You want to avoid ambiguity when listing the same table name twice in the FROM clause. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
SELECT is the first keyword of this type of query and tells SQL Server that we want
to retrieve data from the database. The word "SELECT" is followed by a list of columns
that the query will return. If the column list contains duplicate column names (as
when you are getting data from two different tables and they each have a column with
the same name), you should precede the column name with the table name or alias. 
&lt;/p&gt;
&lt;p&gt;
You can also use the special character "*" in place of (or in addition to) the list
of column names in order to return all columns in the tables. 
&lt;/p&gt;
&lt;p&gt;
The following query returns all columns and rows in the Customer table. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; *
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;CustID &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font color=#000000 size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;&lt;font color=#000000&gt;TotalSales&lt;/font&gt; &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;1&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;123 Oxford Ct&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Erlanger&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;KY&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;40111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;456 Hollywood Blvd&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45222&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1500.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;3&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;789 Killbubbakill St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Baltimore&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MD&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;10111&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;501 E Grand River Ave&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Okemos&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45333&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;2000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
We can return onWe can return only the FirstName and LastName columns from the Customer
table with the following table 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer &lt;/span&gt;&lt;/pre&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
In the queries above, it is possible to qualify the column names, explicitly indicating
that they are from the Customer table. Of course, in this case it is unnecessary because
the column names are unique within the Customer table. The following examples qualify
the column names and returns the same data. 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Customer.FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Customer.LastName 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cu.FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cu.LastName 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer
cu&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
By default, each column returned by the query retains the name of the corresponding
column in the source table. you want to change the name of a If you want to change
the name of a column in the query, alias that column by appending the keyword " AS
" followed by the alias you want. For example 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; FirstNm, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;AS&lt;/span&gt; LastNm 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer&lt;/span&gt;
&lt;/p&gt;
This will return the following output 
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstNm &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastNm &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
If wIf we want to sort the output we can add the ORDER BY clause to our query. The
syntax for this clause is 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ORDER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; &lt;/span&gt;[List
of Columns on which to sort] 
&lt;/p&gt;
&lt;p&gt;
For example, we can sort our output on Last Name by changing our query to 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ORDER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; LastName &lt;/span&gt;
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
We can add more columns to the list of sort columns if we separate each with a comma.
The second column is only appropriate in our sort if two rows have identical values
for the first column. 
&lt;/p&gt;
&lt;p&gt;
For example 
&lt;/p&gt;
&lt;p&gt;
SELECT FirstNameFor example 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LastName 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; Customer 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ORDER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; LastName,
FirstName&lt;/span&gt;
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;David&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Giard&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Bubba&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
The above result set contains 2 rows with the last name "Smith".&amp;nbsp; These two rows
were sorted in order of their FirstName column.
&lt;/p&gt;
&lt;p&gt;
In many cases, we may not want to return eIn many cases, we may not want to return
every row in a table. We can use the WHERE clause to filter data. The syntax of the
WHERE clause is 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&lt;/span&gt; &lt;/span&gt;[Filter
Condition]
&lt;/p&gt;
&lt;p&gt;
The Filter condition is a Boolean expression, meaning it evaluates to either TRUE
or FALSE for every row. The query will return only those rows for which this condition
evaluates to TRUE. 
&lt;/p&gt;
&lt;p&gt;
For example, if we want to get only those customers in Michigan we can use the query 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; *&amp;nbsp;&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM&lt;/span&gt; Customer&amp;nbsp;&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&lt;/span&gt; State
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'MI'&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;CustID&lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;StreetAddress &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;City &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;State &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;ZipCode &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;TotalSales &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;2&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;456 Hollywood Blvd&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Lansing&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45222&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;1500.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;4&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;501 E Grand River Ave&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Okemos&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;45333&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;2000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;5&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;900 Belle St&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Detroit&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;48888&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;5000.00&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
This query only returned those rows that match our filter condition.
&lt;/p&gt;
&lt;p&gt;
Of course, we can combine several of these clauses as in the following
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cu.FirstName, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cu.LastName,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cu.State AS ResidencyState&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM Customer cu 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE cu.State = &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'MI'&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ORDER BY cu.LastName&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
which returns the following results 
&lt;table style="BORDER-BOTTOM: white thin solid; TEXT-ALIGN: left; BORDER-LEFT: white thin solid; BACKGROUND-COLOR: gray; WIDTH: 57%; COLOR: white; BORDER-TOP: white thin solid; BORDER-RIGHT: white thin solid"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;FirstName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;LastName &lt;/font&gt;&lt;/td&gt;
&lt;td style="BACKGROUND-COLOR: white; COLOR: black"&gt;
&lt;font size=1&gt;ResidencyState &lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Magic&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Johnson&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Ron&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Mason&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;font size=1&gt;Steve&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;Smith&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;
&lt;font size=1&gt;MI&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
As you can see, we can use the SELECT commmand to retrieve data from a table in a
database and customize the way that data comes back.&amp;nbsp; We've just scratched the
surface of this command.&amp;nbsp; In the next article, we'll look at more options of
the SELECT command 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=e319538e-1502-490c-870c-1a0bfc912bb7" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,e319538e-1502-490c-870c-1a0bfc912bb7.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=eea3f49a-7347-468a-9375-97a4ee388c1a</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,eea3f49a-7347-468a-9375-97a4ee388c1a.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,eea3f49a-7347-468a-9375-97a4ee388c1a.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=eea3f49a-7347-468a-9375-97a4ee388c1a</wfw:commentRss>
      <slash:comments>20</slash:comments>
      <title>SQL 101 - Part 2: Relationships</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,eea3f49a-7347-468a-9375-97a4ee388c1a.aspx</guid>
      <link>http://www.davidgiard.com/2009/02/26/SQL101Part2Relationships.aspx</link>
      <pubDate>Thu, 26 Feb 2009 13:17:33 GMT</pubDate>
      <description>&lt;img style="FLOAT: right; MARGIN-RIGHT: 5px" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;p&gt;
In &lt;a href="http://www.davidgiard.com/2009/02/24/SQL101Part1WhatIsADatabase.aspx"&gt;my
last article&lt;/a&gt;, I defined the basic concepts of database, table, column and row.
Using these constructs, you can organize data into a rectangular format. This paradigm
often works really well, because 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
You can group related information into a single container (a table) 
&lt;li&gt;
Each row represents a single entity (such as a customer, employee, or invoice) and 
&lt;li&gt;
Each column represents an attribute of the entity (such as FirstName, LastName, or
TotalSales).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Using this model, we can create a table containing information about a customer's
purchases. Each row in this item might represent a single purchase. 
&lt;/p&gt;
&lt;p&gt;
When a customer purchases an item, we probably would want to store some information
about that purchase. These bits of information about each purchase are attributes
of the purchase and are therefore candidates for columns. Below are examples of the
information we might want to save about a customer's purchase. 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Date of Purchase 
&lt;li&gt;
Customer First Name 
&lt;li&gt;
Customer Last Name 
&lt;li&gt;
Customer Street Address 
&lt;li&gt;
Customer City 
&lt;li&gt;
Customer Zip Code 
&lt;li&gt;
Item Purchased 
&lt;li&gt;
Quantity Purchased 
&lt;li&gt;
Price per Item 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We can create a table &lt;i&gt;CustomerPurchase&lt;/i&gt; with a column for each of the above
attributes and begin populating with data each time a customer purchases something.
The data would look something like this: 
&lt;/p&gt;
&lt;table border=1 cellpadding=0 cellspacing: 0&gt;
&lt;tbody&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
PurchaseDate&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
LastName&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
City&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
ZipCode&lt;/td&gt;
&lt;td&gt;
ItemPurchased&lt;/td&gt;
&lt;td&gt;
Quantity&lt;/td&gt;
&lt;td&gt;
PricePerItem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;td&gt;
Lamp&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
Bill&lt;/td&gt;
&lt;td&gt;
Jones&lt;/td&gt;
&lt;td&gt;
456 Maple&lt;/td&gt;
&lt;td&gt;
Smallville&lt;/td&gt;
&lt;td&gt;
48333&lt;/td&gt;
&lt;td&gt;
Chair&lt;/td&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
Mary&lt;/td&gt;
&lt;td&gt;
Brown&lt;/td&gt;
&lt;td&gt;
789 Oak&lt;/td&gt;
&lt;td&gt;
Middleton&lt;/td&gt;
&lt;td&gt;
48444&lt;/td&gt;
&lt;td&gt;
Table&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
This model seems to capture the information we want. Do you see any problems with
it? 
&lt;/p&gt;
&lt;p&gt;
What happens if a customer orders more than one item? If John Smith purchases a Chair
in addition to his Lamp, we can just add another row to the table, like so. 
&lt;/p&gt;
&lt;table border=1 cellspacing=0 cellpadding=0&gt;
&lt;tbody&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
PurchaseDate&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
LastName&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
City&lt;/td&gt;
&lt;td&gt;
Customer&lt;br&gt;
ZipCode&lt;/td&gt;
&lt;td&gt;
ItemPurchased&lt;/td&gt;
&lt;td&gt;
Quantity&lt;/td&gt;
&lt;td&gt;
PricePerItem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;td&gt;
Lamp&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
Bill&lt;/td&gt;
&lt;td&gt;
Jones&lt;/td&gt;
&lt;td&gt;
456 Maple&lt;/td&gt;
&lt;td&gt;
Smallville&lt;/td&gt;
&lt;td&gt;
48333&lt;/td&gt;
&lt;td&gt;
Chair&lt;/td&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
Mary&lt;/td&gt;
&lt;td&gt;
Brown&lt;/td&gt;
&lt;td&gt;
789 Oak&lt;/td&gt;
&lt;td&gt;
Middleton&lt;/td&gt;
&lt;td&gt;
48444&lt;/td&gt;
&lt;td&gt;
Table&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;td&gt;
Chair&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=20&gt;
2/27/2009&lt;/td&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;td&gt;
Table&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
But notice that now we are storing John Smith's name and address multiple times.&amp;nbsp;
Assuming John Smith will never change his name, this is a waste of space.&amp;nbsp; Granted,
this isn't very much wasted space when we have only a few orders, but imagine a system
with thousands of customers and millions of orders.&amp;nbsp; Do you really want all that
redundant information cluttering up your database? 
&lt;/p&gt;
&lt;p&gt;
Also, imagine that we want to correct an error in the spelling of John's name.&amp;nbsp;
With the current model, we must correct that error three times due to the redundant
storage.
&lt;/p&gt;
&lt;p&gt;
To address these issues, we can normalize the data.&amp;nbsp; Data normalization refers
to structuring our data in order to remove redundancy.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In our example, we accomplish this by creating a table of customers with the following
structure 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
FirstName 
&lt;li&gt;
LastName 
&lt;li&gt;
StreetAddress 
&lt;li&gt;
City 
&lt;li&gt;
ZipCode 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
and and moving the customer data to this table - one row per customer. 
&lt;/p&gt;
&lt;p&gt;
&lt;table border=1 cellspacing=0 cellpadding=0&gt;
&lt;tbody&gt;
&lt;tr height=20&gt;
&lt;td&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
LastName&lt;/td&gt;
&lt;td&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
City&lt;/td&gt;
&lt;td&gt;
ZipCode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
Bill&lt;/td&gt;
&lt;td&gt;
Jones&lt;/td&gt;
&lt;td&gt;
456 Maple&lt;/td&gt;
&lt;td&gt;
Smallville&lt;/td&gt;
&lt;td&gt;
48333&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
Mary&lt;/td&gt;
&lt;td&gt;
Brown&lt;/td&gt;
&lt;td&gt;
789 Oak&lt;/td&gt;
&lt;td&gt;
Middleton&lt;/td&gt;
&lt;td&gt;
48444&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Then we add an extra column to the ustomerPurchase&gt; tab table.&amp;nbsp; This new column
is special in that the value in it will uniquely identify each row - in other words,
no two rows will have the same value.&amp;nbsp; This unique column goes by many names
but we will call it a Primary Key here.&amp;nbsp; In this case, the Primary Key column
will be named "CustomerID" and will hold an integer. 
&lt;/p&gt;
&lt;p&gt;
&lt;table border=1 cellspacing=0 cellpadding=0&gt;
&lt;tbody&gt;
&lt;tr height=20&gt;
&lt;td&gt;
CustomerID&lt;/td&gt;
&lt;td&gt;
FirstName&lt;/td&gt;
&lt;td&gt;
LastName&lt;/td&gt;
&lt;td&gt;
StreetAddress&lt;/td&gt;
&lt;td&gt;
City&lt;/td&gt;
&lt;td&gt;
ZipCode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
John&lt;/td&gt;
&lt;td&gt;
Smith&lt;/td&gt;
&lt;td&gt;
123 Elm&lt;/td&gt;
&lt;td&gt;
Bigg City&lt;/td&gt;
&lt;td&gt;
48222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
Bill&lt;/td&gt;
&lt;td&gt;
Jones&lt;/td&gt;
&lt;td&gt;
456 Maple&lt;/td&gt;
&lt;td&gt;
Smallville&lt;/td&gt;
&lt;td&gt;
48333&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td&gt;
3&lt;/td&gt;
&lt;td&gt;
Mary&lt;/td&gt;
&lt;td&gt;
Brown&lt;/td&gt;
&lt;td&gt;
789 Oak&lt;/td&gt;
&lt;td&gt;
Middleton&lt;/td&gt;
&lt;td&gt;
48444&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now we can go back to the ustomerPurchase&gt; tab table, and replace the columns that
describe customer with a column to hold the CustomerID.&amp;nbsp; This&amp;nbsp;replacement
column&amp;nbsp;is known as a "Foreign Key".&amp;nbsp; It references a Primary Key in another
table and is used to point to a single unique record in that other table.
&lt;/p&gt;
&lt;p&gt;
&lt;table border=1 cellspacing=0 cellpadding=0&gt;
&lt;tbody&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
PurchaseDate&lt;/td&gt;
&lt;td&gt;
CustomerID&lt;/td&gt;
&lt;td&gt;
ItemPurchased&lt;/td&gt;
&lt;td&gt;
Quantity&lt;/td&gt;
&lt;td&gt;
PricePerItem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
Lamp&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
Chair&lt;/td&gt;
&lt;td&gt;
2&lt;/td&gt;
&lt;td&gt;
100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=20&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
3&lt;/td&gt;
&lt;td&gt;
Table&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=20&gt;
2/26/2009&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
Chair&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height=20&gt;
2/27/2009&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
Table&lt;/td&gt;
&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;
50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This is all we need because, given the CustomerID, we can look in the &lt;em&gt;Customer&lt;/em&gt; table,
find the record for that customer and get all information about that customer. 
&lt;p&gt;
This concept of using a key value to point to a row in another table is known as a
relationship.&amp;nbsp; We say that the &lt;i&gt;Customer&lt;/i&gt; table is related to the &lt;i&gt;CustomerPurchase&lt;/i&gt; tab
table.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
This type of relationship is known as a one-to-many relationship, every customer may
have many orders.&amp;nbsp; In this type of relationship the table with one row is known
as the parent and the table with (potentially) many rows is known as the child table.&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
This relationship is typically represented by a drawing similar to the one below.
&lt;/p&gt;
&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/DbRelationship.jpg"&gt;
&lt;/p&gt;
&lt;p&gt;
Organizing data in this way can make storage of that data far more efficient and flexible.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=eea3f49a-7347-468a-9375-97a4ee388c1a" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,eea3f49a-7347-468a-9375-97a4ee388c1a.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f07efbfb-04c9-4db1-bd79-9300f5eaeee2</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f07efbfb-04c9-4db1-bd79-9300f5eaeee2.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f07efbfb-04c9-4db1-bd79-9300f5eaeee2.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f07efbfb-04c9-4db1-bd79-9300f5eaeee2</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img style="FLOAT: right; MARGIN-RIGHT: 5px" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG" />
        <p>
In this article, we will define a database, a table and the main parts of a table
- rows and columns.
</p>
        <p>
A database is an organized (or structured) collection of information. 
</p>
        <p>
Most companies spend a lot of time and effort collecting information and storing it
somewhere, but not all that information is organized, which makes it difficult to
retrieve anything relevant later on.  A database adds structure to the information
making it easier to maintain and query it.
</p>
        <p>
Database engines like SQL Server provide a structure to organize data in a way that
makes sense to a user.  Specifically, SQL Server uses a relational model* to
organize its data. 
</p>
        <p>
In a relational database, data is partitioned into tables.  Tables are a way
of data storing data in rows and columns, kind of like in an Excel worksheet.  
</p>
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/ExcelSample.bmp" />
          <br />
          <strong>
            <font size="1">Figure 1 - Data in an Excel workbook</font>
          </strong>
        </p>
        <p>
I've always found this rectangular view of data very intuitive.
</p>
        <p>
Just as in a workbook, each table row represents a discrete record.  All information
in that row serves to describe the row.   
</p>
        <p>
Similarly, a table column is a placeholder that describes a single attribute for each
row.  The advantage SQL Server has over Excel is that you can easily place rules
onto a column, restricting the type of data that can be stored there.  
</p>
        <p>
If a SQL Server column is designed to hold a date, a property of that column can be
set to throw an error if a person or program tries to store a string.  
We can set up such restrictions for many data types, so that a column can be restricted
to allow only integers, only TRUE/FALSE values, or only binary objects.  We can
even restrict the maximum length of a string or require users to always enter a value
into a column - all simply by setting properties on the column.**
</p>
        <p>
For example, a table named "Customers" might be used to store information about your
company's customers.  Each row in this table would represent a single customer. 
Each column would hold an attribute of that customer, so you could create columns
such as FirstName, LastName and StreetAddress that would hold the appropriate values
for each customer.  
</p>
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/SqlServerTableSample.bmp" />
          <br />
          <strong>
            <font size="1">Figure 2 - Data in a SQL Server table</font>
          </strong>
        </p>
        <p>
Looking at the first row, gives us information about the customer.  It should
be obvious that this customer has a first name of "David", a last name of "Giard"
and an address of "123 Main St".
</p>
        <hr />
        <p>
*SQL Server does provide some non-relational ways of storing data but those are beyond
the scope of this article.<br />
** It is possible to configure Microsoft Excel to restrict data input, but this task
is relatively advanced and far more easily accomplished in SQL Server.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f07efbfb-04c9-4db1-bd79-9300f5eaeee2" />
      </body>
      <title>SQL 101 - Part 1: What is a Database?</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f07efbfb-04c9-4db1-bd79-9300f5eaeee2.aspx</guid>
      <link>http://www.davidgiard.com/2009/02/24/SQL101Part1WhatIsADatabase.aspx</link>
      <pubDate>Tue, 24 Feb 2009 18:14:48 GMT</pubDate>
      <description>&lt;img style="FLOAT: right; MARGIN-RIGHT: 5px" src="http://www.davidgiard.com/content/binary/BackToBasics.JPG"&gt; 
&lt;p&gt;
In this article, we will define a database, a table and the&amp;nbsp;main parts of a table
- rows and columns.
&lt;/p&gt;
&lt;p&gt;
A database is an organized (or structured) collection of information. 
&lt;/p&gt;
&lt;p&gt;
Most companies spend a lot of time and effort collecting information and storing it
somewhere, but not all that information is organized, which makes it difficult to
retrieve anything relevant later on.&amp;nbsp; A database adds structure to the information
making it easier to maintain and query it.
&lt;/p&gt;
&lt;p&gt;
Database engines like SQL Server provide a structure to organize data in a way that
makes sense to a user.&amp;nbsp; Specifically, SQL Server uses a relational model* to
organize its data. 
&lt;/p&gt;
&lt;p&gt;
In a relational database, data is partitioned into tables.&amp;nbsp; Tables are a way
of data storing data in rows and columns, kind of like in an Excel worksheet.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/ExcelSample.bmp"&gt;
&lt;br&gt;
&lt;strong&gt;&lt;font size=1&gt;Figure 1 - Data in an Excel workbook&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I've always found this rectangular view of data very intuitive.
&lt;/p&gt;
&lt;p&gt;
Just as in a workbook, each table row represents a discrete record.&amp;nbsp; All information
in that row serves to describe the row.&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Similarly, a table column is a placeholder that describes a single attribute for each
row.&amp;nbsp; The advantage SQL Server has over Excel is that you can easily place rules
onto a column, restricting the type of data that can be stored there.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
If a SQL Server column is designed to hold a date, a property of that column can be
set to throw an error if a person or program tries to store a string.&amp;nbsp;&amp;nbsp;
We can set up such restrictions for many data types, so that a column can be restricted
to allow only integers, only TRUE/FALSE values, or only binary objects.&amp;nbsp; We can
even restrict the maximum length of a string or require users to always enter a value
into a column - all simply by setting properties on the column.**
&lt;/p&gt;
&lt;p&gt;
For example, a table named "Customers" might be used to store information about your
company's customers.&amp;nbsp; Each row in this table would represent a single customer.&amp;nbsp;
Each column would hold an attribute of that customer, so you could create columns
such as FirstName, LastName and StreetAddress that would hold the appropriate values
for each customer.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/SqlServerTableSample.bmp"&gt;
&lt;br&gt;
&lt;strong&gt;&lt;font size=1&gt;Figure&amp;nbsp;2 - Data in a SQL Server table&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Looking at the first row, gives us information about the customer.&amp;nbsp; It should
be obvious that this customer has a first name of "David", a last name of "Giard"
and an address of "123 Main St".
&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;
*SQL Server does provide some non-relational ways of storing data but those are beyond
the scope of this article.&lt;br&gt;
** It is possible to configure Microsoft Excel to restrict data input, but this task
is relatively advanced and far more easily accomplished in SQL Server.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f07efbfb-04c9-4db1-bd79-9300f5eaeee2" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f07efbfb-04c9-4db1-bd79-9300f5eaeee2.aspx</comments>
      <category>Back To Basics</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=77ca0949-337c-4c64-b055-e9b32a96d002</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,77ca0949-337c-4c64-b055-e9b32a96d002.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,77ca0949-337c-4c64-b055-e9b32a96d002.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=77ca0949-337c-4c64-b055-e9b32a96d002</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 3</strong>
        </p>
        <p>
In this interview, <a href="http://jasonfollas.com/blog/" target="_blank">Jason Follas</a> explains
spatial data types, which were introduced in SQL Server 2008
</p>
        <object id="viddler_f6790a76" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="311">
          <param name="_cx" value="11562" />
          <param name="_cy" value="8228" />
          <param name="FlashVars" value="" />
          <param name="Movie" value="http://www.viddler.com/simple/f6790a76/" />
          <param name="Src" value="http://www.viddler.com/simple/f6790a76/" />
          <param name="WMode" value="Transparent" />
          <param name="Play" value="-1" />
          <param name="Loop" value="-1" />
          <param name="Quality" value="High" />
          <param name="SAlign" value="LT" />
          <param name="Menu" value="-1" />
          <param name="Base" value="" />
          <param name="AllowScriptAccess" value="always" />
          <param name="Scale" value="ShowAll" />
          <param name="DeviceFont" value="0" />
          <param name="EmbedMovie" value="0" />
          <param name="BGColor" value="" />
          <param name="SWRemote" value="" />
          <param name="MovieData" value="" />
          <param name="SeamlessTabbing" value="1" />
          <param name="Profile" value="0" />
          <param name="ProfileAddress" value="" />
          <param name="ProfilePort" value="0" />
          <param name="AllowNetworking" value="all" />
          <param name="AllowFullScreen" value="true" />
          <embed src="http://www.viddler.com/simple/f6790a76/" width="437" height="311" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_f6790a76" wmode="transparent">
          </embed>
        </object>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=77ca0949-337c-4c64-b055-e9b32a96d002" />
      </body>
      <title>Jason Follas explains SQL Server Spatial Data Types</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,77ca0949-337c-4c64-b055-e9b32a96d002.aspx</guid>
      <link>http://www.davidgiard.com/2009/02/10/JasonFollasExplainsSQLServerSpatialDataTypes.aspx</link>
      <pubDate>Tue, 10 Feb 2009 15:16:49 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 3&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this interview, &lt;a href="http://jasonfollas.com/blog/" target=_blank&gt;Jason Follas&lt;/a&gt; explains
spatial data types, which were introduced in SQL Server 2008
&lt;/p&gt;
&lt;object id=viddler_f6790a76 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=311&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="8228"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/simple/f6790a76/"&gt;
&lt;param name="Src" value="http://www.viddler.com/simple/f6790a76/"&gt;
&lt;param name="WMode" value="Transparent"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value="LT"&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/simple/f6790a76/" width="437" height="311" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_f6790a76" wmode="transparent"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=77ca0949-337c-4c64-b055-e9b32a96d002" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,77ca0949-337c-4c64-b055-e9b32a96d002.aspx</comments>
      <category>Interviews</category>
      <category>SQL Server</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=6bf5d62c-0d0f-4641-af96-a271631eeac4</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,6bf5d62c-0d0f-4641-af96-a271631eeac4.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,6bf5d62c-0d0f-4641-af96-a271631eeac4.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6bf5d62c-0d0f-4641-af96-a271631eeac4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Below is a list of my recent series of articles on Visual Studio 2008 Database Edition
(aka “Data Dude”)
</p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/10/TheGoodnessOfDataDude.aspx">The
Goodness of Data Dude </a>
          </span>
        </p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx">Data
Dude tutorial 1 - Creating a database project </a>
          </span>
        </p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/12/DataDudeTutorial2UsingSchemaCompareToolToUpdateADatabaseProject.aspx">Data
Dude tutorial 2 - Using Schema Compare tool to update a database project </a>
          </span>
        </p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/13/DataDudeTutorial3UsingSchemaCompareToolToDeployDatabaseChanges.aspx">Data
Dude tutorial 3 - Using Schema Compare tool to deploy database changes </a>
          </span>
        </p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/14/DataDudeTutorial4WritingDatabaseUnitTests.aspx">Data
Dude tutorial 4 - Writing Database Unit Tests </a>
          </span>
        </p>
        <p>
          <span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">
            <a href="http://www.davidgiard.com/2008/08/15/DataDudeTutorial5UsingTheDataCompareTool.aspx" temp_href="temp_href">Data
Dude tutorial 5 - Using the Data Compare tool </a>
          </span>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=6bf5d62c-0d0f-4641-af96-a271631eeac4" />
      </body>
      <title>Dave's Data Dude series</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,6bf5d62c-0d0f-4641-af96-a271631eeac4.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/16/DavesDataDudeSeries.aspx</link>
      <pubDate>Sat, 16 Aug 2008 15:39:15 GMT</pubDate>
      <description>&lt;p&gt;
Below is a list of my recent series of articles on Visual Studio 2008 Database Edition
(aka “Data Dude”)
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/10/TheGoodnessOfDataDude.aspx"&gt;The
Goodness of Data Dude &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx"&gt;Data
Dude tutorial 1 - Creating a database project &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/12/DataDudeTutorial2UsingSchemaCompareToolToUpdateADatabaseProject.aspx"&gt;Data
Dude tutorial 2 - Using Schema Compare tool to update a database project &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/13/DataDudeTutorial3UsingSchemaCompareToolToDeployDatabaseChanges.aspx"&gt;Data
Dude tutorial 3 - Using Schema Compare tool to deploy database changes &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/14/DataDudeTutorial4WritingDatabaseUnitTests.aspx"&gt;Data
Dude tutorial 4 - Writing Database Unit Tests &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;a href="http://www.davidgiard.com/2008/08/15/DataDudeTutorial5UsingTheDataCompareTool.aspx" temp_href&gt;Data
Dude tutorial 5 - Using the Data Compare tool &lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=6bf5d62c-0d0f-4641-af96-a271631eeac4" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,6bf5d62c-0d0f-4641-af96-a271631eeac4.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=cde1a47b-5f8b-4ecb-ba48-7ffea2524d30</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,cde1a47b-5f8b-4ecb-ba48-7ffea2524d30.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,cde1a47b-5f8b-4ecb-ba48-7ffea2524d30.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cde1a47b-5f8b-4ecb-ba48-7ffea2524d30</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Microsoft Visual Studio
Team System 2008 Database Edition (aka “Data Dude”) provides tools for managing and
deploying SQL Server databases.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p>
          <font color="#000000" size="3" face="Calibri">In this article, we will discuss how
to migrate data from one database to another.<span style="mso-spacerun: yes">   </span>Data
Dude provides the <i style="mso-bidi-font-style: normal">Data Compare</i> tool for
this purpose.</font>
        </p>
        <p>
          <font color="#000000" size="3" face="Calibri">In order to use the Data Compare tool,
the following conditions must be true</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Data
exists in a source table.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">You
want to migrate that data to a table of the same name in a different database.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Both
tables must have the same structure.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Both
tables must have a primary key to uniquely identify rows.</font>
          </font>
        </p>
        <p>
          <font color="#000000" size="3" face="Calibri">Follow the steps below to migrate data
with the Data Compare tool.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Launch
Visual Studio 2008</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Select <b style="mso-bidi-font-weight: normal">Data
| Data Compare | New Data Compare</b>.<span style="mso-spacerun: yes">  </span>The <b style="mso-bidi-font-weight: normal">New
Data Comparison</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> dialog
displays<br /><a href="http://www.davidgiard.com/content/binary/DD04_Fig1.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD04_Fig1.jpg" width="528" height="451" /></a><br /><span style="mso-spacerun: yes">  </span><b style="mso-bidi-font-weight: normal">Figure
1</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">When
migrating data from a table in one database to another, the database you intend to
update is known as the “Target Database”.<span style="mso-spacerun: yes">  </span>The
other database is known as the “Source Database”.<span style="mso-spacerun: yes">  </span>In
the <b style="mso-bidi-font-weight: normal">New Data Comparison</b> dialog, select
the Source Database and Target Database connections.<span style="mso-spacerun: yes">  </span>If
you have not created a Visual Studio connection to these databases in Visual Studio,
you can click the <b style="mso-bidi-font-weight: normal">New Connection</b></font>
              <font size="3"> button
to create them.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The <b style="mso-bidi-font-weight: normal">New
Data Comparison</b> dialog contains checkboxes that allow you to specify which rows
you want to see and compare.<span style="mso-spacerun: yes">  </span>I don’t
usually change these (they are all checked by default) but it may speed up the process
to clear the <b style="mso-bidi-font-weight: normal">Identical Records</b></font>
              <font size="3"> checkbox.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Click
the <b style="mso-bidi-font-weight: normal">Next</b></font>
            </font>
          </font>
          <font color="#000000" size="3" face="Calibri"> button
to advance to the second screen of the wizard.<br /><a href="http://www.davidgiard.com/content/binary/DD04_Fig2.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD04_Fig2.jpg" width="566" height="464" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
2</b><br />
On this screen, you can choose which tables to compare.<span style="mso-spacerun: yes">  </span>Usually
I am only interested in one or two tables, so I clear the rest of the checkboxes.<span style="mso-spacerun: yes">  </span>If
I have a million rows in my customer table and I’m not interested in migrating any
of those rows, I can save a lot of processing time by un-checking the customer table.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">d.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Click
the <b style="mso-bidi-font-weight: normal">Finish</b> button to display the <b style="mso-bidi-font-weight: normal">Data
Compare</b></font>
              <font size="3"> window.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">The <b style="mso-bidi-font-weight: normal">Data
Compare</b> window consists of two panes: the <i style="mso-bidi-font-style: normal">Object
List</i> on top and the <i style="mso-bidi-font-style: normal">Record Details</i></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> at
the bottom.<br /><a href="http://www.davidgiard.com/content/binary/DD04_Fig3.jpg" target="_pix"><img style="WIDTH: 667px; HEIGHT: 316px" border="0" src="http://www.davidgiard.com/content/binary/DD04_Fig3.jpg" width="959" height="633" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
3</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The
object list displays each table or view as a single row with columns summarizing the
number of new, removed, changed and identical rows.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Rows
are matched on their primary key.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Click
a row in the object list to display details in the record details pane.<span style="mso-spacerun: yes">  </span>Here
you can click a tab to view the rows that are new, missing or changed.<span style="mso-spacerun: yes">  </span>Checking
the checkbox next to a record flags it to the Data Compare tool, meaning you want
to update the target database to match the same row in the source database.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">This
may result in an INSERT, UPDATE, or DELETE statement depending on the tab on which
the record is listed.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">For
a record to be flagged for update, both the table and the record must be checked.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">4.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">After
checking all the rows you wish to update, click the <b style="mso-bidi-font-weight: normal">Write
Updates</b></font>
              <font size="3"> toolbar button to commit your changes to the target
database.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">5.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Alternatively,
you can click the <b style="mso-bidi-font-weight: normal">Export To Editor</b> toolbar
button to generate a SQL script that you can run in the SQL Server query editor.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">This
method requires an extra step but has the following advantages</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">You
can modify the script before running it.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font size="3" face="Calibri">You
can send the script to someone else to run.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">You
can view the script to learn what Data Dude is doing.<span style="mso-spacerun: yes">  </span>It’s
interesting to note that constraints on each table are dropped before copying data,
then created after the data is copied.<span style="mso-spacerun: yes">  </span>This
speeds up the process.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Also,
note the use of transactions to prevent incomplete data copies.  Below is a sample
script updating data in one table.<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">/*<br />
This script was created by Visual Studio on 8/15/2008 at 8:57 AM.<br />
Run this script on dgiard.Test_QA.dbo to make it the same as dgiard.Test_Dev.dbo.<br />
This script performs its actions in the following order:<br />
1. Disable foreign-key constraints.<br />
2. Perform DELETE commands. 
<br />
3. Perform UPDATE commands.<br />
4. Perform INSERT commands.<br />
5. Re-enable foreign-key constraints.<br />
Please back up your target database before running this script.<br />
*/</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> NUMERIC_ROUNDABORT <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">OFF</span><br />
GO<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> XACT_ABORT,
ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">QUOTED_IDENTIFIER</span>, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ANSI_NULLS</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ON</span><br />
GO<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">/*Pointer
used for text / image updates. This might not be needed, but is declared here just
in case*/</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @pv <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">binary</span>(16)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BEGIN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TRANSACTION</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[OrderDetails] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DROP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_OrderDetails_Orders]<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[OrderDetails] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DROP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_OrderDetails_Products]<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[Orders] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DROP</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_Orders_Customers]<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DELETE</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> [dbo].[ProductTypes] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHERE</span> [ProductTypeID]=N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'5646953f-7b89-4862-bcf3-bf53450d28bb'</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INSERT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">VALUES</span> (N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'7beb0d99-d034-41b9-bbf7-f9cdcdbedc30'</span>,
N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Furniture'</span>)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INSERT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">VALUES</span> (N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'abc19a14-5968-4c5f-9f0f-4debc034cb90'</span>,
N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Hardware'</span>)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INSERT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">VALUES</span> (N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'b9e446ed-eeb1-4334-b191-c70a55ef1a05'</span>,
N<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Books'</span>)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[OrderDetails] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ADD</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_OrderDetails_Orders] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FOREIGN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">KEY</span> ([OrderID]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">REFERENCES</span> [dbo].[Orders]
([OrderID])<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[OrderDetails] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ADD</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_OrderDetails_Products] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FOREIGN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">KEY</span> ([ProductID]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">REFERENCES</span> [dbo].[Products]
([ProductID])<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ALTER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TABLE</span> [dbo].[Orders] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ADD</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CONSTRAINT</span> [FK_Orders_Customers] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FOREIGN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">KEY</span> ([CustomerID]) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">REFERENCES</span> [dbo].[Customers]
([CustID])<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">COMMIT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">TRANSACTION</span><br /></span></font>
            </font>
          </font>
        </p>
        <p>
          <font color="#000000" size="3" face="Calibri">The <i style="mso-bidi-font-style: normal">Data
Compare</i> tool is a simple tool for accomplishing a useful task.<span style="mso-spacerun: yes">  </span>Since
I discovered it, it has saved me a lot of time setting up new data environments.</font>
        </p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cde1a47b-5f8b-4ecb-ba48-7ffea2524d30" />
      </body>
      <title>Data Dude tutorial 5 - Using the Data Compare tool</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,cde1a47b-5f8b-4ecb-ba48-7ffea2524d30.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/15/DataDudeTutorial5UsingTheDataCompareTool.aspx</link>
      <pubDate>Fri, 15 Aug 2008 13:02:53 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Microsoft Visual Studio Team System
2008 Database Edition (aka “Data Dude”) provides tools for managing and deploying
SQL Server databases.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In this article, we will discuss how to migrate
data from one database to another.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Data
Dude provides the &lt;i style="mso-bidi-font-style: normal"&gt;Data Compare&lt;/i&gt; tool for
this purpose.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In order to use the Data Compare tool, the
following conditions must be true&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Data
exists in a source table.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;You
want to migrate that data to a table of the same name in a different database.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Both
tables must have the same structure.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Both
tables must have a primary key to uniquely identify rows.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Follow the steps below to migrate data with
the Data Compare tool.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Launch
Visual Studio 2008&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Select &lt;b style="mso-bidi-font-weight: normal"&gt;Data
| Data Compare | New Data Compare&lt;/b&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;New
Data Comparison&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; dialog
displays&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD04_Fig1.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD04_Fig1.jpg" width=528 height=451&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
1&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;When
migrating data from a table in one database to another, the database you intend to
update is known as the “Target Database”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The
other database is known as the “Source Database”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In
the &lt;b style="mso-bidi-font-weight: normal"&gt;New Data Comparison&lt;/b&gt; dialog, select
the Source Database and Target Database connections.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
you have not created a Visual Studio connection to these databases in Visual Studio,
you can click the &lt;b style="mso-bidi-font-weight: normal"&gt;New Connection&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; button
to create them.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;New
Data Comparison&lt;/b&gt; dialog contains checkboxes that allow you to specify which rows
you want to see and compare.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I don’t
usually change these (they are all checked by default) but it may speed up the process
to clear the &lt;b style="mso-bidi-font-weight: normal"&gt;Identical Records&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; checkbox.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Click
the &lt;b style="mso-bidi-font-weight: normal"&gt;Next&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000 size=3 face=Calibri&gt; button
to advance to the second screen of the wizard.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD04_Fig2.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD04_Fig2.jpg" width=566 height=464&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
2&lt;/b&gt;
&lt;br&gt;
On this screen, you can choose which tables to compare.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Usually
I am only interested in one or two tables, so I clear the rest of the checkboxes.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
I have a million rows in my customer table and I’m not interested in migrating any
of those rows, I can save a lot of processing time by un-checking the customer table.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;d.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Click
the &lt;b style="mso-bidi-font-weight: normal"&gt;Finish&lt;/b&gt; button to display the &lt;b style="mso-bidi-font-weight: normal"&gt;Data
Compare&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; window.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;Data
Compare&lt;/b&gt; window consists of two panes: the &lt;i style="mso-bidi-font-style: normal"&gt;Object
List&lt;/i&gt; on top and the &lt;i style="mso-bidi-font-style: normal"&gt;Record Details&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; at
the bottom.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD04_Fig3.jpg" target=_pix&gt;&lt;img style="WIDTH: 667px; HEIGHT: 316px" border=0 src="http://www.davidgiard.com/content/binary/DD04_Fig3.jpg" width=959 height=633&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
3&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The
object list displays each table or view as a single row with columns summarizing the
number of new, removed, changed and identical rows.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Rows
are matched on their primary key.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Click
a row in the object list to display details in the record details pane.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here
you can click a tab to view the rows that are new, missing or changed.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Checking
the checkbox next to a record flags it to the Data Compare tool, meaning you want
to update the target database to match the same row in the source database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;This
may result in an INSERT, UPDATE, or DELETE statement depending on the tab on which
the record is listed.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;For
a record to be flagged for update, both the table and the record must be checked.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;4.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;After
checking all the rows you wish to update, click the &lt;b style="mso-bidi-font-weight: normal"&gt;Write
Updates&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; toolbar button to commit your changes to the target
database.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;5.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Alternatively,
you can click the &lt;b style="mso-bidi-font-weight: normal"&gt;Export To Editor&lt;/b&gt; toolbar
button to generate a SQL script that you can run in the SQL Server query editor.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;This
method requires an extra step but has the following advantages&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;You
can modify the script before running it.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;You
can send the script to someone else to run.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l1 level2 lfo2; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;You
can view the script to learn what Data Dude is doing.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It’s
interesting to note that constraints on each table are dropped before copying data,
then created after the data is copied.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
speeds up the process.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Also,
note the use of transactions to prevent incomplete data copies.&amp;nbsp; Below is a sample
script updating data in one table.&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;/*&lt;br&gt;
This script was created by Visual Studio on 8/15/2008 at 8:57 AM.&lt;br&gt;
Run this script on dgiard.Test_QA.dbo to make it the same as dgiard.Test_Dev.dbo.&lt;br&gt;
This script performs its actions in the following order:&lt;br&gt;
1. Disable foreign-key constraints.&lt;br&gt;
2. Perform DELETE commands. 
&lt;br&gt;
3. Perform UPDATE commands.&lt;br&gt;
4. Perform INSERT commands.&lt;br&gt;
5. Re-enable foreign-key constraints.&lt;br&gt;
Please back up your target database before running this script.&lt;br&gt;
*/&lt;/span&gt;
&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; NUMERIC_ROUNDABORT &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;OFF&lt;/span&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; XACT_ABORT,
ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;QUOTED_IDENTIFIER&lt;/span&gt;, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ANSI_NULLS&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ON&lt;/span&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;/*Pointer
used for text / image updates. This might not be needed, but is declared here just
in case*/&lt;/span&gt;
&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @pv &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;binary&lt;/span&gt;(16)&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BEGIN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TRANSACTION&lt;/span&gt;
&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[OrderDetails] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DROP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_OrderDetails_Orders]&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[OrderDetails] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DROP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_OrderDetails_Products]&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[Orders] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DROP&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_Orders_Customers]&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DELETE&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; [dbo].[ProductTypes] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHERE&lt;/span&gt; [ProductTypeID]=N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'5646953f-7b89-4862-bcf3-bf53450d28bb'&lt;/span&gt;
&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INSERT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;VALUES&lt;/span&gt; (N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'7beb0d99-d034-41b9-bbf7-f9cdcdbedc30'&lt;/span&gt;,
N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Furniture'&lt;/span&gt;)&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INSERT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;VALUES&lt;/span&gt; (N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'abc19a14-5968-4c5f-9f0f-4debc034cb90'&lt;/span&gt;,
N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Hardware'&lt;/span&gt;)&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INSERT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; [dbo].[ProductTypes]
([ProductTypeID], [ProductTypeName]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;VALUES&lt;/span&gt; (N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'b9e446ed-eeb1-4334-b191-c70a55ef1a05'&lt;/span&gt;,
N&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Books'&lt;/span&gt;)&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[OrderDetails] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ADD&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_OrderDetails_Orders] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FOREIGN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;KEY&lt;/span&gt; ([OrderID]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;REFERENCES&lt;/span&gt; [dbo].[Orders]
([OrderID])&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[OrderDetails] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ADD&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_OrderDetails_Products] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FOREIGN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;KEY&lt;/span&gt; ([ProductID]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;REFERENCES&lt;/span&gt; [dbo].[Products]
([ProductID])&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ALTER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TABLE&lt;/span&gt; [dbo].[Orders] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ADD&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CONSTRAINT&lt;/span&gt; [FK_Orders_Customers] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FOREIGN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;KEY&lt;/span&gt; ([CustomerID]) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;REFERENCES&lt;/span&gt; [dbo].[Customers]
([CustID])&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;COMMIT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;TRANSACTION&lt;/span&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&gt;&gt;&gt; 
&lt;p&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;The &lt;i style="mso-bidi-font-style: normal"&gt;Data
Compare&lt;/i&gt; tool is a simple tool for accomplishing a useful task.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Since
I discovered it, it has saved me a lot of time setting up new data environments.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cde1a47b-5f8b-4ecb-ba48-7ffea2524d30" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,cde1a47b-5f8b-4ecb-ba48-7ffea2524d30.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#000000" size="3" face="Calibri">Writing Unit Tests is an essential step
in developing robust, maintainable code.<span style="mso-spacerun: yes">  </span>Unit
Tests increase quality and mitigate the risk of future code changes.<span style="mso-spacerun: yes">  </span>However,
relatively few developers take the time to write unit tests for their stored procedures. <span style="mso-spacerun: yes"> </span>The
primary reason for this is that few tools exist to test stored procedures.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">Microsoft Visual Studio Team System
2008 Database Edition (aka “Data Dude”) provides tools to help developers write unit
tests against SQL Server stored procedures.<span style="mso-spacerun: yes">  </span>The
tool integrates with MSTest, wich is a testing framework many developers are already
using for their other unit tests.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In order to write unit tests for your
stored procedures, those stored procedures must be in a database project.<span style="mso-spacerun: yes">  </span>For
information on how to create a database project from a SQL Server database see: </font>
          <a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx">
            <font color="#0000ff" size="3" face="Calibri">http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx</font>
          </a>
          <font color="#000000" size="3" face="Calibri">
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">This document describes how to create
a database unit test.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Launch
Visual Studio and open your Database Project. </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Open
the Schema View.<span style="mso-spacerun: yes">  </span>Select <b style="mso-bidi-font-weight: normal">View
| Schema View</b></font>
              <font size="3">.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Right-click
a stored procedure and select <b style="mso-bidi-font-weight: normal">Create Unit
Test</b> from the context menu.<span style="mso-spacerun: yes">  </span>The <b style="mso-bidi-font-weight: normal">Create
Unit Tests</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> dialog
displays.<br /><a href="http://www.davidgiard.com/content/binary/DD03_Fig1.jpg" target="_pix"><img style="WIDTH: 544px; HEIGHT: 418px" border="0" src="http://www.davidgiard.com/content/binary/DD03_Fig1.jpg" width="772" height="290" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
1</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">4.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Check
the checkboxes next to all the stored procedures for which you wish to create unit
tests.<span style="mso-spacerun: yes">  </span>Select the .Net language (Visual
Basic .Net or C#) in which you want the automatic code to be generated.<span style="mso-spacerun: yes">  </span>You
won’t be modifying this code so it isn’t that important, but I tend to keep all my
code in the same language, so you may as well choose your favorite language here.<span style="mso-spacerun: yes">  </span>Enter
a meaningful name for the Unit Test Project and class.<span style="mso-spacerun: yes">  </span>I
like to name my Unit Test projects the same as my database project, followed by “Tests”
or “UnitTests”.<span style="mso-spacerun: yes">  </span>If this is a new Database
Unit Test Project, the <b style="mso-bidi-font-weight: normal">Database Unit Test
Configuration</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> dialog
displays.<br /><a href="http://www.davidgiard.com/content/binary/DD03_Fig2.jpg" target="_pix"><img style="WIDTH: 652px; HEIGHT: 459px" border="0" src="http://www.davidgiard.com/content/binary/DD03_Fig2.jpg" width="772" height="290" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
2</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">5.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The <b style="mso-bidi-font-weight: normal">Database
Unit Test Configuration</b> dialog allows you to specify what you want to occur when
you run these unit tests.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">The
dialog is organized into the following sections.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Database
connections</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <span style="FONT: 7pt 'Times New Roman'">                                                               </span>
                <font size="3" face="Calibri">i.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </font>
            </span>
          </span>
          <font color="#000000" size="3" face="Calibri">Execute
unit tests using the following data connection<br />
This is the database against which tests will run.<span style="mso-spacerun: yes">  </span>Typically
I set this to my Development or QA database.</font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <span style="FONT: 7pt 'Times New Roman'">                                                             </span>
                <font size="3" face="Calibri">ii.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </font>
            </span>
          </span>
          <font color="#000000" size="3" face="Calibri">Use
a secondary data connection to validate unit tests<br />
You may specify a different database to validate the syntax of your unit tests and
test that all the objects you refer to exist.<span style="mso-spacerun: yes">  </span>I
can only think this might be good if you are writing tests while disconnected from
your testing database, but I never set this option.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font size="3" face="Calibri">Deployment</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <span style="FONT: 7pt 'Times New Roman'">                                                               </span>
                <font size="3" face="Calibri">i.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </font>
            </span>
          </span>
          <font color="#000000" size="3" face="Calibri">Automatically
deploy the database project before unit tests are run<br />
To save manual steps, you may wish to check this box and deploy the database project
to the database each time you run your unit tests.<span style="mso-spacerun: yes">  </span>This
slows down the testing step so I do not select this option.<span style="mso-spacerun: yes">  </span>I
prefer to deploy my changes once; then run my unit tests – sometimes several times.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Database
state</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <span style="FONT: 7pt 'Times New Roman'">                                                               </span>
                <font size="3" face="Calibri">i.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </font>
            </span>
          </span>
          <font color="#000000" size="3" face="Calibri">Generate
Test data before Unit tests are run<br />
It is often useful to populate your database with some test data prior to your test
run.<span style="mso-spacerun: yes">  </span>Use this button to do this.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">6.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">After
creating your unit tests, you need to modify each one and specify what you are testing.<span style="mso-spacerun: yes">  </span>Open
the Solution Explorer (<b style="mso-bidi-font-weight: normal">View | Solution Explorer</b></font>
              <font size="3">).</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">7.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Double-click
the unit test class to open it in the unit test designer.</font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <span style="mso-spacerun: yes">  </span>
                <br />
                <br />
                <span style="mso-spacerun: yes">    </span>
                <b style="mso-bidi-font-weight: normal">Figure
2</b>
              </font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">8.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The
Unit Test Designer contains some controls and two panes as described below.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">A
class can contain multiple tests.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">The
first control is a dropdown that allows you to select which test you are designing.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">To
the right of the Test Name dropdown is another dropdown that allows you to specify
what part of the test you are writing.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">You
can choose between the test itself, the “Pre-test” (which runs before the test is
executed) and the “Post-test” (which runs after the test has completed – successfully
or unsuccessfully).<br /><a href="http://www.davidgiard.com/content/binary/DD03_Fig3.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD03_Fig3.jpg" /></a><br /><span style="mso-spacerun: yes">   </span><b style="mso-bidi-font-weight: normal">Figure
3</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Further
to the right are three buttons that allow you to add a new test or to delete or rename
the currently active test.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">d.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Below
the controls is the test editor.<span style="mso-spacerun: yes">  </span>This
is where you will write your test.<span style="mso-spacerun: yes">  </span>You
will write your test in T-SQL and Data Dude provides some stub code to get you started.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Write
SQL statements that call your stored procedure and return one or more results.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">e.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Below
the test editor is the Test Conditions pane.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">It
is here that you enter your assertions.</font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <span style="mso-spacerun: yes">  </span>
                <br />
                <a href="http://www.davidgiard.com/content/binary/DD03_Fig4.jpg" target="_pix">
                  <img border="0" src="http://www.davidgiard.com/content/binary/DD03_Fig4.jpg" />
                </a>
                <br />
                <span style="mso-spacerun: yes">    </span>
                <b style="mso-bidi-font-weight: normal">Figure
4</b>
              </font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <span style="FONT: 7pt 'Times New Roman'">                                                               </span>
                <font size="3" face="Calibri">i.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">You
can test for a given result set having 0 rows, 1 or more rows, or an exact number
of rows.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <span style="FONT: 7pt 'Times New Roman'">                                                             </span>
                <font size="3" face="Calibri">ii.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">You
can also test if a specific column and row in a given result set evaluates to a given
value.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <span style="FONT: 7pt 'Times New Roman'">                                                            </span>
                <font size="3" face="Calibri">iii.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Click
the “+” button to add new assertions.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Highlight
an existing assertion row and edit the row or click the “x” button to remove the assertion.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <span style="FONT: 7pt 'Times New Roman'">                                                           </span>
                <font size="3" face="Calibri">iv.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Use
the properties window to modify properties of the assertion.<span style="mso-spacerun: yes">  </span>Many
assertions are based on a given resultset.<span style="mso-spacerun: yes">  </span>When
I first started writing unit tests, I found it difficult to determine which resultset
was which.<span style="mso-spacerun: yes">  </span>Basically, any line in your
SQL script that begins with the word “SELECT” creates a resultset.<span style="mso-spacerun: yes">  </span>Each
resultset is numbered, beginning with 1, in the order it is created in your script.<span style="mso-spacerun: yes">  </span>I
sometimes find it useful to copy the SQL code and paste it into SQL Management Studio
query window and run it.<span style="mso-spacerun: yes">  </span>Each resultset
then appears in a separate grid in the Results pane.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Looking
at these grids allows me to more easily see a sample result set and in what order
they are created.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">f.</font>
                <span style="FONT: 7pt 'Times New Roman'">        </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">You
run your database unit tests the same ways you run any MS Test unit test.<span style="mso-spacerun: yes">  </span>One
way to run the tests is to open the Test List Editor (Test | Windows | Test List Window),
check the tests you want to run, and click the <b style="mso-bidi-font-weight: normal">Run
Checked Test</b> toolbar button.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Tests
in which all assertions prove true are passed; all others are failed.</font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">Using Data Dude, you can extend your
unit tests to cover your database objects and, therefore, improve the overall quality
and maintainability of your code.</font>
        </p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf" />
      </body>
      <title>Data Dude tutorial 4 - Writing Database Unit Tests</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/14/DataDudeTutorial4WritingDatabaseUnitTests.aspx</link>
      <pubDate>Thu, 14 Aug 2008 13:56:47 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Writing Unit Tests is an essential step in
developing robust, maintainable code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Unit
Tests increase quality and mitigate the risk of future code changes.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;However,
relatively few developers take the time to write unit tests for their stored procedures. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;The
primary reason for this is that few tools exist to test stored procedures.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Microsoft Visual Studio Team System 2008 Database
Edition (aka “Data Dude”) provides tools to help developers write unit tests against
SQL Server stored procedures.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The tool
integrates with MSTest, wich is a testing framework many developers are already using
for their other unit tests.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In order to write unit tests for your stored
procedures, those stored procedures must be in a database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;For
information on how to create a database project from a SQL Server database see: &lt;/font&gt;&lt;a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx"&gt;&lt;font color=#0000ff size=3 face=Calibri&gt;http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000 size=3 face=Calibri&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;This document describes how to create a database
unit test.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Launch
Visual Studio and open your Database Project. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Open
the Schema View.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Select &lt;b style="mso-bidi-font-weight: normal"&gt;View
| Schema View&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Right-click
a stored procedure and select &lt;b style="mso-bidi-font-weight: normal"&gt;Create Unit
Test&lt;/b&gt; from the context menu.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;Create
Unit Tests&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; dialog
displays.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD03_Fig1.jpg" target=_pix&gt;&lt;img style="WIDTH: 544px; HEIGHT: 418px" border=0 src="http://www.davidgiard.com/content/binary/DD03_Fig1.jpg" width=772 height=290&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
1&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;4.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Check
the checkboxes next to all the stored procedures for which you wish to create unit
tests.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Select the .Net language (Visual
Basic .Net or C#) in which you want the automatic code to be generated.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
won’t be modifying this code so it isn’t that important, but I tend to keep all my
code in the same language, so you may as well choose your favorite language here.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Enter
a meaningful name for the Unit Test Project and class.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
like to name my Unit Test projects the same as my database project, followed by “Tests”
or “UnitTests”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If this is a new Database
Unit Test Project, the &lt;b style="mso-bidi-font-weight: normal"&gt;Database Unit Test
Configuration&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; dialog
displays.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD03_Fig2.jpg" target=_pix&gt;&lt;img style="WIDTH: 652px; HEIGHT: 459px" border=0 src="http://www.davidgiard.com/content/binary/DD03_Fig2.jpg" width=772 height=290&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
2&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;5.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;Database
Unit Test Configuration&lt;/b&gt; dialog allows you to specify what you want to occur when
you run these unit tests.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;The
dialog is organized into the following sections.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Database
connections&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;i.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font color=#000000 size=3 face=Calibri&gt;Execute
unit tests using the following data connection&lt;br&gt;
This is the database against which tests will run.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Typically
I set this to my Development or QA database.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;ii.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font color=#000000 size=3 face=Calibri&gt;Use
a secondary data connection to validate unit tests&lt;br&gt;
You may specify a different database to validate the syntax of your unit tests and
test that all the objects you refer to exist.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
can only think this might be good if you are writing tests while disconnected from
your testing database, but I never set this option.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Deployment&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;i.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font color=#000000 size=3 face=Calibri&gt;Automatically
deploy the database project before unit tests are run&lt;br&gt;
To save manual steps, you may wish to check this box and deploy the database project
to the database each time you run your unit tests.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
slows down the testing step so I do not select this option.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
prefer to deploy my changes once; then run my unit tests – sometimes several times.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Database
state&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;i.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font color=#000000 size=3 face=Calibri&gt;Generate
Test data before Unit tests are run&lt;br&gt;
It is often useful to populate your database with some test data prior to your test
run.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Use this button to do this.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;6.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;After
creating your unit tests, you need to modify each one and specify what you are testing.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Open
the Solution Explorer (&lt;b style="mso-bidi-font-weight: normal"&gt;View | Solution Explorer&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;).&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;7.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Double-click
the unit test class to open it in the unit test designer.&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
2&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;8.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The
Unit Test Designer contains some controls and two panes as described below.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;A
class can contain multiple tests.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;The
first control is a dropdown that allows you to select which test you are designing.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;To
the right of the Test Name dropdown is another dropdown that allows you to specify
what part of the test you are writing.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;You
can choose between the test itself, the “Pre-test” (which runs before the test is
executed) and the “Post-test” (which runs after the test has completed – successfully
or unsuccessfully).&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD03_Fig3.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD03_Fig3.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
3&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Further
to the right are three buttons that allow you to add a new test or to delete or rename
the currently active test.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;d.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Below
the controls is the test editor.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
is where you will write your test.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
will write your test in T-SQL and Data Dude provides some stub code to get you started.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Write
SQL statements that call your stored procedure and return one or more results.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;e.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Below
the test editor is the Test Conditions pane.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;It
is here that you enter your assertions.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD03_Fig4.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD03_Fig4.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
4&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;i.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;You
can test for a given result set having 0 rows, 1 or more rows, or an exact number
of rows.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;ii.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;You
can also test if a specific column and row in a given result set evaluates to a given
value.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;iii.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Click
the “+” button to add new assertions.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Highlight
an existing assertion row and edit the row or click the “x” button to remove the assertion.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -1.5in; MARGIN: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;font size=3 face=Calibri&gt;iv.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Use
the properties window to modify properties of the assertion.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Many
assertions are based on a given resultset.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;When
I first started writing unit tests, I found it difficult to determine which resultset
was which.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Basically, any line in your
SQL script that begins with the word “SELECT” creates a resultset.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Each
resultset is numbered, beginning with 1, in the order it is created in your script.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
sometimes find it useful to copy the SQL code and paste it into SQL Management Studio
query window and run it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Each resultset
then appears in a separate grid in the Results pane.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Looking
at these grids allows me to more easily see a sample result set and in what order
they are created.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;f.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;You
run your database unit tests the same ways you run any MS Test unit test.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;One
way to run the tests is to open the Test List Editor (Test | Windows | Test List Window),
check the tests you want to run, and click the &lt;b style="mso-bidi-font-weight: normal"&gt;Run
Checked Test&lt;/b&gt; toolbar button.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Tests
in which all assertions prove true are passed; all others are failed.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Using Data Dude, you can extend your unit
tests to cover your database objects and, therefore, improve the overall quality and
maintainability of your code.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,8672e98b-0e16-45ba-b7d5-59ab9dd0a1cf.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=e8910d69-6570-4257-b79f-2ffd9e1b4a9e</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,e8910d69-6570-4257-b79f-2ffd9e1b4a9e.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,e8910d69-6570-4257-b79f-2ffd9e1b4a9e.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e8910d69-6570-4257-b79f-2ffd9e1b4a9e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Microsoft Visual Studio
Team System 2008 Database Edition (aka “Data Dude”) provides tools for managing and
deploying SQL Server databases.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In our </font>
          <a href="http://www.davidgiard.com/2008/08/12/DataDudeTutorial2UsingSchemaCompareToolToUpdateADatabaseProject.aspx">
            <font color="#0000ff" size="3" face="Calibri">last
tutorial</font>
          </a>
          <font color="#000000" size="3" face="Calibri">, we described how
a database developer would use the Schema Compare tool to update a database project
with changes to a SQL Server database.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">This article describes how
to use the Schema Compare tool to push those changes out to a different SQL Server
database.<span style="mso-spacerun: yes">  </span>There are two scenarios where
you would do this.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">In Scenario 1, a developer
has a local copy of the development database and wishes to get the latest updates
to the database.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In Scenario 2, a database administrator
(DBA) or build master who is charged with migrating database changes from one environment
to the next.<span style="mso-spacerun: yes">  </span>Just as .Net and web code
gets regularly migrated from a development environment to a QA or Production environment,
database object code must also be migrated, and that migration generally must be kept
in sync with all code that depends on those database objects.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">We start this process by launching Visual
Studio and opening the database project.<span style="mso-spacerun: yes">  </span>If
a source code repository such as TFS is used, we need to get the latest code from
the repository.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">The database to which we wish to write
the changes is known to Data Dude as the “target database”.<span style="mso-spacerun: yes">  </span>We
need to make sure that a connection exists in Visual Studio to the target database.<span style="mso-spacerun: yes">  </span>This
is a one-time step and you can use the Server Explorer (<b style="mso-bidi-font-weight: normal">View
| Server Explorer</b>) to create a connection.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">The following steps describe how to
propagate changes to the database.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Launch
Visual Studio and open the database project.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Get
the latest source code from your source code repository.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">From
the Visual Studio menu, select <b style="mso-bidi-font-weight: normal">Data | Schema
Compare | New Schema Compare</b>.<span style="mso-spacerun: yes">  </span>The <b style="mso-bidi-font-weight: normal">New
Schema Compare</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> dialog
displays.<br /><a href="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" target="_pix"><img style="WIDTH: 652px; HEIGHT: 185px" border="0" src="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" width="772" height="290" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
1</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Under <b style="mso-bidi-font-weight: normal">Source
Schema</b>, select the <b style="mso-bidi-font-weight: normal">Project </b></font>
              <font size="3">radio
button and select your database project from the dropdown list.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">4.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Under <b style="mso-bidi-font-weight: normal">Target
Schema</b>, select the <b style="mso-bidi-font-weight: normal">Database</b></font>
              <font size="3"> radio
button and select the connection to your database from dropdown list.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">5.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Click
the <b style="mso-bidi-font-weight: normal">OK</b> button to display the <b style="mso-bidi-font-weight: normal">Schema
Compare</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> window.<br /><a href="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" target="_pix"><img style="WIDTH: 671px; HEIGHT: 583px" border="0" src="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" width="726" height="677" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
2</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">6.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The <b style="mso-bidi-font-weight: normal">Schema
Compare</b> window lists every object that exists in either the database or the database
project.<span style="mso-spacerun: yes">  </span>The objects are grouped in folders
by object type (Tables, views, stored procedures, etc.)<span style="mso-spacerun: yes">  </span>You
can expand or collapse a folder to view or hide objects of that type.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">The
important column is “Update Action” which describes what will happen if you write
the updates to the target.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Objects
that exist in the source (the project) but not in the target (the database) were likely
recently added after the last synchronization.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">By
default, the Update Action will be “Create” meaning the object will be created in
the target database.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font size="3" face="Calibri">Objects
that exist in both the source and the target will have an Update Action of “Update”
if they have been modified in the database since the last synchronization or “Skip”
if they have not.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Objects
that exist in the destination (the database) but not in the source (the project) were
likely dropped after the last synchronization. By default, the Update Action will
be “Drop” meaning the object will be removed from the database.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">7.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">On
a database with many objects, it is useful to view only the objects that have changed
since the last synchronization.<span style="mso-spacerun: yes">  </span>To do
this, click the <b style="mso-bidi-font-weight: normal">Filter</b> toolbar button
and select <b style="mso-bidi-font-weight: normal">Non Skip Objects</b></font>
              <font size="3">.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  
<br /><a href="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" /></a><br />
    <strong>Figure 3</strong></font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">8.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">If
you wish, you can modify the Update Action on objects by selecting the dropdown in
the “Update Action” column.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Some
actions are grayed out because Data Dude will not allow you to perform any action
that would violate referential integrity rules.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">9.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">After
you have set the “Update Action” of every object appropriately, you have a couple
options.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">You
can migrate your changes immediately to the target database by clicking the “Write
Updates” toolbar button.<span style="mso-spacerun: yes">  </span>Click <b style="mso-bidi-font-weight: normal">Yes</b></font>
              <font size="3"> at
the confirmation to write the updates to the database project.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Alternatively,
you can export your changes to a SQL script by clicking the <b style="mso-bidi-font-weight: normal">Export
To Editor</b> toolbar button.<span style="mso-spacerun: yes">  </span>This will
create a single text file containing SQL script that you can run from a query window
of <i style="mso-bidi-font-style: normal">SQL Server Management Studio</i>.<span style="mso-spacerun: yes">  </span>This
is useful if you need to make changes to the script prior to executing.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">I
have used this technique when my database contains views or stored procedures that
refer to remote servers and I want to modify the name of the server before migrating
the object.</font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">Alternatively, you can deploy changes
from a database project to a database by “Deploying” the project (select <span class="QuoteChar"><b style="mso-bidi-font-weight: normal"><span style="FONT-STYLE: normal; mso-bidi-font-style: italic">Build
| Deploy Solution</span></b></span>).<span style="mso-spacerun: yes">  </span>This
deploys your changes using the settings found on the <b style="mso-bidi-font-weight: normal">Build</b> tab
of the project properties page.<span style="mso-spacerun: yes">  </span>This
method requires fewer steps, but it is less flexible than the method described above.<span style="mso-spacerun: yes">  </span>In
particular, it does not allow you to select which objects are deployed or export and
modify the script of database changes.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In the next article, we will discuss
how to use Data Dude to write Unit Tests against SQL Server stored procedures.</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=e8910d69-6570-4257-b79f-2ffd9e1b4a9e" />
      </body>
      <title>Data Dude tutorial 3 - Using Schema Compare tool to deploy database changes</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,e8910d69-6570-4257-b79f-2ffd9e1b4a9e.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/13/DataDudeTutorial3UsingSchemaCompareToolToDeployDatabaseChanges.aspx</link>
      <pubDate>Wed, 13 Aug 2008 11:46:54 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Microsoft Visual Studio Team System
2008 Database Edition (aka “Data Dude”) provides tools for managing and deploying
SQL Server databases.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In our &lt;/font&gt;&lt;a href="http://www.davidgiard.com/2008/08/12/DataDudeTutorial2UsingSchemaCompareToolToUpdateADatabaseProject.aspx"&gt;&lt;font color=#0000ff size=3 face=Calibri&gt;last
tutorial&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000 size=3 face=Calibri&gt;, we described how a database
developer would use the Schema Compare tool to update a database project with changes
to a SQL Server database.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;This article describes how to
use the Schema Compare tool to push those changes out to a different SQL Server database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;There
are two scenarios where you would do this.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;In Scenario 1, a developer has
a local copy of the development database and wishes to get the latest updates to the
database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In Scenario 2, a database administrator (DBA)
or build master who is charged with migrating database changes from one environment
to the next.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Just as .Net and web code
gets regularly migrated from a development environment to a QA or Production environment,
database object code must also be migrated, and that migration generally must be kept
in sync with all code that depends on those database objects.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;We start this process by launching Visual
Studio and opening the database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
a source code repository such as TFS is used, we need to get the latest code from
the repository.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;The database to which we wish to write the
changes is known to Data Dude as the “target database”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;We
need to make sure that a connection exists in Visual Studio to the target database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
is a one-time step and you can use the Server Explorer (&lt;b style="mso-bidi-font-weight: normal"&gt;View
| Server Explorer&lt;/b&gt;) to create a connection.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;The following steps describe how to propagate
changes to the database.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Launch
Visual Studio and open the database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Get
the latest source code from your source code repository.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;From
the Visual Studio menu, select &lt;b style="mso-bidi-font-weight: normal"&gt;Data | Schema
Compare | New Schema Compare&lt;/b&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;New
Schema Compare&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; dialog
displays.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" target=_pix&gt;&lt;img style="WIDTH: 652px; HEIGHT: 185px" border=0 src="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" width=772 height=290&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
1&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Under &lt;b style="mso-bidi-font-weight: normal"&gt;Source
Schema&lt;/b&gt;, select the &lt;b style="mso-bidi-font-weight: normal"&gt;Project &lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;radio
button and select your database project from the dropdown list.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;4.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Under &lt;b style="mso-bidi-font-weight: normal"&gt;Target
Schema&lt;/b&gt;, select the &lt;b style="mso-bidi-font-weight: normal"&gt;Database&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; radio
button and select the connection to your database from dropdown list.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;5.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Click
the &lt;b style="mso-bidi-font-weight: normal"&gt;OK&lt;/b&gt; button to display the &lt;b style="mso-bidi-font-weight: normal"&gt;Schema
Compare&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; window.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" target=_pix&gt;&lt;img style="WIDTH: 671px; HEIGHT: 583px" border=0 src="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" width=726 height=677&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
2&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;6.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;Schema
Compare&lt;/b&gt; window lists every object that exists in either the database or the database
project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The objects are grouped in folders
by object type (Tables, views, stored procedures, etc.)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
can expand or collapse a folder to view or hide objects of that type.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;The
important column is “Update Action” which describes what will happen if you write
the updates to the target.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Objects
that exist in the source (the project) but not in the target (the database) were likely
recently added after the last synchronization.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;By
default, the Update Action will be “Create” meaning the object will be created in
the target database.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Objects
that exist in both the source and the target will have an Update Action of “Update”
if they have been modified in the database since the last synchronization or “Skip”
if they have not.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Objects
that exist in the destination (the database) but not in the source (the project) were
likely dropped after the last synchronization. By default, the Update Action will
be “Drop” meaning the object will be removed from the database.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;7.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;On
a database with many objects, it is useful to view only the objects that have changed
since the last synchronization.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To do
this, click the &lt;b style="mso-bidi-font-weight: normal"&gt;Filter&lt;/b&gt; toolbar button
and select &lt;b style="mso-bidi-font-weight: normal"&gt;Non Skip Objects&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; 
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD02_Filter.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Figure 3&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;8.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;If
you wish, you can modify the Update Action on objects by selecting the dropdown in
the “Update Action” column.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Some
actions are grayed out because Data Dude will not allow you to perform any action
that would violate referential integrity rules.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;9.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;After
you have set the “Update Action” of every object appropriately, you have a couple
options.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;You
can migrate your changes immediately to the target database by clicking the “Write
Updates” toolbar button.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Click &lt;b style="mso-bidi-font-weight: normal"&gt;Yes&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; at
the confirmation to write the updates to the database project.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Alternatively,
you can export your changes to a SQL script by clicking the &lt;b style="mso-bidi-font-weight: normal"&gt;Export
To Editor&lt;/b&gt; toolbar button.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This will
create a single text file containing SQL script that you can run from a query window
of &lt;i style="mso-bidi-font-style: normal"&gt;SQL Server Management Studio&lt;/i&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
is useful if you need to make changes to the script prior to executing.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;I
have used this technique when my database contains views or stored procedures that
refer to remote servers and I want to modify the name of the server before migrating
the object.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Alternatively, you can deploy changes from
a database project to a database by “Deploying” the project (select &lt;span class=QuoteChar&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Build
| Deploy Solution&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
deploys your changes using the settings found on the &lt;b style="mso-bidi-font-weight: normal"&gt;Build&lt;/b&gt; tab
of the project properties page.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This
method requires fewer steps, but it is less flexible than the method described above.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In
particular, it does not allow you to select which objects are deployed or export and
modify the script of database changes.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In the next article, we will discuss how to
use Data Dude to write Unit Tests against SQL Server stored procedures.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=e8910d69-6570-4257-b79f-2ffd9e1b4a9e" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,e8910d69-6570-4257-b79f-2ffd9e1b4a9e.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=5f9a973b-417f-4010-84db-b8a783d8b618</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,5f9a973b-417f-4010-84db-b8a783d8b618.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,5f9a973b-417f-4010-84db-b8a783d8b618.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5f9a973b-417f-4010-84db-b8a783d8b618</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p class="MsoNormal">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Microsoft Visual Studio
Team System 2008 Database Edition (aka “Data Dude”) provides tools for managing and
deploying SQL Server databases.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In our </font>
          <a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx">
            <font size="3" face="Calibri">last
tutorial</font>
          </a>
          <font color="#000000" size="3" face="Calibri">, we described how
to create a new database project based on an existing SQL Server database.<span style="mso-spacerun: yes">  </span>As
the source database changes, you will want to update the database project to reflect
those changes.<span style="mso-spacerun: yes">  </span>This article describes
how to use the Schema Compare tool to import database schema changes into your database
project.<span style="mso-spacerun: yes">  </span>The steps in this article are
typically performed by a database administrator (DBA) or database developer who is
charged with creating tables, views, functions and stored procedures.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">The Schema Compare tool
can be used to display and manage differences between two databases, between two database
projects, or between a database and a database project.<span style="mso-spacerun: yes">  </span>Most
of the time, I use it to compare a database with a database project.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">After making a change to a database
schema (for example, adding a new table or adding a new column to a table), use the
Schema Compare tool as described below to update an existing database project with
these changes.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Launch
Visual Studio and open your Database Project. (For info on how to create a database
project from a SQL Server database see: </font>
          </font>
          <a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx">
            <font size="3" face="Calibri">http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx</font>
          </a>
          <font color="#000000" size="3" face="Calibri"> )</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">From
the Visual Studio menu, select <b style="mso-bidi-font-weight: normal">Data | Schema
Compare | New Schema Compare</b>.<span style="mso-spacerun: yes">  </span>The <b style="mso-bidi-font-weight: normal">New
Schema Compare</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> dialog
displays.<br /><a href="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" width="613" height="255" /></a><br /><span style="mso-spacerun: yes">    </span><b style="mso-bidi-font-weight: normal">Figure
1</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Under <b style="mso-bidi-font-weight: normal">Source
Schema</b>, select the <b style="mso-bidi-font-weight: normal">Database</b></font>
              <font size="3"> radio
button and select the connection to your database from dropdown list.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">4.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Under <b style="mso-bidi-font-weight: normal">Target
Schema</b>, select the <b style="mso-bidi-font-weight: normal">Project </b></font>
              <font size="3">radio
button and select your database project from the dropdown list.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">5.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3">
              <font face="Calibri">Click
the <b style="mso-bidi-font-weight: normal">OK</b> button to display the <b style="mso-bidi-font-weight: normal">Schema
Compare</b></font>
            </font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri"> window.<br /><a href="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" target="_pix"><img style="WIDTH: 670px; HEIGHT: 379px" border="0" src="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" width="1028" height="624" /><br /><span style="mso-spacerun: yes"></span></a>    <b style="mso-bidi-font-weight: normal">Figure 2</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">6.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The <b style="mso-bidi-font-weight: normal">Schema
Compare</b> window lists every object that exists in either the database or the database
project.<span style="mso-spacerun: yes">  </span>The objects are grouped in folders
by object type (Tables, views, stored procedures, etc.)<span style="mso-spacerun: yes">  </span>You
can expand or collapse a folder to view or hide objects of that type.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">The
important column is “Update Action” which describes what will happen if you write
the updates to the target.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Objects
that exist in the source (the database) but not in the target (the project) were likely
added to the database after the last synchronization.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">By
default, the Update Action will be “Create” meaning the object will be created in
the database project.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font size="3" face="Calibri">Objects
that exist in both the source and the target will have an Update Action of “Update”
if they have been modified in the database since the last synchronization or “Skip”
if they have not.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">c.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Objects
that exist in the destination (the project) but not in the source (the database) were
likely dropped from the database after the last synchronization. By default, the Update
Action will be “Drop” meaning the object will be removed from the database project.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">7.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">If
you are updating your database project frequently, most of the objects will be unchanged
and marked “Skip”.<span style="mso-spacerun: yes">  </span>On a database with
many objects, it is useful to view only the objects that have changed since the last
synchronization.<span style="mso-spacerun: yes">  </span>To do this, click the <b style="mso-bidi-font-weight: normal">Filter</b> toolbar
button and select <b style="mso-bidi-font-weight: normal">Non Skip Objects</b></font>
              <font size="3">. </font>
              <span style="mso-spacerun: yes">
                <font size="3"> <br /><a href="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" /></a><br />
    <strong>Figure 3</strong></font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">8.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">At
this point, you can view differences and you may wish to modify the Update Action
of some objects.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">a.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">If
you click on an object row in the <b style="mso-bidi-font-weight: normal">Schema Compare</b> window,
the SQL definition code of both the source and destination version appears in the <b style="mso-bidi-font-weight: normal">Object
Definition</b> window.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Any
differences between the two versions will be highlighted (changed lines in darker
blue; new lines in darker green).</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">b.</font>
                <span style="FONT: 7pt 'Times New Roman'">      </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">If
you like, you can modify the Update Action any object by selecting the dropdown in
the “Update Action” column.<span style="mso-spacerun: yes">  </span>Some actions
are grayed out because Data Dude will not allow you to perform any action that would
violate referential integrity rules.<span style="mso-spacerun: yes">  </span>If
several developers are sharing the same development database, you may wish to skip
those objects on which you are not working.<span style="mso-spacerun: yes">  </span>You
may also decide that some objects are ready to share with the rest of the team and
others are not fully tested and should be skipped.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">It
is possible to change the Update Action of every object of a given type by right-clicking
the type folder and selecting the desired action to apply to all objects of that type.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">9.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">After
you have set the “Update Action” of every object appropriately, you can migrate your
changes to the database project by clicking the <strong>Write Updates</strong> toolbar
button.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Click Yes
at the confirmation to write the updates to the database project.<br /><a href="http://www.davidgiard.com/content/binary/DD02_WriteUpdates.jpg" target="_pix"><img border="0" src="http://www.davidgiard.com/content/binary/DD02_WriteUpdates.jpg" /></a><br />
    <strong>Figure 4</strong></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">10.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </span>
            </span>
            <font size="3" face="Calibri">If
you are using a source control repository, such as TFS, you will want to check in
your changes.</font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In the next article, we will discuss
how to use the Schema Compare tool to write changes to a new database environment.</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=5f9a973b-417f-4010-84db-b8a783d8b618" />
      </body>
      <title>Data Dude tutorial 2 - Using Schema Compare tool to update a database project</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,5f9a973b-417f-4010-84db-b8a783d8b618.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/12/DataDudeTutorial2UsingSchemaCompareToolToUpdateADatabaseProject.aspx</link>
      <pubDate>Tue, 12 Aug 2008 12:40:04 GMT</pubDate>
      <description>&lt;p class=MsoNormal&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Microsoft Visual Studio Team System
2008 Database Edition (aka “Data Dude”) provides tools for managing and deploying
SQL Server databases.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In our &lt;/font&gt;&lt;a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx"&gt;&lt;font size=3 face=Calibri&gt;last
tutorial&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000 size=3 face=Calibri&gt;, we described how to create
a new database project based on an existing SQL Server database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;As
the source database changes, you will want to update the database project to reflect
those changes.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This article describes
how to use the Schema Compare tool to import database schema changes into your database
project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The steps in this article are
typically performed by a database administrator (DBA) or database developer who is
charged with creating tables, views, functions and stored procedures.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;The Schema Compare tool can be
used to display and manage differences between two databases, between two database
projects, or between a database and a database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Most
of the time, I use it to compare a database with a database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;After making a change to a database schema
(for example, adding a new table or adding a new column to a table), use the Schema
Compare tool as described below to update an existing database project with these
changes.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Launch
Visual Studio and open your Database Project. (For info on how to create a database
project from a SQL Server database see: &lt;/font&gt;&lt;/font&gt;&lt;a href="http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx"&gt;&lt;font size=3 face=Calibri&gt;http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000 size=3 face=Calibri&gt; )&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;From
the Visual Studio menu, select &lt;b style="mso-bidi-font-weight: normal"&gt;Data | Schema
Compare | New Schema Compare&lt;/b&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;New
Schema Compare&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; dialog
displays.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD02_Fig1.jpg" width=613 height=255&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
1&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Under &lt;b style="mso-bidi-font-weight: normal"&gt;Source
Schema&lt;/b&gt;, select the &lt;b style="mso-bidi-font-weight: normal"&gt;Database&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt; radio
button and select the connection to your database from dropdown list.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;4.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Under &lt;b style="mso-bidi-font-weight: normal"&gt;Target
Schema&lt;/b&gt;, select the &lt;b style="mso-bidi-font-weight: normal"&gt;Project &lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;radio
button and select your database project from the dropdown list.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;5.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Click
the &lt;b style="mso-bidi-font-weight: normal"&gt;OK&lt;/b&gt; button to display the &lt;b style="mso-bidi-font-weight: normal"&gt;Schema
Compare&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt; window.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" target=_pix&gt;&lt;img style="WIDTH: 670px; HEIGHT: 379px" border=0 src="http://www.davidgiard.com/content/binary/DD02_Fig2.jpg" width=1028 height=624&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;
&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure 2&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;6.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;Schema
Compare&lt;/b&gt; window lists every object that exists in either the database or the database
project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The objects are grouped in folders
by object type (Tables, views, stored procedures, etc.)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
can expand or collapse a folder to view or hide objects of that type.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;The
important column is “Update Action” which describes what will happen if you write
the updates to the target.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Objects
that exist in the source (the database) but not in the target (the project) were likely
added to the database after the last synchronization.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;By
default, the Update Action will be “Create” meaning the object will be created in
the database project.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Objects
that exist in both the source and the target will have an Update Action of “Update”
if they have been modified in the database since the last synchronization or “Skip”
if they have not.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;c.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Objects
that exist in the destination (the project) but not in the source (the database) were
likely dropped from the database after the last synchronization. By default, the Update
Action will be “Drop” meaning the object will be removed from the database project.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;7.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;If
you are updating your database project frequently, most of the objects will be unchanged
and marked “Skip”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;On a database with
many objects, it is useful to view only the objects that have changed since the last
synchronization.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To do this, click the &lt;b style="mso-bidi-font-weight: normal"&gt;Filter&lt;/b&gt; toolbar
button and select &lt;b style="mso-bidi-font-weight: normal"&gt;Non Skip Objects&lt;/b&gt;&lt;/font&gt;&lt;font size=3&gt;.&amp;nbsp;&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp;&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_Filter.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD02_Filter.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Figure 3&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;8.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;At
this point, you can view differences and you may wish to modify the Update Action
of some objects.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;If
you click on an object row in the &lt;b style="mso-bidi-font-weight: normal"&gt;Schema Compare&lt;/b&gt; window,
the SQL definition code of both the source and destination version appears in the &lt;b style="mso-bidi-font-weight: normal"&gt;Object
Definition&lt;/b&gt; window.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Any
differences between the two versions will be highlighted (changed lines in darker
blue; new lines in darker green).&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;b.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;If
you like, you can modify the Update Action any object by selecting the dropdown in
the “Update Action” column.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Some actions
are grayed out because Data Dude will not allow you to perform any action that would
violate referential integrity rules.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
several developers are sharing the same development database, you may wish to skip
those objects on which you are not working.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
may also decide that some objects are ready to share with the rest of the team and
others are not fully tested and should be skipped.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;It
is possible to change the Update Action of every object of a given type by right-clicking
the type folder and selecting the desired action to apply to all objects of that type.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;9.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;After
you have set the “Update Action” of every object appropriately, you can migrate your
changes to the database project by clicking the &lt;strong&gt;Write Updates&lt;/strong&gt; toolbar
button.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Click Yes
at the confirmation to write the updates to the database project.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD02_WriteUpdates.jpg" target=_pix&gt;&lt;img border=0 src="http://www.davidgiard.com/content/binary/DD02_WriteUpdates.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Figure 4&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;10.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;If
you are using a source control repository, such as TFS, you will want to check in
your changes.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In the next article, we will discuss how to
use the Schema Compare tool to write changes to a new database environment.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=5f9a973b-417f-4010-84db-b8a783d8b618" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,5f9a973b-417f-4010-84db-b8a783d8b618.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=30b4fa79-a994-49f0-abe4-d644c77b8c65</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,30b4fa79-a994-49f0-abe4-d644c77b8c65.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,30b4fa79-a994-49f0-abe4-d644c77b8c65.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=30b4fa79-a994-49f0-abe4-d644c77b8c65</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Microsoft Visual Studio
Team System 2008 Database Edition (aka “Data Dude”) provides tools for managing and
deploying SQL Server databases.<span style="mso-spacerun: yes">  </span>In order
to use Data Dude to manage an existing SQL Server database, the first step is to create
a database project.<span style="mso-spacerun: yes">  </span></font>
            </font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">There are a couple key points you will
need to know before using Data<span style="mso-spacerun: yes">  </span>Dude.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The
current version of Data Dude only works on SQL Server 2000 and SQL Server 2005.<span style="mso-spacerun: yes">  </span>Visual
Studio 2008 Service Pack 1 should provide support for SQL Server 2008.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">I
will describe an example using SQL Server 2005.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The
validation engine in Data Dude requires that you install either SQL Server or SQL
Express on the same machine on which Data Dude is installed.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l1 level1 lfo1" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">You
must grant “Create database” rights in this database engine to the currently logged-in
user.</font>
          </font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">Now, let’s discuss how to create a database
project to manage an existing SQL Server 2005 database.</font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpFirst">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">1.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">Open
Visual Studio.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">2.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Select <strong>File
| New Project…</strong> The <strong>New Project</strong> dialog displays</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">3.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Under <strong>Project
Type</strong>, select Database <em>Projects\Microsoft SQL Server</em></font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">4.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Under <strong>Templates</strong>,
select <em>SQL Server 2005 Wizard</em>.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">5.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">Enter
a meaningful name and location for this project.</font>
          </font>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <span style="mso-spacerun: yes">  </span>
                <br />
Typically, my databases have names like “AdventureWorks_Dev” and “AdventureWorks_QA”
which describe both the data and the environment to which the data belongs.<span style="mso-spacerun: yes">  </span>Because
a single database project is used for all environments, I name my database project
to describe the data and follow it with “DB” to make it obvious it is a database project.<span style="mso-spacerun: yes">  </span>In
the above example, I would name my database project “AdventureWorksDb”.<span style="mso-spacerun: yes">  </span>In
this exercise, I’ll create a project named “TestDB”.<br /><span style="mso-spacerun: yes"><a href="http://www.davidgiard.com/content/binary/DD01_Fig1.jpg" target="_pix"><img style="WIDTH: 462px; HEIGHT: 337px" border="0" alt="New Project dialog" src="http://www.davidgiard.com/content/binary/DD01_Fig1.jpg" width="594" height="448" /></a><br />
  </span><b style="mso-bidi-font-weight: normal">Figure 1</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">6.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font size="3" face="Calibri">The <strong>New
Database Project Wizard</strong> displays with the <strong>Welcome</strong> screen
active.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <font size="3" face="Calibri">7.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </font>
            </span>
          </span>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">At
the <strong>Welcome</strong> screen, click the <strong>Next</strong> button to advance
to the <strong>Project Properties</strong> screen. 
<br /><a href="http://www.davidgiard.com/content/binary/DD01_Fig2.jpg" target="_pix"><img style="WIDTH: 462px; HEIGHT: 445px" border="0" alt="Project Properties screen" src="http://www.davidgiard.com/content/binary/DD01_Fig2.jpg" width="594" height="503" /></a><br /><span style="mso-spacerun: yes">  </span><b style="mso-bidi-font-weight: normal">Figure
2</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">8.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">I
almost never change the options on the <strong>Project Properties</strong> screen.<span style="mso-spacerun: yes">   </span></font>
              <font size="3">If
my database contains any stored procedures or functions written in C# or VB.Net, I
will check the <strong>Enable SQLCLR</strong> checkbox.</font>
              <span style="mso-spacerun: yes">
                <font size="3">  </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <font size="3" face="Calibri">9.</font>
                <span style="FONT: 7pt 'Times New Roman'">       </span>
              </font>
            </span>
          </span>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Click
the <strong>Next</strong> button to advance to the <strong>Set Database Options</strong> screen. 
<br /><a href="http://www.davidgiard.com/content/binary/DD01_Fig3.jpg" target="_pix"><img style="WIDTH: 463px; HEIGHT: 461px" border="0" alt="Set Database Options screen" src="http://www.davidgiard.com/content/binary/DD01_Fig3.jpg" width="594" height="495" /></a><br /><span style="mso-spacerun: yes">  </span><b style="mso-bidi-font-weight: normal">Figure
3</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">10.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The
options on the<strong> Set Database Options</strong> screen correspond to the settings
you will find in SQL Server Management Studio when you right-click a database and
select Properties.<span style="mso-spacerun: yes">  </span>The defaults in the
database project wizard are also the defaults in SQL Server.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Since
I seldom override these defaults in SQL Server, there is usually no reason to change
them on this screen.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <font size="3" face="Calibri">11.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </font>
            </span>
          </span>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Click
the <strong>Next</strong> button to advance to the <strong>Import Database Schema</strong> screen. 
<br /><a href="http://www.davidgiard.com/content/binary/DD01_Fig4.jpg" target="_pix"><img style="WIDTH: 462px; HEIGHT: 428px" border="0" alt="Import Database Schema screen" src="http://www.davidgiard.com/content/binary/DD01_Fig4.jpg" width="589" height="485" /></a><br /><span style="mso-spacerun: yes">  </span><b style="mso-bidi-font-weight: normal">Figure
4</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">12.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">On
the <strong>Import Database Schema</strong> screen, check the <strong>Import Existing
S</strong>chema checkbox.<span style="mso-spacerun: yes">  </span>This enables
the Source database connection dropdown.<span style="mso-spacerun: yes">  </span>If
you already have created a connection to your database, select it from the dropdown.<span style="mso-spacerun: yes">   </span>If
you have not yet created a connection, click the <strong>New Connection</strong> button
to create one now.<span style="mso-spacerun: yes">  </span>The process for creating
a database connection in Visual Studio hasn’t changed for several versions of the
product so I won’t repeat it here.<span style="mso-spacerun: yes">  </span>However
it is worth noting that, although Data Dude requires that you have a local installation
of SQL Server, the database you connect to here can be located on any server to which
you have access.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">I
always usually connect to the Development database because this is the first database
I create for an application.</font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
            <span style="mso-list: Ignore">
              <font color="#000000">
                <font size="3" face="Calibri">13.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </font>
            </span>
          </span>
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Click
the <strong>Next</strong> button to advance to the <strong>Configure Build and Deploy</strong> screen. 
<br /><a href="http://www.davidgiard.com/content/binary/DD01_Fig5.jpg" target="_pix"><img style="WIDTH: 461px; HEIGHT: 405px" border="0" alt="Configure Build and Deploy screen" src="http://www.davidgiard.com/content/binary/DD01_Fig5.jpg" width="543" height="440" /></a><br /><span style="mso-spacerun: yes">  </span><b style="mso-bidi-font-weight: normal">Figure
5</b></font>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpMiddle">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">14.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </span>
            </span>
            <font face="Calibri">
              <font size="3">The <strong>Configure
Build and Deploy</strong> screen contains settings that will take effect when you
“deploy” your database project.<span style="mso-spacerun: yes">  </span>Deploying
a database project writes changes to the schema of a target database (specified in
the Target database name field of this screen) and is accomplished by selecting the
menu options <strong>Build | Deploy</strong> with the database project open and selected.<span style="mso-spacerun: yes">  </span></font>
              <font size="3">Deploying
is most useful when each developer has his own copy of the development database and
needs a quick way to synchronize his schema with a master copy. </font>
              <span style="mso-spacerun: yes">
                <font size="3"> </font>
              </span>
            </font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpLast">
          <font color="#000000">
            <span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin">
              <span style="mso-list: Ignore">
                <font size="3" face="Calibri">15.</font>
                <span style="FONT: 7pt 'Times New Roman'">   </span>
              </span>
            </span>
            <font size="3" face="Calibri">Click
the <strong>Finish</strong> button to create the database project initialized
with schema objects found in the source database and with the settings you chose in
the wizard screens.</font>
          </font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpLast">
          <font color="#000000" size="3" face="Calibri">16. </font>
          <font color="#000000" size="3" face="Calibri">After
Visual Studio finishes creating the database project, view the objects in the Solution
Explorer (Select <strong>View | Solution Explorer</strong>).  You should
see a "Schema Objects" folder in the project containing a subfolder for each type
of database object.  Open the "tables" subfolder to view you will see files containing
scripts for each table in your database.  Double-click one of these script files
to see the SQL code generated for you.<br /><a href="http://www.davidgiard.com/content/binary/DD01_Fig6.jpg" target="_pix"><img border="1" alt="Database project in Solution Explorer" src="http://www.davidgiard.com/content/binary/DD01_Fig6.jpg" /></a><br />
    <strong>Figure 6</strong></font>
        </p>
        <p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class="MsoListParagraphCxSpLast">
          <font color="#000000" size="3" face="Calibri">17. If you use a source control repository,
such as TFS, you will want to check this project into the repository to make it easier
to share with others.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">As you can see, when you use the wizard
to create your project, most of the work is done for you.<span style="mso-spacerun: yes">  </span>You
are able to change the default settings, but in most cases this is not necessary.<span style="mso-spacerun: yes">  </span>Often,
the only change I make on the wizard screens is when I select a database connection.</font>
        </p>
        <p style="MARGIN: 0in 0in 10pt" class="MsoNormal">
          <font color="#000000" size="3" face="Calibri">In the next article, we will discuss
how to use the Schema Compare tool to bring data changes into or out of your database
project.</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=30b4fa79-a994-49f0-abe4-d644c77b8c65" />
      </body>
      <title>Data Dude tutorial 1 - Creating a database project</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,30b4fa79-a994-49f0-abe4-d644c77b8c65.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/11/DataDudeTutorial1CreatingADatabaseProject.aspx</link>
      <pubDate>Mon, 11 Aug 2008 14:12:22 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Microsoft Visual Studio Team System
2008 Database Edition (aka “Data Dude”) provides tools for managing and deploying
SQL Server databases.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In order to use
Data Dude to manage an existing SQL Server database, the first step is to create a
database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;There are a couple key points you will need
to know before using Data&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Dude.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The
current version of Data Dude only works on SQL Server 2000 and SQL Server 2005.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Visual
Studio 2008 Service Pack 1 should provide support for SQL Server 2008.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;I
will describe an example using SQL Server 2005.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The
validation engine in Data Dude requires that you install either SQL Server or SQL
Express on the same machine on which Data Dude is installed.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l1 level1 lfo1" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;You
must grant “Create database” rights in this database engine to the currently logged-in
user.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;Now, let’s discuss how to create a database
project to manage an existing SQL Server 2005 database.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpFirst&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;1.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;Open
Visual Studio.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;2.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Select &lt;strong&gt;File
| New Project…&lt;/strong&gt; The &lt;strong&gt;New Project&lt;/strong&gt; dialog displays&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;3.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Under &lt;strong&gt;Project
Type&lt;/strong&gt;, select Database &lt;em&gt;Projects\Microsoft SQL Server&lt;/em&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;4.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Under &lt;strong&gt;Templates&lt;/strong&gt;,
select &lt;em&gt;SQL Server 2005 Wizard&lt;/em&gt;.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;5.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Enter
a meaningful name and location for this project.&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;br&gt;
Typically, my databases have names like “AdventureWorks_Dev” and “AdventureWorks_QA”
which describe both the data and the environment to which the data belongs.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Because
a single database project is used for all environments, I name my database project
to describe the data and follow it with “DB” to make it obvious it is a database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In
the above example, I would name my database project “AdventureWorksDb”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In
this exercise, I’ll create a project named “TestDB”.&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig1.jpg" target=_pix&gt;&lt;img style="WIDTH: 462px; HEIGHT: 337px" border=0 alt="New Project dialog" src="http://www.davidgiard.com/content/binary/DD01_Fig1.jpg" width=594 height=448&gt; &lt;/a&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure 1&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;6.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;The &lt;strong&gt;New
Database Project Wizard&lt;/strong&gt; displays with the &lt;strong&gt;Welcome&lt;/strong&gt; screen
active.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font size=3 face=Calibri&gt;7.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;At
the &lt;strong&gt;Welcome&lt;/strong&gt; screen, click the &lt;strong&gt;Next&lt;/strong&gt; button to advance
to the &lt;strong&gt;Project Properties&lt;/strong&gt; screen. 
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig2.jpg" target=_pix&gt;&lt;img style="WIDTH: 462px; HEIGHT: 445px" border=0 alt="Project Properties screen" src="http://www.davidgiard.com/content/binary/DD01_Fig2.jpg" width=594 height=503&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
2&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;8.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;I
almost never change the options on the &lt;strong&gt;Project Properties&lt;/strong&gt; screen.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;If
my database contains any stored procedures or functions written in C# or VB.Net, I
will check the &lt;strong&gt;Enable SQLCLR&lt;/strong&gt; checkbox.&lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font size=3 face=Calibri&gt;9.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Click
the &lt;strong&gt;Next&lt;/strong&gt; button to advance to the &lt;strong&gt;Set Database Options&lt;/strong&gt; screen. 
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig3.jpg" target=_pix&gt;&lt;img style="WIDTH: 463px; HEIGHT: 461px" border=0 alt="Set Database Options screen" src="http://www.davidgiard.com/content/binary/DD01_Fig3.jpg" width=594 height=495&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
3&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;10.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The
options on the&lt;strong&gt; Set Database Options&lt;/strong&gt; screen correspond to the settings
you will find in SQL Server Management Studio when you right-click a database and
select Properties.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The defaults in the
database project wizard are also the defaults in SQL Server.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Since
I seldom override these defaults in SQL Server, there is usually no reason to change
them on this screen.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font size=3 face=Calibri&gt;11.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Click
the &lt;strong&gt;Next&lt;/strong&gt; button to advance to the &lt;strong&gt;Import Database Schema&lt;/strong&gt; screen. 
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig4.jpg" target=_pix&gt;&lt;img style="WIDTH: 462px; HEIGHT: 428px" border=0 alt="Import Database Schema screen" src="http://www.davidgiard.com/content/binary/DD01_Fig4.jpg" width=589 height=485&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
4&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;12.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;On
the &lt;strong&gt;Import Database Schema&lt;/strong&gt; screen, check the &lt;strong&gt;Import Existing
S&lt;/strong&gt;chema checkbox.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This enables
the Source database connection dropdown.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
you already have created a connection to your database, select it from the dropdown.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;If
you have not yet created a connection, click the &lt;strong&gt;New Connection&lt;/strong&gt; button
to create one now.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The process for creating
a database connection in Visual Studio hasn’t changed for several versions of the
product so I won’t repeat it here.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;However
it is worth noting that, although Data Dude requires that you have a local installation
of SQL Server, the database you connect to here can be located on any server to which
you have access.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;I
always usually connect to the Development database because this is the first database
I create for an application.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font size=3 face=Calibri&gt;13.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;Click
the &lt;strong&gt;Next&lt;/strong&gt; button to advance to the &lt;strong&gt;Configure Build and Deploy&lt;/strong&gt; screen. 
&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig5.jpg" target=_pix&gt;&lt;img style="WIDTH: 461px; HEIGHT: 405px" border=0 alt="Configure Build and Deploy screen" src="http://www.davidgiard.com/content/binary/DD01_Fig5.jpg" width=543 height=440&gt; &lt;/a&gt;
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Figure
5&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;14.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri&gt;&lt;font size=3&gt;The &lt;strong&gt;Configure
Build and Deploy&lt;/strong&gt; screen contains settings that will take effect when you
“deploy” your database project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Deploying
a database project writes changes to the schema of a target database (specified in
the Target database name field of this screen) and is accomplished by selecting the
menu options &lt;strong&gt;Build | Deploy&lt;/strong&gt; with the database project open and selected.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;font size=3&gt;Deploying
is most useful when each developer has his own copy of the development database and
needs a quick way to synchronize his schema with a master copy. &lt;/font&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font size=3&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3 face=Calibri&gt;15.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3 face=Calibri&gt;Click
the&amp;nbsp;&lt;strong&gt;Finish&lt;/strong&gt; button to create the database project initialized
with schema objects found in the source database and with the settings you chose in
the wizard screens.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;16. &lt;/font&gt;&lt;font color=#000000 size=3 face=Calibri&gt;After
Visual Studio finishes creating the database project, view the objects in the Solution
Explorer (Select &lt;strong&gt;View&amp;nbsp;| Solution Explorer&lt;/strong&gt;).&amp;nbsp; You should
see a "Schema Objects" folder in the project containing a subfolder for each type
of database object.&amp;nbsp; Open the "tables" subfolder to view you will see files containing
scripts for each table in your database.&amp;nbsp; Double-click one of these script files
to see the SQL code generated for you.&lt;br&gt;
&lt;a href="http://www.davidgiard.com/content/binary/DD01_Fig6.jpg" target=_pix&gt;&lt;img border=1 alt="Database project in Solution Explorer" src="http://www.davidgiard.com/content/binary/DD01_Fig6.jpg"&gt; &lt;/a&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Figure 6&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo2" class=MsoListParagraphCxSpLast&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;17. If you use a source control repository,
such as TFS, you will want to check this project into the repository to make it easier
to share with others.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;As you can see, when you use the wizard to
create your project, most of the work is done for you.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
are able to change the default settings, but in most cases this is not necessary.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Often,
the only change I make on the wizard screens is when I select a database connection.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;
&lt;font color=#000000 size=3 face=Calibri&gt;In the next article, we will discuss how to
use the Schema Compare tool to bring data changes into or out of your database project.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=30b4fa79-a994-49f0-abe4-d644c77b8c65" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,30b4fa79-a994-49f0-abe4-d644c77b8c65.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=b6b26260-96b7-4492-b58b-5aef6edc3759</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,b6b26260-96b7-4492-b58b-5aef6edc3759.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,b6b26260-96b7-4492-b58b-5aef6edc3759.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b6b26260-96b7-4492-b58b-5aef6edc3759</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Visual Studio Team System 2008 Database Edition is a mouthful to say, so a lot of
people affectionately call it “Data Dude”.
</p>
        <p>
Data Dude provides a set of tools integrated into Visual Studio that assist developers
in managing and deploying SQL Server database objects.
</p>
        <p>
There are four tools in this product that I have found particularly useful: the Database
Project; the Schema Compare tool; the Data Compare Tool; and Database Unit Tests.
</p>
        <p>
A <strong>Database Project </strong>is a Visual Studio project just as a class library
or ASP.Net web project is.  However, instead of holding .Net source code, a Database
Project holds the source code for database objects, such as tables, views and stored
procedures.  This code is typically written in SQL Data Definition Language (DDL). 
Storing this code in a Database Project makes it easier to check it into a source
code repository such as Team Foundation Server (TFS); and simplifies the process of
migrating database objects to other environments.
</p>
        <p>
The <strong>Schema Compare </strong>tool is most useful when comparing a database
with a Visual Studio Database Project.  Developers can use this tool after adding,
modifying or deleting objects from a database in order to propagate those changes
to a Database Project.  Later, a Database Administrator (DBA) can compare the
Database Project to a different database to see what objects have been added, dropped
or modified since the last compare.  The DBA can then deploy those changes to
the other database.  This is useful for migrating data objects from one environment
to another, for example when moving code changes from a Development database to a
QA or Production database.
</p>
        <p>
The <strong>Data Compare </strong>is another tool for migrating from one database
environment to the next.  This tool facilitates the migration of records in a
given table from one database to another.  The table in both the source and destination
database must have the same structure.  I use this when I want to seed values
into lookup tables, such as a list of states or a list of valid customer types that
are stored in database tables.
</p>
        <p>
          <strong>Unit tests </strong>have increased in popularity the last few years as developers
have come to realize their importance in maintaining robust, error-free code. 
But unit testing stored procedures is still relatively rare, even though code in stored
procedures is no less important than code in .Net assemblies.  Data Dude provides
the ability to write unit tests for stored procedures using the same testing framework
(MS Test) you used for unit tests of .Net code.  The tests work the same as your
other unit tests – you write code and assert what you expect to be true.  Each
test passes only if all its assertions are true at runtime.  The only difference
is that your code is written in T-SQL, instead of C# or Visual Basic.Net.  
</p>
        <p>
There are some limitations.  In order to use Data Dude, you must have either
SQL Server 2008 or SQL Express installed locally on your development machine and you
(the logged-in user) must have "Create Database" rights on that local installation. 
To my knowledge, Data Dude only works with SQL Server 2000 and 2005 databases. 
Plans to integrate with SQL Server 2008 have been announced but I don't know Microsoft's
plans for other database engines.   I also occasionally find myself wishing
Data Dude could accomplish its tasks more easily or in a more automated fashion. 
I wish, for example, I could specify that I always want to ignore database users in
a database and always want to migrate everything else when using the Schema Compare
tool.  But overall, the tools in this product have increased my productivity
significantly.  Nearly every application I write has a database element to it
and anything that can help me with database development, management and deployment
improves the quality of my applications.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=b6b26260-96b7-4492-b58b-5aef6edc3759" />
      </body>
      <title>The Goodness of Data Dude</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,b6b26260-96b7-4492-b58b-5aef6edc3759.aspx</guid>
      <link>http://www.davidgiard.com/2008/08/10/TheGoodnessOfDataDude.aspx</link>
      <pubDate>Sun, 10 Aug 2008 12:34:41 GMT</pubDate>
      <description>&lt;p&gt;
Visual Studio Team System 2008 Database Edition is a mouthful to say, so a lot of
people affectionately call it “Data Dude”.
&lt;/p&gt;
&lt;p&gt;
Data Dude provides a set of tools integrated into Visual Studio that assist developers
in managing and deploying SQL Server database objects.
&lt;/p&gt;
&lt;p&gt;
There are four tools in this product that I have found particularly useful: the Database
Project; the Schema Compare tool; the Data Compare Tool; and Database Unit Tests.
&lt;/p&gt;
&lt;p&gt;
A &lt;strong&gt;Database Project &lt;/strong&gt;is a Visual Studio project just as a class library
or ASP.Net web project is.&amp;nbsp; However, instead of holding .Net source code, a Database
Project holds the source code for database objects, such as tables, views and stored
procedures.&amp;nbsp; This code is typically written in SQL Data Definition Language (DDL).&amp;nbsp;
Storing this code in a Database Project makes it easier to check it into a source
code repository such as Team Foundation Server (TFS); and simplifies the process of
migrating database objects to other environments.
&lt;/p&gt;
&lt;p&gt;
The &lt;strong&gt;Schema Compare &lt;/strong&gt;tool is most useful when comparing a database
with a Visual Studio Database Project.&amp;nbsp; Developers can use this tool after adding,
modifying or deleting objects from a database in order to propagate those changes
to a Database Project.&amp;nbsp; Later, a Database Administrator (DBA) can compare the
Database Project to a different database to see what objects have been added, dropped
or modified since the last compare.&amp;nbsp; The DBA can then deploy those changes to
the other database.&amp;nbsp; This is useful for migrating data objects from one environment
to another, for example when moving code changes from a Development database to a
QA or Production database.
&lt;/p&gt;
&lt;p&gt;
The &lt;strong&gt;Data Compare &lt;/strong&gt;is another tool for migrating from one database
environment to the next.&amp;nbsp; This tool facilitates the migration of records in a
given table from one database to another.&amp;nbsp; The table in both the source and destination
database must have the same structure.&amp;nbsp; I use this when I want to seed values
into lookup tables, such as a list of states or a list of valid customer types that
are stored in database tables.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Unit tests &lt;/strong&gt;have increased in popularity the last few years as developers
have come to realize their importance in maintaining robust, error-free code.&amp;nbsp;
But unit testing stored procedures is still relatively rare, even though code in stored
procedures is no less important than code in .Net assemblies.&amp;nbsp; Data Dude provides
the ability to write unit tests for stored procedures using the same testing framework
(MS Test) you used for unit tests of .Net code.&amp;nbsp; The tests work the same as your
other unit tests – you write code and assert what you expect to be true.&amp;nbsp; Each
test passes only if all its assertions are true at runtime.&amp;nbsp; The only difference
is that your code is written in T-SQL, instead of C# or Visual Basic.Net.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
There are some limitations.&amp;nbsp; In order to use Data Dude, you must have either
SQL Server 2008 or SQL Express installed locally on your development machine and you
(the logged-in user) must have "Create Database" rights on that local installation.&amp;nbsp;
To my knowledge, Data Dude only works with SQL Server 2000 and 2005 databases.&amp;nbsp;
Plans to integrate with SQL Server 2008 have been announced but I don't know Microsoft's
plans for other database engines.&amp;nbsp;&amp;nbsp; I also occasionally find myself wishing
Data Dude could accomplish its tasks more easily or in a more automated fashion.&amp;nbsp;
I wish, for example, I could specify that I always want to ignore database users in
a database and always want to migrate everything else when using the Schema Compare
tool.&amp;nbsp; But overall, the tools in this product have increased my productivity
significantly.&amp;nbsp; Nearly every application I write has a database element to it
and anything that can help me with database development, management and deployment
improves the quality of my applications.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=b6b26260-96b7-4492-b58b-5aef6edc3759" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,b6b26260-96b7-4492-b58b-5aef6edc3759.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>VSTS</category>
    </item>
  </channel>
</rss>