<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SSIS Junkie : Datadude</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx</link><description>Tags: Datadude</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Considerations when starting a new SSDT database project</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/03/21/considerations-when-starting-a-new-ssdt-database-project.aspx</link><pubDate>Thu, 21 Mar 2013 10:58:03 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:48327</guid><dc:creator>jamiet</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/48327.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=48327</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=48327</wfw:comment><description>&lt;p&gt;As you may have realised from much of my blogging over the past year or so I’m an advocate of using SSDT database projects for building database solutions on SQL Server. I have been using SSDT database projects a lot in that time and have come up with a checklist of things to consider when starting a new SSDT database project and I’ll be detailing that checklist below. I strongly advise you to consider making decisions about these items before you even write a scrap of code as invariably it will be more difficult to change later, especially if you have already deployed your database.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;In no particular order here is my checklist:&lt;/p&gt;  &lt;h3&gt;Folder Structure&lt;/h3&gt;  &lt;p&gt;By default SSDT will not provide a folder structure for new projects in which to store all your script files so you might want to consider setting one up yourself. I recommend not trying to create a large hierarchy of folders to start with as this will evolve as you go about building your database. Here’s a simple starter for ten:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_2ADBA6CA.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_174E4729.png" width="212" height="138" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Filegroups&lt;/h3&gt;  &lt;p&gt;If you don’t understand the importance of filegroups then read Thomas Larock’s recent blog post &lt;a href="http://thomaslarock.com/2013/01/database-filegroups-just-like-seatbelts-but-with-less-chafing/"&gt;DATABASE FILEGROUPS: JUST LIKE SEATBELTS BUT WITH LESS CHAFING&lt;/a&gt;. Quite often your organisation will stipulate policies for what filegroups you should be using and I highly recommend that you set up filegroups in your database projects to match those policies sooner rather than later. If your organisation does not have any such policies then perhaps think about defining them yourself, Thomas lists a few considerations that may influence your decisions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;separation of system data from user data &lt;/li&gt;    &lt;li&gt;larger indexes may benefit from their own filegroup &lt;/li&gt;    &lt;li&gt;archival of data can benefit from using dedicated filegroups as this will reduce backup maintenance tasks &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you follow my suggested folder structure above then put your filegroups into the “Storage” folder:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_2852750C.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_75826E97.png" width="183" height="173" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Above all, specify your default filegroup especially as many DBAs won’t be happy about you putting objects into the PRIMARY filegroup (which is the default). This is done by right-clicking on the project and selecting “Properties..” When there hit “Database Settings…” and set your default filegroup on the “Operational” tab:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML1ebb40b8_7FD392F7.png"&gt;&lt;img title="SNAGHTML1ebb40b8" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="SNAGHTML1ebb40b8" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML1ebb40b8_thumb_25C9434E.png" width="405" height="146" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you intend to use the filestream feature of SQL Server then you can set the default filestream filegroup here too.&lt;/p&gt;  &lt;h3&gt;Collation&lt;/h3&gt;  &lt;p&gt;If you take only one piece of advice from this blog post make it this: &lt;strong&gt;set your collation before you write a single line of code&lt;/strong&gt; (just trust me on this, OK). You’ll find this in Project Properties-&amp;gt;Project Settings-&amp;gt;Database Settings-&amp;gt;Common&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML1ebc6e3e_4BBEF3A4.png"&gt;&lt;img title="SNAGHTML1ebc6e3e" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="SNAGHTML1ebc6e3e" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML1ebc6e3e_thumb_71B4A3FA.png" width="415" height="160" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Again, find out if your organisation has any guidance on database collation.&lt;/p&gt;  &lt;h3&gt;Specify Target platform&lt;/h3&gt;  &lt;p&gt;SSDT allows you to deploy a project to SQL Server 2005, 2008, 2012 or Azure so it stands to reason that you should specify which you are intending to deploy to. You’ll find this in Project Properties-&amp;gt;Project Settings:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_778F4793.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5AA622BE.png" width="399" height="128" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h3&gt;Default Schema&lt;/h3&gt;  &lt;p&gt;If you follow the premise that “anything that SQL Server picks as the default is probably wrong” then you should probably think about changing the default schema which, by default, will be [dbo]. SSDT will create all new objects in the default schema (unless otherwise specified).&lt;/p&gt;  &lt;p&gt;Generally I’m of the opinion that not accepting SQL Server’s defaults is a good idea if only because it forces you to think about these things and be aware of them; in the case of schemas it forces you to think about security and who should have GRANT or DENY permissions and on what.&lt;/p&gt;  &lt;p&gt;Specify the default schema in Project properties-&amp;gt;Project Settings:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_158D5588.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_791063A7.png" width="428" height="71" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Review other database settings&lt;/h3&gt;  &lt;p&gt;I’ve mentioned the most important database settings that you should look to change however you should also glance over the rest of the defaults that SSDT chooses for you to verify that they are valid for your project. Again, these are in Project Properties-&amp;gt;Project Settings-&amp;gt;Database Settings. a few I’d call out as being especially worthy of your attention are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Auto update stats (on by default) &lt;/li&gt;    &lt;li&gt;Recovery model (FULL by default) &lt;/li&gt;    &lt;li&gt;Transaction Isolation (RCSI off by default) &lt;/li&gt;    &lt;li&gt;Service broker (disabled by default) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_18530A7B.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6C360D89.png" width="244" height="240" /&gt;&lt;/a&gt;       &lt;br /&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5D1F2EAF.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_42DEC58B.png" width="395" height="404" /&gt;&lt;/a&gt;       &lt;br /&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_289E5C67.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_12684115.png" width="396" height="403" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Code Analysis&lt;/h3&gt;  &lt;p&gt;SSDT always checks the syntax of your database code, that’s one of the main justifications for using SSDT database projects. However what it does not do (not by default anyway) is check whether the code you write might be considered &lt;em&gt;good &lt;/em&gt;code. That’s what Code Analysis is for, your code gets checked to see if it adheres to well-understood good practices for SQL Server database development. For example, Code Analysis will check for use of “SELECT*” which is generally regarded as a bad thing.&lt;/p&gt;  &lt;p&gt;Code analysis is turned off by default. I recommend that you head into Project Properties-&amp;gt;Code Analysis and turn it on. Moreover I recommend that you check all the boxes under “Treat Warning as Error” – this forces developers to address issues that get raised by Code Analysis.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0D195A64.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2B839B4D.png" width="437" height="255" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Big Labels&lt;/h3&gt;  &lt;p&gt;Add a banner to your Pre-Deployment script as I describe in &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/09/26/big-label-generator.aspx" target="_blank"&gt;Big label generator&lt;/a&gt;. This may seem rather unnecessary but it takes about 30 seconds and believe me, at some point you’ll be glad you did!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2A99351D.png" width="619" height="334" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The demo project that I took some of the above screenshots from is downloadable from &lt;a title="http://sdrv.ms/ZW0gNt" href="http://sdrv.ms/ZW0gNt"&gt;http://sdrv.ms/ZW0gNt&lt;/a&gt; and might provide a useful template for your own SSDT database projects.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;If you have any more suggestions for my checklist please add them to the comments below!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=48327" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>SSDT database projects were not always going to output T-SQL…</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/02/13/ssdt-database-projects-were-not-always-going-to-output-t-sql.aspx</link><pubDate>Wed, 13 Feb 2013 09:15:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47693</guid><dc:creator>jamiet</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/47693.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=47693</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=47693</wfw:comment><description>&lt;p&gt;Interesting the stuff you pick up from reading forums…&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;“The BATCH seperators [in SSDT deployment scripts] are used to provide scoping when resolving object shapes. SSDT or VSDB scripts for that matter serve a different purpose, they provide the blueprint of the model you want, and do not represent how it will be used to construct the target site. &lt;strong&gt;We choose TSQL as our DSL, at first we wanted to use a different representation&lt;/strong&gt;, but user research in 2005 told us loud and clear users wanted to use TSQL as their DSL. In order to make the compiler work, we had to impose some simplifications, one is a more frequent use of BATCH seperators to indentify object scopes.”&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;by Gert Drapers (former lead of the SSDT product team) at &lt;/em&gt;&lt;a title="http://social.msdn.microsoft.com/Forums/en-US/ssdt/thread/47d4124b-82cd-48f9-8ba7-c2ae4c73cbcf/" href="http://social.msdn.microsoft.com/Forums/en-US/ssdt/thread/47d4124b-82cd-48f9-8ba7-c2ae4c73cbcf/"&gt;&lt;em&gt;http://social.msdn.microsoft.com/Forums/en-US/ssdt/thread/47d4124b-82cd-48f9-8ba7-c2ae4c73cbcf/&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Personally I’m glad that they chose to use T-SQL as it makes debugging easier but I’d be interested to know what else was on the table!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=47693" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>Which version of SSDT Database Projects do I have installed?</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/02/08/which-version-of-ssdt-database-projects-do-i-have-installed.aspx</link><pubDate>Fri, 08 Feb 2013 21:15:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47608</guid><dc:creator>jamiet</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/47608.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=47608</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=47608</wfw:comment><description>&lt;p&gt;SQL Server Data Tools (SSDT) is released on a very regular cadence (note that I’m talking about the &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/04/03/ssdt-what-s-in-a-name.aspx" target="_blank"&gt;database projects part of SSDT&lt;/a&gt;, this is nothing to do with SSIS/SSAS/SSRS). Since the first release in &lt;a href="http://blogs.msdn.com/b/ssdt/archive/2012/03/05/available-today-sql-server-data-tools-rtw.aspx" target="_blank"&gt;March 2012&lt;/a&gt; there have been releases in &lt;a href="http://blogs.msdn.com/b/ssdt/archive/2012/09/14/now-available-sql-server-data-tools-september-2012-update.aspx" target="_blank"&gt;September 2012&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/ssdt/archive/2012/11/07/sql-server-data-tools-november-2012-is-now-available.aspx" target="_blank"&gt;November 2012&lt;/a&gt;, &amp;amp; &lt;a href="http://blogs.msdn.com/b/ssdt/archive/2012/12/13/available-today-ssdt-december-2012.aspx" target="_blank"&gt;December 2012&lt;/a&gt;. I personally have found it difficult to keep track of not only which particular version I am using but also that which are my colleagues are using – quite simply I didn’t know how to discover the current version number. I assumed that the answer would lie within Visual Studio 2012 in the Help-&amp;gt;About Microsoft Visual Studio menu option, when I checked there I saw this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML339e96a2_1BDE30CA.png"&gt;&lt;img title="SNAGHTML339e96a2" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="SNAGHTML339e96a2" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML339e96a2_thumb_286BDDE6.png" width="507" height="333" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;A version number – 11.1.21208.0. What does that mean though? To understand more we have to go to Add/Remove programs:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML42d8efe8_2008088F.png"&gt;&lt;img title="SNAGHTML42d8efe8" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="SNAGHTML42d8efe8" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML42d8efe8_thumb_528B6601.png" width="934" height="275" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;There are many different items listed there, let’s look at them in turn:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Microsoft SQL Server 2012 Data-Tier App Framework&lt;/strong&gt;. This is fairly self-explanatory if you know what the Data-Tier App Framework (aka DACFx) is. If you don’t, see the notes at the end of this blog post*. The reason that you see two entries in the list above is due to my having the 32bit &amp;amp; 64bit versions installed – the fact that there is no differentiation between the two in the title is a bug. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Microsoft SQL Server 2012 Express LocalDB&lt;/strong&gt;. LocalDB is the small server-less version of SQL Server that now gets deployed with SQL Server proper. LocalDB also gets installed with SSDT if you do not already have it, but you should consider it part of SQL Server itself. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Microsoft SQL Server Data Tools 2010&lt;/strong&gt;. This was described to me as the “installation chainer” – it is the installation component that manages SSDT and its dependencies. I think of it as the SSDT shell within Visual Studio 2010. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Microsoft SQL Server Data Tools 2012&lt;/strong&gt;. This was described to me as the “installation chainer” – it is the installation component that manages SSDT and its dependencies. I think of it as the SSDT shell within Visual Studio 2012. Note that the version number is the same as in the Help-&amp;gt;About screenshot at the top of this article – that is because they are one and the same. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Microsoft SQL Server Data Tools – Database Projects – Web installer entry point&lt;/strong&gt;. A stub project that gets installed when you install SQL Server. Its the SSDT database project entry point. &lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;&lt;u&gt;&lt;strong&gt;Microsoft SQL Server Data Tools – enu (10.3.21208.0)&lt;/strong&gt; &amp;amp; &lt;strong&gt;Microsoft SQL Server Data Tools – enu (11.1.21208.0)&lt;/strong&gt;. These are the things we’re interested in. These *are* SSDT database projects, for Visual Studio 2010 &amp;amp; Visual Studio 2012 respectively. The version numbers are those for the December 2012 release; note that the build numbers are the same (X.X.21208.X), only the major and minor numbers are different.&lt;/u&gt;&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Microsoft SQL Server Data Tools Build Utilities – enu (10.3.21208.0)&lt;/strong&gt; &amp;amp; &lt;strong&gt;Microsoft SQL Server Data Tools Build Utilities – enu (11.1.21208.0)&lt;/strong&gt;. Everything you need to do a headless (i.e. without having Visual Studio installed) build/deploy of an SSDT database project. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So at the end of all that we have determined the following version numbers for SSDT database projects are:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2"&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;p align="center"&gt;&lt;strong&gt;Release&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;&lt;strong&gt;Visual Studio 2010 version number&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;&lt;strong&gt;Visual Studio 2012 version number&lt;/strong&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p align="center"&gt;September 2012&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;10.3.20905.0&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;11.1.20905.0&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p align="center"&gt;November 2012&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;10.3.21101.1&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;11.1.21101.1&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;         &lt;p align="center"&gt;December 2012&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;10.3.21208.0&lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&amp;nbsp;&lt;/td&gt;        &lt;td&gt;         &lt;p align="center"&gt;11.1.21208.0&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;&lt;strike&gt;I do not know the version numbers for the March 2012, September 2012 &amp;amp; November 2012 releases (if anyone out there does know please let me know in the comments) however I shall update this blog post for future releases.&lt;/strike&gt; September 2012 and November 2012 releases now added!&lt;/p&gt;  &lt;p&gt;I have requested that any blog post to announce future releases should contain the version numbers. Let’s hope that happens.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;* DACFx is described &lt;a href="http://www.microsoft.com/en-gb/download/details.aspx?id=35756" target="_blank"&gt;here&lt;/a&gt; as:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The Microsoft® SQL Server® 2012 Data-Tier Application Framework (DACFx) is a component which provides application lifecycle services for database development and management for Microsoft® SQL Server® and Windows Azure SQL Databases.      &lt;br /&gt;DacFX supports various database deployment and management scenarios for SQL Server and Windows Azure SQL Databases including extracting/exporting a live database to a DAC package, deploying a DAC package to a new or existing database, and migrating from on-premise SQL Server to Windows Azure. This functionality is exposed via the DACFx managed API. DACFx can target SQL Server 2005 SP4, 2008 SP1, 2008R2, 2012, and Windows Azure SQL Databases. DACFx also provides the command-line utility SqlPackage.exe for creating and deploying .dacpac and .bacpac packages. DACFx supports scenarios provided by SQL Server client tooling including SQL Server Data Tools and SQL Server Management Studio 2012.&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=47608" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>Responses to SSDT questions</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/01/11/responses-to-ssdt-questions.aspx</link><pubDate>Fri, 11 Jan 2013 22:22:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47124</guid><dc:creator>jamiet</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/47124.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=47124</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=47124</wfw:comment><description>&lt;p&gt;My recent article &lt;a href="http://www.devproconnections.com/article/sql-server-2012/sql-server-2012-data-tools-144829"&gt;Get to Know SQL Server 2012's SQL Server Data Tools&lt;/a&gt; prompted two questions to come to me via email and in the interests of sharing knowledge via search engines I thought I would answer them here rather than by simply replying by email (I hate that so much useful information gets trapped inside closed inboxes).&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Question: How would you handle cases below, our main database has many objects already, we are using redgate source control to keep things under sourcecontrol but ssdt would be awesome.        &lt;br /&gt;Our database has some invalid stored procs etc, unfortunately we do not want to drop them, underlying objects either don't exists or has changed etc         &lt;br /&gt;There are linked servers or code referencing other objects stored in the database         &lt;br /&gt;There are staging table named automatically in the database and we do not want to include them in the project and not drop them or touch them in a deploy &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;JT: The overall question here seems to be “how do we prevent SSDT from DROPping sprocs and staging tables that are in the target database but are not in the SSDT project?” Fortunately SSDT has an option within it to allow exactly what the questioner requires. When an SSDT project is published one has the option to set some properties relating to that publish. One of the settings is “DROP objects in target but not in project”:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML5751f10_20688721.png"&gt;&lt;img title="SNAGHTML5751f10" style="border-left-width:0px;border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;display:inline;padding-right:0px;border-top-width:0px;" border="0" alt="SNAGHTML5751f10" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML5751f10_thumb_11A9A170.png" width="340" height="484" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If that option is left unchecked (which is the default) then no objects will get removed from the target database.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Question: At my previous shop, I done a proof of concept with one of our databases, but never got it implemented as VS2012 (with SSDT) had not been released yet. Well, fast forward 9 or so months, and at my new shop (which is extremely agile) I've been tasked with setting up our db projects with SSDT so for the immediate short term goals/objectives we can;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Allow new or existing developers to be able to easily get the latest databases from source control downloaded from TFS, built and deployed onto our local sandbox db environments. This ideally will be done via a powershell script or something of the sort. &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#c0504d"&gt;&lt;em&gt;Be able to employ C.I. so that every night a database deployment is done to our system test servers.&lt;/em&gt; &lt;/font&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;3 days into it, and I've wrestled with 3 of our databases, reverse engineering them into TFS and getting them built etc. My question is, what are the best practices or guidelines for;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Allowing only Windows authentication for the local deploys to the sandbox environment. i.e. is it best to have a script with all our team user logins in a script? How would the project recognise a team member which will create a login for them so once the project is deployed they can login to their local db? &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Using a 1-touch/click action (preferably outside of VS2010) to get latest, build project &amp;amp; deploy to local sandbox &lt;/font&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;&lt;font color="#c0504d"&gt;Same as above but to a system test server&lt;/font&gt;&lt;/em&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;JT: There are quite a few questions there. Firstly I’ll say that its great to hear of sandboxed environments and Continuous Integration (CI) being used – I openly advocate these techniques in my blog post &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/01/implementing-sql-server-solutions-using-visual-studio-2010-database-projects-a-compendium-of-project-experiences.aspx"&gt;Implementing SQL Server solutions using Visual Studio 2010 Database Projects – a compendium of project experiences&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Now, taking each question in turn:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Windows Auth for local deploys. I’m not sure if there’s any recognised best practise here but if developers are working on local sandboxes I would assume they would have sysadmin rights so I’m not sure there’s a need to have a script of team logins. Perhaps I have misunderstood the question in which case please clarify in the comments below. I will say this though – I think its better to have a Windows group that you can move all of your devs in and out of rather than having to modify a script each time a user joins your team. &lt;/li&gt;    &lt;li&gt;1-click get latest, build &amp;amp; deploy. Scripting your build &amp;amp; deploy is something else I advocate in the &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/01/implementing-sql-server-solutions-using-visual-studio-2010-database-projects-a-compendium-of-project-experiences.aspx"&gt;aforementioned blog post&lt;/a&gt;:       &lt;blockquote&gt;       &lt;p&gt;&lt;em&gt;Building and deploying your datadude projects within Visual Studio can become a real time hog; in my experience its not unusual for deployments to take many minutes and your Visual Studio environment will be unavailable for further development work during that time. For that reason I recommend investing some time in writing some msbuild scripts that will build and deploy your project(s) from the command-line.&lt;/em&gt;&lt;/p&gt;     &lt;/blockquote&gt;      &lt;p&gt;I’ll go further here and say that the script with which you use to build and deploy to your sandbox should be the same script as which you use for your production environment and everything in between. The script should take a parameter value to name the environment and then deploy appropriately.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;See 2. &lt;/li&gt; &lt;/ol&gt;    &lt;hr /&gt;Hope that is useful. Any questions? Please put them in the comments.    &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=47124" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>“Add as object” or “Add as script”? [SSDT]</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/01/04/add-as-object-or-add-as-script-ssdt.aspx</link><pubDate>Fri, 04 Jan 2013 14:15:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47006</guid><dc:creator>jamiet</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/47006.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=47006</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=47006</wfw:comment><description>&lt;p&gt;In SQL Server Data Tools (SSDT) one way to create a new object is to right click on a folder in Solution Explorer and point to Add. Doing so will display this menu:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_20905F62.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0215F8AC.png" width="505" height="203" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;A number of options are offered for creating a brand new object (“function”, “table”, “stored proc” etc…) and one of them is “Script”. If your preference is to handcraft the DDL for every database object without resorting to a GUI then you may choose to use the “Script” option because, after all, every file is just a DDL script – why not write the thing from scratch? There is however one fundamental difference between the Script” option and all the other options that you should be aware of.&lt;/p&gt;  &lt;p&gt;For the screenshot below I added a script and handcrafted a simple CREATE TABLE statement:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML760417d0_6BDFDD59.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="SNAGHTML760417d0" border="0" alt="SNAGHTML760417d0" src="http://sqlblog.com/blogs/jamie_thomson/SNAGHTML760417d0_thumb_6D44002B.png" width="778" height="359" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Notice that the table is defined in the dbo schema but it is not appearing in SQL Server Object Explorer under the dbo schema node. Why is that? The answer is actually pretty simple. If I select Script1.sql in Solution Explorer and hit F4 the properties window appears and we see this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_3686A527.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_7C97623A.png" width="304" height="276" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The Build Action property of the file is set to “None” which means that the file does not get included in a build and hence any objects defined within that file will not appear in our database. This is the default behaviour when you Add as script whereas the default behaviour when you explicitly add an object is to set Build Action=Build. That is the fundamental difference between adding a script and adding a specific object.&lt;/p&gt;  &lt;p&gt;This is one of those nuances of SSDT that is an easy problem to spot when you know about it but can cause you to spend hours hunting around for a solution if you do not (believe me, I’ve been there). Be aware of it!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=47006" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>SQL Server Data Tools does support required variables</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/02/12/sql-server-data-tools-does-support-required-variables.aspx</link><pubDate>Sun, 12 Feb 2012 11:58:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:41704</guid><dc:creator>jamiet</dc:creator><slash:comments>9</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/41704.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=41704</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=41704</wfw:comment><description>&lt;p&gt;Over the past few years of using datadude (aka DBPro aka Visual Studio Database Projects) I have fallen prey to a peculiar little nuance – if you forget to supply a value for a sqlcmd variable then it will simply use a default and often that is not the desired behaviour. Hence why yesterday I submitted the following suggestion to &lt;a href="http://connect.microsoft.com/sqlserver/feedback"&gt;http://connect.microsoft.com/sqlserver/feedback&lt;/a&gt; :&lt;/p&gt;  &lt;blockquote&gt;   &lt;h3&gt;&lt;em&gt;Specify sqlcmdvars properties as &amp;quot;required to be overridden”&lt;/em&gt;&lt;/h3&gt;    &lt;p&gt;&lt;em&gt;In my current place of work I am responsible for maintaining our datadude projects and we have another team that is in charge of deployments. Hence, when we place new properties into the sqlcmdvars file I need to tell the deployment team what values to supply for that property per environment (dev, systest, uat, prod).       &lt;br /&gt;Unfortunately lack of communication/human error occasionally creeps in and, for whatever reason, no value gets supplied for some property at deployment time. If this is the case the default value as specified in the sqlcmdvars file gets used instead - invariably this will be the wrong value. I would like a mechanism within SSDT of preventing this from ever happening.&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;One simple way to prevent this would be to specify that a sqlcmdvars property is *required* to be overridden during the deployment. In other words, never use the default. if an override is not supplied at deployment time then the deployment should fail.       &lt;br /&gt;Note that this stipulation should only be in place when deployment occurs from the command-line - if deploying from Visual Studio the default should be allowed (simply because Visual Studio doesn't provide a way to specify anything other than the default value supplied in the sqlcmdvars file).&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="https://connect.microsoft.com/sqlserver/feedback/details/724366/ssdt-specify-sqlcmdvars-properties-as-required-to-be-overridden#details"&gt;&lt;em&gt;https://connect.microsoft.com/sqlserver/feedback/details/724366/ssdt-specify-sqlcmdvars-properties-as-required-to-be-overridden#details&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It transpires that this requested feature is already available in the forthcoming SQL Server Data Tools (SSDT) as I shall now demonstrate. This screenshot shows the project properties of a SSDT project where we define the sqlcmd variables, I have defined a variable called $(Id_value):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_49257C87.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_63856F9E.png" width="732" height="259" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In SSDT the nomenclature for deploying a project is “Publish”, a function that can be found by right-clicking on a project in Solution Explorer:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_1438774A.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_05219870.png" width="368" height="248" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Selecting that brings up the Publish dialog.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4AC6228E.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6FE36CFA.png" width="554" height="536" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Notice how the “Publish” button is greyed out – that it because I have not supplied a value for $(Id_value); supplying a value enables the Publish button and I can go ahead and publish my project. In other words, SSDT &lt;em&gt;insists&lt;/em&gt; that I supply a value for that variable – exactly as I requested in my Connect submission.&lt;/p&gt;  &lt;p&gt;The same is true if I use the command-line publishing tool sqlpackage.exe. The following command does essentially the same thing as the above depicted Publish dialog:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt;sqlpackage.exe /TargetDatabaseName:MyDB /TargetServerName:&amp;quot;.\RC0&amp;quot; /Action:Publish /SourceFile:&amp;quot;TestRequiredSqlCmdVars.dacpac&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Executing that gives me an error:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Publishing to database 'MyDB' on server '.\RC0'.     &lt;br /&gt;&lt;font color="#ff0000"&gt;*** Missing values for the following SqlCmd variables:       &lt;br /&gt;'Id_value'.&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here’s a screenshot showing the same:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_40454E6E.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_05E9D88D.png" width="618" height="201" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In order to supply a value for the variable from the command-line you need to use the /v: switch like so:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;gt;sqlpackage.exe /TargetDatabaseName:MyDB /TargetServerName:&amp;quot;.\RC0&amp;quot; /Action:Publish /SourceFile:&amp;quot;TestRequiredSqlCmdVars.dacpac&amp;quot; &lt;strong&gt;/v:Id_value=1&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4B8E62AB.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5C265D99.png" width="617" height="201" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;As you can see, publish was successful!&lt;/p&gt;  &lt;p&gt;So there you go, using SSDT you’ll no longer be able to fall prey to the problem I highlighted at the top of this blog post. In a later blog post I’ll show how you CAN supply a default value if you want to and also how you can override for your local environment.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=41704" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+2012/default.aspx">SQL Server 2012</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sqlpackage.exe/default.aspx">sqlpackage.exe</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>Thoughts on Test Driven Database Development</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/26/thoughts-on-test-driven-database-development.aspx</link><pubDate>Thu, 26 Jan 2012 08:30:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:41327</guid><dc:creator>jamiet</dc:creator><slash:comments>15</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/41327.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=41327</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=41327</wfw:comment><description>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank"&gt;Test-Driven Development (TDD)&lt;/a&gt; is a software development practise that has been around for a few years. Wikipedia describes it as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;i&gt;Test-driven development (TDD) is a &lt;a href="http://en.wikipedia.org/wiki/Software_development_process" title="Software development process"&gt;software development process&lt;/a&gt; that relies on the repetition of a very short development cycle: first the developer writes a failing automated &lt;a href="http://en.wikipedia.org/wiki/Test_case" title="Test case"&gt;test case&lt;/a&gt; that defines a desired improvement or new function, then produces code to pass that test and finally &lt;a href="http://en.wikipedia.org/wiki/Code_refactoring" title="Code refactoring"&gt;refactors&lt;/a&gt; the new code to acceptable standards. &lt;a href="http://en.wikipedia.org/wiki/Kent_Beck" title="Kent Beck"&gt;Kent Beck&lt;/a&gt;,
 who is credited with having developed or 'rediscovered' the technique, 
stated in 2003 that TDD encourages simple designs and inspires 
confidence.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;&lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank"&gt;http://en.wikipedia.org/wiki/Test-driven_development&lt;/a&gt;&lt;/i&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since 2003 TDD practises have seen refinements such as &lt;a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank"&gt;Behavior-Driven Development&lt;/a&gt; and &lt;a href="http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd" target="_blank"&gt;Uncle Bob's Three Rules of TDD&lt;/a&gt;, all the while TDD has pretty much become an accepted way of developing quality software. Accepted that is everywhere outside of the database development arena and that is the arena in which I spend my working life. TDD simply has not, in my opinion, caught on with database developers like it has our appdev brethren and I was reminded of this yesterday when &lt;a href="https://twitter.com/#%21/atulthakor" target="_blank"&gt;Atul Thakor&lt;/a&gt; asked on Twitter:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;i&gt;anyone done TDD for database development and would they recommend it?&lt;/i&gt; &lt;i&gt;&lt;br&gt;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;&lt;i&gt;&lt;a href="https://twitter.com/#%21/atulthakor/status/161886007929733120" target="_blank"&gt;https://twitter.com/#!/atulthakor/status/161886007929733120&lt;/a&gt;&lt;/i&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To which my answer was an emphatic:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;i&gt;(1) yes &amp;amp; (2) absolutely, yes&lt;/i&gt;&lt;/p&gt;
&lt;i&gt;&lt;a href="https://twitter.com/#%21/jamiet/status/161894215217987585" target="_blank"&gt;https://twitter.com/#!/jamiet/status/161894215217987585&lt;/a&gt;&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;I'll use this blog post to expand on that outside of 140 characters.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;In October 2010 I undertook a mini-project for the client I was working for at the time (a bank) where a colleague and I were tasked with building the database portion of a system that would support reconciliation of our ETL processes. It was a nice piece of work in that it was small, well-scoped, time-bound, greenfield, did not have any external dependancies and had a technically savvy product owner. We sat down at the start and decided that this was an ideal opportunity to trial TDD as a method of developing a database; I would write the failing tests and my colleague would make the tests pass. We came up with some guiding principles and, although we didn't know it at the time, they were pretty close to Uncle Bob's three rules.&lt;/p&gt;

&lt;p&gt;I used Visual Studio 2010's &lt;a href="http://msdn.microsoft.com/en-us/library/bb381703%28v=vs.80%29.aspx" target="_blank"&gt;database unit testing framework&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt; to write my tests and have them run as part of our Continuous Integration (CI) build (see &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/20/setting-up-database-unit-testing-as-part-of-a-continuous-integration-build-process-vs2010-db-tools-datadude.aspx" target="_blank"&gt;Setting up database unit testing as part of a Continuous Integration build process&lt;/a&gt;). I would write the tests, check-in, the CI build would fail and my colleague would "get latest" in order to see what code he had to write to stop the build from failing. To cut a long story short the use of TDD was considered to be a great success; we shipped a working system on time/on budget and moreover, &lt;i&gt;&lt;b&gt;even though I didn't write a scrap of code that went into production I have never had more confidence that a system I was involved in building worked as intended&lt;/b&gt;&lt;/i&gt;. That's quite a statement. My confidence stemmed from the fact that as the test author I was ultimately responsible for ensuring that the system did what it was supposed to; I could qualify my confidence by pointing at our CI build and highlighting the number of tests that were passing and how that number had steadily increased as the project progressed.&lt;/p&gt;&lt;p&gt;By the time the project had finished the database consisted of (if memory serves me correctly) 6 tables and about 10 stored procedures or functions (so yes, very small). To test that we had roughly 70 tests that were getting run up to 20 times a day. The project had taken about two months from start-up to final delivery - you can make your own opinions as to whether you consider that prompt or tardy but our product owner was happy and that's pretty much all that counted as far as I was concerned.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Since that project I have moved onto other clients and at each one I have always extolled the use of database unit testing; we haven't always practised TDD but at each one we &lt;i&gt;have &lt;/i&gt;been writing database unit tests and in the future I suspect that a client's willingness (or lack thereof) to use database unit testing will be a major factor in influencing whether we end up working together or not.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Are you a database developer doing database unit testing or perhaps even TDD? Let me know in the comments, I'd love to hear about others' experiences.&lt;/p&gt;&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;Yes, that linked-to article from &lt;u&gt;7 years ago&lt;/u&gt; is the best one I 
could find to describe what Visual Studio's Database Unit testing Framework actually is - sort it out Microsoft!&lt;/p&gt;&lt;p&gt;UPDATE: I have just remembered that Jamie Laflen has written an excellent whitepaper entitled &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc164243.aspx" target="_blank"&gt;Apply Test-Driven Development to your Database Projects&lt;/a&gt; that goes into much more detail about how to achieve database TDD using Visual Studio than I have here. Well worth a read. &lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=41327" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/agile/default.aspx">agile</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/DBPro/default.aspx">DBPro</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/TDD/default.aspx">TDD</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Test-Driven+Development/default.aspx">Test-Driven Development</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/unit+testing/default.aspx">unit testing</category></item><item><title>Implementing SQL Server solutions using Visual Studio 2010 Database Projects – a compendium of project experiences</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/01/implementing-sql-server-solutions-using-visual-studio-2010-database-projects-a-compendium-of-project-experiences.aspx</link><pubDate>Sun, 01 Jan 2012 18:13:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40711</guid><dc:creator>jamiet</dc:creator><slash:comments>28</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/40711.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=40711</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=40711</wfw:comment><description>&lt;p&gt;Over the past eighteen months I have worked on four separate projects for customers that wanted to make use of Visual Studio 2010 Database projects to manage their database schema.* All the while I have been trying to take lots of notes in order that I can write the blog post that you are reading right now – a compendium of experiences and tips from those eighteen months. I should note that this blog post should not necessarily be taken as a recommendation to actually &lt;i&gt;use&lt;/i&gt; database projects in Visual Studio 2010 – it is intended to be useful for those of you that have already made the decision to use them; having said that, I do make recommendations as to actions I think you should take if you have made that decision.&lt;/p&gt;  &lt;p&gt;First let’s be clear what we’re talking about here. Visual Studio Database Projects have been known by a few different names down the years, some of which you may be familiar with. If you have ever heard the terms datadude, DBPro, teamdata, TSData or Visual Studio Team System for Database Professionals then just know that all of these terms refer to the same thing, namely the project type highlighted below when starting a new project in Visual Studio:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4302F9CA.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_4079C80C.png" width="748" height="411"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;From here onwards I am going to refer to Visual Studio Database projects and all the features therein simply as datadude because that’s a popular colloquial name (and is also much quicker to type). Know also that at the time of writing the features that I am talking about here are currently undergoing some changes ahead of the next release of SQL Server (i.e. SQL Server 2012) in which these features are mooted to be delivered under a new moniker - SQL Server Developer Tools (SSDT).&lt;/p&gt;  &lt;p&gt;OK, with all those preliminaries out of the way let’s dig in.&lt;/p&gt;  &lt;h1&gt;Continuous Integration&lt;/h1&gt;  &lt;p&gt;&lt;a href="http://www.martinfowler.com/articles/continuousIntegration.html" target="_blank"&gt;Continuous Integration&lt;/a&gt; (CI) is a development practise that has existed for many years but in my experience has not been wholly embraced by the database community. The idea behind CI for databases is that every time a developer checks-in a piece of code be it a stored procedure, a table definition or whatever, the entire database project is built and then deployed to a database instance. Microsoft provide a useful article &lt;a href="http://msdn.microsoft.com/en-us/library/aa833165.aspx" target="_blank"&gt;An Overview of Database Build and Deployment&lt;/a&gt; that goes some way to explaining how to setup your CI deployment.&lt;/p&gt;  &lt;p&gt;CI is one of the fundamental tenets that underpins a lot of the things I talk about later in this blog post and hence gives rise to my first recommendation when using datadude:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #1: Use Source Control and implement a Continuous Integration deployment&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;i&gt;In an earlier draft of this blog post I outlined in detail the CI configuration from one of the aforementioned projects. Its not suitable for inclusion at this point in the current draft but I still think there is some useful information to be gleaned so I have included it below in “Appendix – An example CI configuration”.&lt;/i&gt;&lt;/p&gt;  &lt;h1&gt;Composite Projects&lt;/h1&gt;  &lt;p&gt;Each of the four aforementioned projects were brownfield projects meaning that each already encompassed some established, deployed, databases and they wanted to bring those databases under the control of datadude. Each project had thousands of objects across multiple databases and in this situation it is very likely that some of the stored procedures, views or functions will refer to objects in one of the other databases. The way to resolve those references is to use &lt;a href="http://blogs.msdn.com/b/gertd/archive/2007/07/26/database-references.aspx" target="_blank"&gt;database references&lt;/a&gt; however once you have applied all of your database references it is still very possible that you will run into a situation where code in database A refers to an object in database B while at the same time database B refers to an object in database A. This is depicted in the following figure:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_05B21F36.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2BA7CF8C.png" width="435" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here we have a view [DB1]..[View2] that selects data from [DB2]..[Table1] and a view [DB2]..[View1] that selects data from [DB1]..[Table1]. Datadude does not allow a database reference from [DB2] to [DB1] if there is already a database reference from [DB2] to [DB1] and hence will return an error akin to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SQL03006: View: [dbo].[View1] has an unresolved reference to object [DB1].[dbo].[Table1]. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0395206D.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_096FC406.png" width="574" height="108"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;We have the proverbial chicken-and-egg problem, [DB1] can’t be created before [DB2] and vice versa. This problem is solved by using &lt;i&gt;&lt;b&gt;Composite Projects&lt;/b&gt;&lt;/i&gt; (not to be confused with Partial Projects) which allow you to split objects that are intended to be in the same database over multiple datadude projects. I could go over how you set one of these things up but there’s really no need because there is a rather excellent walkthrough on MSDN at &lt;a href="http://msdn.microsoft.com/en-us/library/dd193415.aspx" target="_blank"&gt;Walkthrough: Partition a Database Project by Using Composite Projects&lt;/a&gt;; the reason for me mentioning it here is to make you aware that composite projects exist and of the problem that they solve. If you are introducing datadude into a brownfield project then it is highly likely that you are going to require composite projects so learn them and learn them good.&lt;/p&gt;  &lt;p&gt;One important last note about composite projects is to answer the question “How does the tool know that the multiple projects refer to the same database?” The answer is given at the walkthrough that I linked to above; namely, it says:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5A3DD86E.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Composite projects - referring to the same database" border="0" alt="Do not specify server variables and values or database variables and values when you define references in a composite project. Because no variables are defined, the referenced project is assumed to share the target server and database of the current project." src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_7509FE7A.png" width="631" height="116"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;i&gt;“Do not specify server variables and values or database variables and values when you define references in a composite project. Because no variables are defined, the referenced project is assumed to share the target server and database of the current project.”&lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So now you know! To put it another way, if you reference one project from another and don’t tell datadude that the two projects refer to different databases then it assumes they refer to the &lt;i&gt;same &lt;/i&gt;database.&lt;/p&gt;  &lt;h1&gt;Code Analysis&lt;/h1&gt;  &lt;p&gt;Datadude provides the ability to analyse your code projects for code in stored procedures and functions that it considers to be inferior and highlight it – this feature is called &lt;b&gt;&lt;i&gt;Code Analysis&lt;/i&gt;&lt;/b&gt;. Note that Code Analysis will not highlight code that is syntactically incorrect (datadude does that already, which may well be considered its core feature), it highlights code that is syntactically correct but may be considered defective when executed. Specifically Code Analysis will highlight the following perceived code defects (click through on the links for explanations of why these are considered code defects):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193296.aspx" target="_blank"&gt;Use of SELECT *&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172121.aspx" target="_blank"&gt;Use of @@IDENTITY rather than SCOPE_IDENTITY()&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193263.aspx" target="_blank"&gt;NCHAR &amp;amp; NVARCHAR fields whose maximum length is 1 or 2&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172122.aspx" target="_blank"&gt;Deprecated join syntax&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172136.aspx" target="_blank"&gt;An output parameter that might not be assigned to&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193269.aspx" target="_blank"&gt;Casts that could result in data loss&lt;/a&gt; (in my experience this is the one that shows up most often – particularly in inherited code) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172134.aspx" target="_blank"&gt;Use of special characters in object names&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193421.aspx" target="_blank"&gt;Use of reserved words&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd172115.aspx" target="_blank"&gt;Use of sp_ prefix for stored procedures&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193249.aspx" target="_blank"&gt;Use of unindexed columns in IN predicates&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193273.aspx" target="_blank"&gt;Use of patterns beginning with a wildcard in a LIKE predicate&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193264.aspx" target="_blank"&gt;Code that would not use an existing index that might actually be beneficial&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193267.aspx" target="_blank"&gt;Use of ISNULL() on nullable columns&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193285.aspx" target="_blank"&gt;Deterministic function calls in a WHERE predicate&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In my opinion the best aspect of Code Analysis is that it can be run as part of your Continuous Integration deployment meaning that if anyone checks in some deficient code, BOOM, your CI deployment fails and the developer is left red-faced. Nothing else has increased the code quality on my projects quite like running Code Analysis as part of a CI deployment.&lt;/p&gt;  &lt;p&gt;Hopefully I have convinced you that turning on Code Analysis is a good idea. If you agree then head to the project properties and check the box labelled &lt;b&gt;Enable Code Analysis on Build&lt;/b&gt;. I also recommend checking the &lt;b&gt;Treat warnings as errors&lt;/b&gt; boxes otherwise you’ll find that &lt;a href="http://www.codinghorror.com/blog/2007/08/discipline-makes-strong-developers.html" target="_blank"&gt;undisciplined developers&lt;/a&gt; will simply ignore the warnings.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0CC135E1.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Enable datadude code analysis" border="0" alt="Enable datadude code analysis" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_129BD97A.png" width="583" height="204"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;i&gt;N.B. Incidentally if you have time I highly recommend that you go and read the blog post I linked to there – &lt;/i&gt;&lt;a href="http://www.codinghorror.com/blog/2007/08/discipline-makes-strong-developers.html" target="_blank"&gt;&lt;i&gt;Discipline Makes Strong Developers&lt;/i&gt;&lt;/a&gt;&lt;i&gt; by Jeff Atwood. I’ve read many thousands of blog posts in my time and that is the one that has influenced me more than any other.&lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Turning on Code Analysis on a greenfield project is a no-brainer. On a brownfield project its not quite so easy – on a recent engagement I moved a single database into datadude and turned on Code Analysis which immediately found over two thousand perceived code defects. I generally abhor the use of that famous maxim &lt;a href="http://en.wikipedia.org/wiki/If_it_ain%27t_broke,_don%27t_fix_it#.22If_it_ain.27t_broke.2C_don.27t_fix_it..22" target="_blank"&gt;if it aint broke, don’t fix it&lt;/a&gt;&lt;i&gt;&lt;/i&gt; in our industry but on occasions like this you may be well advised to heed that advice and leave well alone for fear of breaking code that does what it is supposed to (no matter how inefficiently it does it). Instead you do have the option to suppress Code Analysis warnings/errors:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_434EE125.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="Suppress datadude code analysis" border="0" alt="Suppress datadude code analysis" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_492984BE.png" width="585" height="195"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I advise using Code Analysis suppression sparingly. Recently I discovered that one of the developers on my team had decided it was OK to simply suppress every error that was thrown by Code Analysis without first investigating the cause. I was not amused!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #2: Turn on Code Analysis&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;Realising the value of idempotency&lt;/h1&gt;  &lt;p&gt;An operation is considered idempotent if it produces the same result no matter how many times that operation is applied; for example, multiplication by a factor of one is an idempotent operation – no matter how many times you multiple a number by one the result will always be the same.&lt;/p&gt;  &lt;p&gt;Idempotency is a vital facet of database deployment using datadude. Datadude tries to ensure that no matter how many times you deploy the same project the state of your database should be the same after each deployment. The implication here is that during a deployment datadude will examine the target database to see what changes (if any) need to be made rather than simply attempting to create lots of objects; if all the objects already exist nothing will be done. In my opinion this is the single biggest benefit of using datadude – you don’t have to determine what needs to be done to change your database schema to the desired state, datadude does it for you.&lt;/p&gt;  &lt;p&gt;If I have convinced you about the value of idempotency within datadude then you should also realise that the same rigour should be applied to data as well. Datadude provides Post-Deployment scripts that allow you to deploy data to your schema however there is no inbuilt magic here – datadude will simply go and run those scripts as-is, it will not try and comprehend the contents of those scripts. What this means is that you, the developer, are responsible for making your Post-Deployment scripts idempotent and the easiest way to do that is to employ the T-SQL MERGE statement.&lt;/p&gt;  &lt;p&gt;T-SQL’s INSERT is not sufficient as it will work once and thereafter fail as it will be attempting to insert already inserted data; this gives rise to my third recommendation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #3: When running your deployment in a test environment, run it more than once.&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;No-brainer Recommendations&lt;/h1&gt;  &lt;p&gt;I consider Code Analysis and Idempotency to be so important that I called them out as dedicated headlines. In this section I’ll outline some additional simple measures that you can undertake and which will, if employed correctly, have a profound effect on the success of your datadude projects.&lt;/p&gt;  &lt;h2&gt;Putting a build number into the DB&lt;/h2&gt;  &lt;p&gt;I find it is very useful to maintain a log of deployments that have been made to a database and my chosen method is to use a Post-Deployment script to insert a value into some table. Here’s the definition of the table I use for this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(          &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;50&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;,&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&amp;nbsp;&amp;nbsp;&amp;nbsp; SMALLDATETIME          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;,&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;CONSTRAINT&amp;nbsp; &lt;/span&gt;&lt;span style="color:black;"&gt;PK_dboDeployLog &lt;/span&gt;&lt;span style="color:blue;"&gt;PRIMARY KEY &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;)&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In my Post-Deployment script I will use:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;INSERT &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;());&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;to insert a row into that table during every deployment. &lt;font color="#ff0000"&gt;$(BuildId)&lt;/font&gt; is a variable defined in the .sqlcmdvars file of my project:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0ECE0EDD.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0D8975FE.png" width="293" height="216"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is what we see inside that file:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5E578A66.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_64322DFF.png" width="526" height="219"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The &lt;font color="#ff0000"&gt;$(BuildId)&lt;/font&gt; variable has been defined with a default value of UNKNOWN and hence subsequent deployments from Visual Studio will result in the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5BCE58A8.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0F964EFA.png" width="513" height="284"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;On first glance that might not seem particularly useful however it comes into its own if you are doing CI deployments (see recommendation #1) because each build in a CI environment will result in a new build identifier. The following command-line call to vsdbcmd.exe is how deployments are generally done using datadude, note the presence of the &lt;b&gt;/p:BuildId&lt;/b&gt; switch:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;..\Tools\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:"Data Source=.;Integrated Security=True;Pooling=False" &lt;b&gt;/p:BuildId="some-value"&lt;/b&gt; /DeployToDatabase:+ /ManifestFile:.\FinanceDB\sql\release\FinanceDB.deploymanifest&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Your CI tool should be able to replace “some-value” with an identifier for the current build (that’s outside the scope of this blog post but any CI tool worth its salt will be able to do this) – when the deployment executes that value will then make its way into your [dbo].[DeployLog] table and you will have a self-maintaining history of all the deployments (datetime &amp;amp; build identifier) that have been made to your database.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #4: Maintain an automated history of your deployments&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Use Schema View&lt;/h2&gt;  &lt;p&gt;It is natural to navigate through all of the objects in your database project using Solution Explorer however datadude provides a better mechanism for doing just that – the Schema View window.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_6E36A95D.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_781B9AC8.png" width="250" height="304"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Schema View provides a logical view of all the objects defined in your database project regardless of which file they may be defined in. That is very useful for many reasons, not least because it makes it easy to locate whichever object you are after – that’s advantageous if multiple objects are defined in the same file. Moreover if some files have property BuildAction=”Not In Build” (see later) they won’t show up in Schema View (this is a good thing by the way). Schema View is also the place that operations such as refactoring and dependency analysis are launched from.&lt;/p&gt;  &lt;p&gt;Some people think that it is important that the name of each file in a datadude project should accurately reflect the object defined within. I disagree; object renames mean that maintaining the filenames becomes laborious and having the Schema View means you never have to use the filenames to navigate your project anyway.&lt;/p&gt;  &lt;p&gt;One final reason to use Schema View is the External Elements button:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_04A947E5.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6349A248.png" width="356" height="152"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Toggling this button on means that objects in referenced projects show up in the project that they are referenced from (this is particularly useful if you are using Composite Projects). Note in the following screenshot how the object [dbo].[t1] in project Database2 appears in the [dbo] schema of Database3 – that’s because Database3 has a reference to Database2.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_62050969.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_47586D50.png" width="243" height="439"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;For those reasons my fifth recommendation is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #5: Use Schema View in preference to Solution Explorer&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You will still need Solution Explorer to navigate files that do not contain database objects (e.g. Post-Deployment scripts) but ordinarily you should spend most of your time interacting with Schema View.&lt;/p&gt;  &lt;h2&gt;Make liberal use of PRINT statements in Pre/Post-Deployment Scripts&lt;/h2&gt;  &lt;p&gt;When you deploy a datadude project datadude will take care of telling you what it is up to. For example, the following screenshot shows the output from deploying the already discussed [dbo].[DeplogLog]:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_11074541.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_68F49621.png" width="479" height="117"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Of course it only does this for objects that it knows about and that doesn’t include anything in your Pre or Post \deployment scripts so you need to take responsibility for outputting pertinent information from those scripts. Here I have amended the script that inserts into [dbo].[DeployLog]:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;INSERT &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[DeployLog]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildId]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;[DeployDatetime]&lt;/span&gt;&lt;span style="color:gray;"&gt;)          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;());          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:magenta;"&gt;CAST&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span&gt;@@ROWCOUNT &lt;/span&gt;&lt;span style="color:blue;"&gt;as NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;5&lt;/span&gt;&lt;span style="color:gray;"&gt;)) + &lt;/span&gt;&lt;span style="color:red;"&gt;N'rows inserted into [dbo].[DeployLog], BuildId=$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This gives us much more useful output:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_159D4FFB.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_46BC8A9B.png" width="475" height="122"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Adding PRINT statements to your Pre &amp;amp; Post Deployment scripts is so easy it really is a no-brainer and hence my next recommendation is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #6: Any action in a Pre or Post-Deployment Script should use PRINT to state what has been done&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Output variable values in your Pre-Deployment script&lt;/h2&gt;  &lt;p&gt;This is in the same vein as the previous bullet-point – output as much information as is possible. In this case we’re talking about outputting the values of all variables that are stored in the .sqlcmdvars file; first, a reminder of what’s in that file:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_73654474.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5924DB50.png" width="526" height="219"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is the contents of my amended Pre-Deployment Script:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DefaultDataPath=$(DefaultDataPath)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DatabaseName=$(DatabaseName)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'DefaultLogPath=$(DefaultLogPath)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'BuildId=$(BuildId)'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And the resultant output:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_22D3B341.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_3D9FD94D.png" width="568" height="119"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This is the sort of simple amendment that will pay off in spades later in your project (especially if you are supplying many values from the command-line) and again, its so easy to do it there really is no reason not to. Just remember to update your Pre-Deployment script whenever you add new variables to .sqlcmdvars.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #7: Output the value of all variables in your Pre-Deployment script&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;One Object Per File&lt;/h2&gt;  &lt;p&gt;Datadude doesn’t restrict what can go in a file, for example the following file, “t.table.sql”, defines three objects; a table, a primary key and a view:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_75721D70.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_1B67CDC7.png" width="352" height="248"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Even though they’re all defined in the same file they show up in Schema View separately (one of the aforementioned benefits of using Schema View):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_6C35E22F.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_3D03F698.png" width="314" height="355"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That said, just because you can doesn’t mean that you should. I prefer to go for one object per file for the simple reason that its easier to track the history of an object via Source Control. Moreover, if an object is no longer required then it is a simple change to just remove the file containing that object from the build (see “Don’t delete anything from your project” later) as opposed to editing a file to remove all traces of an object.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #8: Each database object should be defined in a dedicated file&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Time your Pre and Post Deployment Scripts&lt;/h2&gt;  &lt;p&gt;Its always useful to know where time is spent when doing deployments, in my experience the majority of time spent is in the Post-Deployment script (your mileage may vary of course). An easy win is to output the time taken to run your Pre and Post Deployment scripts. Adapt your Pre-Deployment script so that it looks something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE &lt;/span&gt;&lt;span&gt;@vPreDeploymentStartTime &lt;/span&gt;&lt;span style="color:blue;"&gt;DATETIME = &lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;();          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'****************Begin Pre-Deployment script at ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;30&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;(),&lt;/span&gt;&lt;span style="color:black;"&gt;120&lt;/span&gt;&lt;span style="color:gray;"&gt;) + &lt;/span&gt;&lt;span style="color:red;"&gt;'***********************'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;         &lt;br&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;/*Call other scripts from here using SQLCMD's :r syntax          &lt;br&gt;Example:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :r .\myfile.sql&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;br&gt;*/           &lt;br&gt;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'Pre-Deployment duration = ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;5&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;DATEDIFF&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;ss&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span&gt;@vPreDeploymentStartTime&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;())) + &lt;/span&gt;&lt;span style="color:red;"&gt;' seconds'&lt;/span&gt;&lt;span style="color:gray;"&gt;;          &lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;PRINT &lt;/span&gt;&lt;span style="color:red;"&gt;'****************End Pre-Deployment script at ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+&lt;/span&gt;&lt;span style="color:magenta;"&gt;CONVERT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;30&lt;/span&gt;&lt;span style="color:gray;"&gt;),&lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;(),&lt;/span&gt;&lt;span style="color:black;"&gt;120&lt;/span&gt;&lt;span style="color:gray;"&gt;) + &lt;/span&gt;&lt;span style="color:red;"&gt;'***********************'&lt;/span&gt;&lt;span style="color:gray;"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;then do similar for your Post-Deployment script. When you deploy your output will include the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_3BBF5DB9.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_217EF495.png" width="593" height="201"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Note the lines:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************Begin Pre-Deployment script at 2011-12-31 20:00:34***********************        &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pre-Deployment duration = 0 seconds         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************End Pre-Deployment script at 2011-12-31 20:00:34***********************         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************Begin Post-Deployment script at 2011-12-31 20:00:34***********************        &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Post-Deployment duration = 0 seconds         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ****************End Post-Deployment script at 2011-12-31 20:00:34***********************&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In this particular case its not all that useful to know that the deployment took 0 seconds but if and when your deployments snowball to many minutes it will be useful to know how long your scripts are taking at which point you can investigate further by timing each individual step in your Pre and Post Deployment scripts.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #9: Time your deployments and output the timings&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Use sqlcmdvars and the command-line as much as possible&lt;/h2&gt;  &lt;p&gt;Hardcoding any value into a piece of code is a fraught practise; you should assume that values previously thought to be constant may not be so in the future. You can protect yourself from future changes by storing all literal values as variables in your .sqlcmdvars file. Sure, you can supply default values for those variables but you have the added advantage that they can be overridden from the command-line when deploying using &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx" target="_blank"&gt;vsdbcmd.exe&lt;/a&gt;. Moreover, if you have values that are hardcoded in multiple places in your code then specifying those values in .sqlcmdvars ensures that your code adheres to the principle of &lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank"&gt;DRY&lt;/a&gt;. Lastly, if values are stored in the .sqlcmdvars file then you can output them at deploy time (see recommendation #7).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #10: All literal values should be stored in your .sqlcmdvars file&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Every developer gets their own development database&lt;/h2&gt;  &lt;p&gt;In most SQL Server development shops that I’ve been on all developers work against a single centralised development database. To me this is an antiquated way of working because its possible that work one person is doing can conflict with that of someone else, I find it much better for every developer to work in isolation and then use the CI deployment to check that one’s code is not in conflict with anyone else’s. Datadude supports (nay encourages) this way of working with the notion of an Isolated Development Environment:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_79001280.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0CACFC15.png" width="541" height="172"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Every developer should configure their isolated development environment which, typically, would be their local instance. And so to my next recommendation:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #11: Every developer should use the Isolated Dev Environment settings in order to author their code&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Incidentally, if every developer has their own development database and you are following my earlier recommendation to use a [DeployLog] table then you can track how often a developer is bothering to deploy and test their code. On a recent project we used this evidence in a (ahem) &lt;i&gt;discussion&lt;/i&gt; with a developer who tried to convince us that he was testing his code sufficiently even though he was repeatedly causing the CI deployment to fail.&lt;/p&gt;  &lt;h2&gt;Don’t delete anything from your project&lt;/h2&gt;  &lt;p&gt;When projects are no longer required in your database then intuitively it makes sense to remove the file containing that object from the datadude project, I would however like to suggest a different approach. Rather than removing a file just change the Build property to “Not in Build”:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0B686336.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_114306CF.png" width="330" height="293"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This has the advantage that your project maintains some semblance of history of what objects have been removed from your database – that can be useful to anyone inheriting your code in the future.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #12: Use “Not in Build” to remove an object from your database&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Build and Deploy your datadude projects outside of Visual Studio&lt;/h2&gt;  &lt;p&gt;Building and deploying your datadude projects within Visual Studio can become a real time hog; in my experience its not unusual for deployments to take many minutes and your Visual Studio environment will be unavailable for further development work during that time. For that reason I recommend investing some time in writing some msbuild scripts that will build and deploy your project(s) from the command-line. Here are some examples that you can adapt for your own use, firstly a script to build a solution:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;white-space:nowrap;"&gt;&lt;span&gt;&amp;lt;?&lt;/span&gt;&lt;span&gt;xml&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;version&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;1.0&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;encoding&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;utf-8&lt;/span&gt;"&lt;span&gt;?&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;!--&lt;/span&gt; &lt;span&gt;Execute using:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;msbuild SolutionBuild.proj&lt;/span&gt;       &lt;br&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Project&lt;/span&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/span&gt;"       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;DefaultTargets&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; When doing .net development Visual Studio Configurations are particularly useful because they can affect&lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;how the code is executed (i.e. under the Debug configuration&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; debug symbols can be used to step through the code (something like that anyway - I don't know too much about that &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;stuff).&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In DBPro, Configurations are less relevant because there is no such thing as debugging symbols. Nonetheless, they &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;can still be useful&lt;/span&gt; &lt;span&gt;for times when you want to do different things (e.g. you might want to run Code Analysis in &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;a debug situation but not in a release&lt;/span&gt;       &lt;span&gt;situation. There is a useful thread on this here: &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;"Debug vs Release" http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/a0ec0dc0-a907-45ba-a2ea-d2f0175261a7&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note that Visual Studio Configurations should not be used to maintain different settings per environment. &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;The correct way to do that is to maintain&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seperate .sqlcmdvars files per environment and then choose which one to use at deployment time when using&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vsdbcmd.exe (use syntax "/p:SqlCommandVariablesFile=$(ProjectName)_$(Environment).sqlcmdvars")&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;List all the configurations here that you want to build&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Config&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Debug&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Config&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Release&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Building %(Config.Identity) configuration...&lt;/span&gt;"&lt;span&gt;/&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;.\Lloyds.UKTax.DB.sln&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Properties&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Configuration=%(Config.Identity)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt; &lt;span&gt;Project&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;and secondly a script that will deploy a datadude project:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;white-space:nowrap;"&gt;&lt;span&gt;&amp;lt;?&lt;/span&gt;&lt;span&gt;xml&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;version&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;1.0&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;encoding&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;utf-8&lt;/span&gt;"&lt;span&gt;?&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;lt;!--&lt;/span&gt; &lt;span&gt;Execute using:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;msbuild SolutionDeploy.proj /Target:Deploy&lt;/span&gt;       &lt;br&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Project&lt;/span&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;xmlns&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/span&gt;"      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;DefaultTargets&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build;Deploy&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;PropertyGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;At time of writing I don't see a reason for anything else to be used but that may change in the future hence why this &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;is a property and hence can be overriden.&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Configuration&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Debug&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Configuration&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DevServer&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Data Source=GBS0039182\GLDDEV01;Integrated Security=True;Pooling=False&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DevServer&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;PropertyGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;ProjectToBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;SolutionBuild.proj&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add a &amp;lt;DbProj&amp;gt; item for every database project (.dbproj) that needs to be deployed. They will get deployed in the &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;order that they are listed&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thus it is your responsibility to make sure they are listed in the correct order (respecting dependency order).&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Identity is a metadata reference. It refers to the name of the item (i.e. Include="The bit that goes here is the &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;identity")&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note also that whatever you put for Include is important. Include="dev_thomsonj" means the project will only get &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;deployed if the&lt;/span&gt;       &lt;span&gt;deployment is being executed by username=dev_thomsonj&lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DbProj&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Include&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;username&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DbName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;MyDB&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DbName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;ProjectName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;MySoln.MyDB&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;ProjectName&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;OutputPath&lt;/span&gt;&lt;span&gt;&amp;gt;\&lt;/span&gt;%(ProjectName)\sql\$(Configuration)\\cf1 &amp;lt;/&lt;span&gt;OutputPath&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;DeployConnStr&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;Data Source=localhost;Integrated Security=True;Pooling=False&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;DeployConnStr&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;DbProj&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;ItemGroup&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Build&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;@(ProjectToBuild)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Deploy&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&lt;/span&gt; &lt;span&gt;Notes:&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 09 is the hex code for TAB, hence all of the %09 references that you can see. See http://asciitable.com/ &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;for more details.&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt; &lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;USERNAME=$(USERNAME)&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;'%(DbProj.Identity)'==$(USERNAME)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Deploying:&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Project%09%09%09:&amp;nbsp; %(DbProj.ProjectName)&amp;nbsp;&amp;nbsp; &lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DbName%09%09%09:&amp;nbsp; %(DbProj.DbName)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From OutputPath%09%09:&amp;nbsp; %(DbProj.OutputPath)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To ConnStr%09%09:&amp;nbsp; %(DbProj.DeployConnStr)&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; By%09%09%09:&amp;nbsp; %(DbProj.Identity)&lt;/span&gt;"      &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;'%(DbProj.Identity)'==$(USERNAME)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;$(VSINSTALLDIR)\vstsdb\deploy\vsdbcmd.exe&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/Action:Deploy /ConnectionString:&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;%(DbProj.DeployConnStr)&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; /DeployToDatabase+ &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/manifest:&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;.%(DbProj.OutputPath)%(DbProj.ProjectName).deploymanifest&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt; /p:TargetDatabase=%(DbProj.DbName) &lt;br&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;/p:Build=&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;&lt;span&gt;from cmd line&lt;/span&gt;&lt;span&gt;&amp;amp;quot;&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;      &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt; &lt;span&gt;Target&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt; &lt;span&gt;Project&lt;/span&gt; &lt;span&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Writing these scripts may appear to be laborious but they’ll save you heaps of time in the long run.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="4"&gt;Recommendation #13: Build and deploy to your development sandbox using scripts&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;i&gt;UPDATE: Upon reading this blog post Mordechai Danielov wrote a follow-up in which he published a useful script that builds a series of projects using Powershell. Its at &lt;/i&gt;&lt;a href="http://bitwisemnm.com/2012/01/03/building-your-database-solutions-outside-of-visual-studio/" target="_blank"&gt;&lt;i&gt;building your database solutions outside of Visual Studio&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;  &lt;h1&gt;Useful links&lt;/h1&gt;  &lt;p&gt;Over the years I’ve collected some links to MSDN articles that have proved invaluable:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193409.aspx" target="_blank"&gt;Build and Deploy Databases to an Isolated Development Environment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa833165.aspx#CommunityContent" target="_blank"&gt;An Overview of Database Build and Deployment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dvdarchive/cc164243.aspx" target="_blank"&gt;Apply Test-Driven Development to your Database Projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193415.aspx" target="_blank"&gt;Walkthrough: Partition a Database Project by Using Composite Projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bahill/archive/2009/03/23/right-sizing-the-master-dbschema-file-for-better-design-time-performance.aspx" target="_blank"&gt;Right sizing the master.dbschema file for better design time performance&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dd483214.aspx#id0100036" target="_blank"&gt;Referencing for Shared Server-Level Objects&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx" target="_blank"&gt;How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD.EXE&lt;/a&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Datadude bugs&lt;/h1&gt;  &lt;p&gt;Like any substantial piece of software datadude is not without bugs. Many of the issues I have found are concerned with the datadude interpreter not correctly parsing T-SQL code, here’s a list of some bugs that I have found down the years:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/688259/refactor-rename-in-schema-view-crashes-visual-studio" target="_blank"&gt;Under certain circumstances a Refactor-&amp;gt;Rename operation can crash Visual Studio&lt;/a&gt; (followed up &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/705676/would-like-feedback-on-a-bug-that-has-been-closed-as-wont-fix" target="_blank"&gt;here&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/674391/datadude-valid-merge-syntax-causes-warnings#details" target="_blank"&gt;Valid T-SQL MERGE syntax can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/668651/datadude-refactoring-applies-the-wrong-edits-to-unit-tests" target="_blank"&gt;Refactor-&amp;gt;Rename doesn’t work properly for database unit tests&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/657580/datadude-deploy-failure-something-to-do-with-triggers#details" target="_blank"&gt;Removal of triggers from your datadude project may, under certain circumstances, cause a failed deployment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/635058/datadude-derived-table-with-the-same-alias-as-one-of-the-columns-in-that-derived-table-incorrectly-causes-a-warning#details" target="_blank"&gt;Rare naming circumstance can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/624876/datadude-t-sql-parser-throws-warnings-for-valid-t-sql#details" target="_blank"&gt;Valid function definition containing a CTE can cause false warnings&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/606656/datadude-datadude-attempts-to-deploy-a-default-constraint-before-deploying-the-function-referenced-by-that-constraint" target="_blank"&gt;A default constraint is attempted to be deployed before a function referenced by that constraint – hence an error occurs&lt;/a&gt; (confirmed as fixed in VS2010 SP1) &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/605544/datadude-failure-to-recognise-operand-type-clash-when-using-table-types#details" target="_blank"&gt;Datadude doesn’t catch a type mismatch between a table-valued-parameter and a parameter passed to it&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/594309/datadude-datetime2-data-generator-doesnt-generate-unique-values-when-the-column-is-part-of-a-composite-key" target="_blank"&gt;DateTime2 Data generator doesn't generate unique values when the column is part of a composite key&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/592932/datadude-certain-db-unit-test-class-names-can-throw-errors-when-the-class-is-created" target="_blank"&gt;Unit test class files cannot contain periods&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/586040/datadude-valid-create-view-syntax-throws-errors#details" target="_blank"&gt;Valid CREATE VIEW definition throws errors&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/573824/datadude-unexplained-warnings-from-dbproj-project" target="_blank"&gt;MERGE syntax in a stored procedure creates false warnings&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Some of these bugs were reported a long time ago and may well have been fixed in later service packs.&lt;/p&gt;  &lt;h1&gt;Previous datadude blog posts&lt;/h1&gt;  &lt;p&gt;I have &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx" target="_blank"&gt;blogged on datadude&lt;/a&gt; quite a bit in the past:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/11/21/workaround-for-datadude-deployment-bug.aspx"&gt;Workaround for datadude deployment bug – NullReferenceException&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/02/10/building-a-database-installer-with-wix-datadude-and-visual-studio-2010.aspx"&gt;Building a database installer with WiX, datadude and Visual Studio 2010&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/19/generate-multiple-sqlcmdvars-vars-in-your-database-projects.aspx"&gt;Generate multiple SqlCmdVars files in your database projects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/17/querying-visual-studio-project-files.aspx"&gt;Querying Visual Studio project files using T-SQL and Powershell&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/19/maintaining-version-history-in-your-database-using-visual-studio-2010.aspx"&gt;Maintaining version history in your database using Visual Studio 2010&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/06/enforcing-naming-conventions-using-database-unit-testing.aspx"&gt;Enforcing naming conventions using database unit testing&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/18/experiences-from-writing-sp-cascadingdataviewer-db-unit-testing-and-code-distribution.aspx"&gt;Experiences from writing sp_CascadingDataViewer – DB unit testing and code distribution&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/14/some-thoughts-on-visual-studio-database-references-and-how-they-should-be-used-for-sql-server-bi.aspx"&gt;Some thoughts on Visual Studio database references and how they should be used for SQL Server BI&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/23/microsoft-publish-visual-studio-2010-database-project-guidance.aspx"&gt;Microsoft publish Visual Studio 2010 Database Project Guidance&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/20/setting-up-database-unit-testing-as-part-of-a-continuous-integration-build-process-vs2010-db-tools-datadude.aspx"&gt;Setting up database unit testing as part of a Continuous Integration build process [VS2010 DB Tools - Datadude]&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/07/21/a-strategy-for-managing-security-for-different-environments-using-the-database-development-tools-in-visual-studio-2010.aspx"&gt;A strategy for managing security for different environments using the Database Development Tools in Visual Studio 2010&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Summing up&lt;/h1&gt;  &lt;p&gt;This has been an inordinately large blog post so if you’ve read this far – well done. For easy reference, here are all the recommendations that I have made:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Use Source Control and implement a Continuous Integration deployment &lt;/li&gt;    &lt;li&gt;Turn on Code Analysis &lt;/li&gt;    &lt;li&gt;When running your deployment in a test environment, run it more than once &lt;/li&gt;    &lt;li&gt;Maintain an automated history of your deployments &lt;/li&gt;    &lt;li&gt;Use Schema View in preference to Solution Explorer &lt;/li&gt;    &lt;li&gt;Any action in a Pre or Post-Deployment Script should use PRINT to state what has been done &lt;/li&gt;    &lt;li&gt;Output the value of all variables in your Pre-Deployment script &lt;/li&gt;    &lt;li&gt;Each database object should be defined in a dedicated file &lt;/li&gt;    &lt;li&gt;Time your deployments and output the timings &lt;/li&gt;    &lt;li&gt;All literal values should be stored in your .sqlcmdvars file &lt;/li&gt;    &lt;li&gt;Every developer should use the Isolated Dev Environment settings in order to author their code &lt;/li&gt;    &lt;li&gt;Use “Not in Build” to remove an object from your database &lt;/li&gt;    &lt;li&gt;Build and deploy to your development sandbox using scripts &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I really hope this proves useful because its taken a good long while to get it published &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_68C424BA.png"&gt; If you have any feedback then please let me know in the comments.&lt;/p&gt;  &lt;p&gt;Thanks for reading!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;* When I started writing this blog post the first sentence was “Over the past six months I have worked on two separate projects for customers that wanted to make use of Visual Studio 2010 Database projects to manage their database schema.” as opposed to what it is now: “Over the past eighteen months I have worked on four separate projects…” Yes, that’s how long its taken to write it! &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_68C424BA.png"&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;/i&gt;&lt;/p&gt;      &lt;h1&gt;Appendix – An example CI configuration&lt;/h1&gt;  &lt;p&gt;&lt;i&gt;As stated above, an earlier draft of this blog post included full details of the CI configuration from one of the projects that I have worked on. Although it may repeat some of what has already been said I have included that text below.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;==============================================================&lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;This project has invested heavily in using a Continuous Integration (CI) approach to development. What that means, succinctly, is that whenever someone checks-in some code to our source control system an automated build process is kicked off that constructs our entire system from scratch on a dedicated server. CI is not a new concept but it is fairly rare that anyone applies the same rigour to their database objects as they do to so-called “application code” (e.g. the stuff written in .Net code) and on this project we have made a conscious decision to properly build our databases as part of the CI build.&lt;/p&gt;  &lt;p&gt;Datadude employs a &lt;i&gt;declarative&lt;/i&gt; approach to database development. In other words you define what you want database schema to look like and datadude will work out what it needs to do to your target in order to turn it into what you have defined. What this means in practice is that you only ever write CREATE … DDL statements rather than IF &amp;lt;object-exists&amp;gt; THEN ALTER …ELSE CREATE … statements which is what you may have done in the past.&lt;/p&gt;  &lt;p&gt;Here’s our CI environment setup:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SubVersion (SVN) is being used for source control &lt;/li&gt;    &lt;li&gt;&lt;a href="http://hudson-ci.org/"&gt;Hudson&lt;/a&gt;, an open source CI server, is being used to orchestrate our whole CI environment. It basically monitors our SVN repository and when it spots a checked-in file, kicks off the CI build &lt;/li&gt;    &lt;li&gt;Our CI scripts (the stuff that actually does the work) are written using &lt;a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx"&gt;msbuild&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;We have 2 msbuild scripts:      &lt;ul&gt;       &lt;li&gt;Build.proj which is responsible for:          &lt;ul&gt;           &lt;li&gt;Compiling all our .Net website code &lt;/li&gt;            &lt;li&gt;Building/Compiling our datadude projects&amp;nbsp; (every datadude project file is a msbuild-compliant script) &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Deploy.proj which is responsible for:          &lt;ul&gt;           &lt;li&gt;Restoring latest database backups from our production environment into our CI environment &lt;/li&gt;            &lt;li&gt;Deploying our built datadude projects on top of those restored backups &lt;/li&gt;            &lt;li&gt;Build a folder structure to hold all the artefacts that get deployed &lt;/li&gt;            &lt;li&gt;Creating folder shares &lt;/li&gt;            &lt;li&gt;Moving SSIS packages into folder structure &lt;/li&gt;            &lt;li&gt;Deploying SSRS reports to our SSRS server &lt;/li&gt;            &lt;li&gt;Deploy our Analysis Services cube definitions to our Analysis Server &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Both Build.proj and Deploy.proj get executed by our CI build &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Building datadude projects&lt;/h2&gt;  &lt;p&gt;Datadude makes it very easy to build datadude projects in a CI environment because they are already msbuild-compliant; its simply a call to the MSBuild task, passing in the location of the solution file as an argument. We use the Release configuration (although there is no particular reason for you to do the same – purely your choice):&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Database&lt;/span&gt;"&lt;span&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;!--&lt;/span&gt;&lt;span&gt;Build database projects and copy output to staging &lt;/span&gt;&lt;span&gt;--&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;Message&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Text&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;*****Building database solution&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span&gt;MSBuild&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Projects&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;..\src\SQL\DatabaseSolution.sln&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Properties&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;Configuration=Release&lt;/span&gt;"&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;/&lt;/span&gt;&lt;span&gt;Target&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That’s it! The output from a datadude build includes a number of files but the most important one is a .dbschema file which is an XML representation of all the objects in your database.&lt;/p&gt;  &lt;h2&gt;Deploying the output from a built datadude project&lt;/h2&gt;  &lt;p&gt;This is a little more difficult. We *&lt;b&gt;could&lt;/b&gt;* simply use the MSBuild task to call our deployment script as we do for build script (see above) but the problem with that is that there are many pre-requisites (including datadude itself) and we don’t want to install Visual Studio and all the assorted paraphernalia onto our various environments. Instead we chose to make use of a command-line tool called &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx"&gt;VSDBCMD.exe&lt;/a&gt; to deploy datadude projects. VSDBCMD does basically the same job as what happens if you were to right-click on a datadude project in Visual Studio and select “Deploy” i.e. It compares the output of a build (A) to the target database (B) and works out what it needs to do to make B look like A. It then produces a .sql script that will actually make those requisite changes, then goes and executes it.&lt;/p&gt;  &lt;p&gt;The difficulty comes in VSDBCMD.exe having its own list of file dependencies that are listed at MSDN article &lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx"&gt;How to: Prepare a Database for Deployment From a Command Prompt by Using VSDBCMD.EXE&lt;/a&gt;, thankfully a much smaller list then if we were using the MSBuild task.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_334B6295.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_11EBBCF9.png" width="581" height="389"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Some of those files, namely:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Sqlceer35en.dll &lt;/li&gt;    &lt;li&gt;Sqlceme35.dll &lt;/li&gt;    &lt;li&gt;Sqlceqp35.dll &lt;/li&gt;    &lt;li&gt;Sqlcese35.dll &lt;/li&gt;    &lt;li&gt;System.Data.SqlServerCe.dll &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;get installed with SQL Server CE. We bundle along the x86 &amp;amp; x64 installers for SQL Server CE along with all the rest of our deployment artefacts and then, as part of Deploy.proj, install them like so:&lt;/p&gt;  &lt;div style="font-size:10pt;"&gt;   &lt;div style="padding:2px 5px;overflow:auto;"&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;'&lt;span&gt;msiexec /passive /l* "$(SetupLogDirectory)\SSCERuntime_x86-ENU.log" /i "$(BuildDir)\Vendor\SSCERuntime_x86-ENU.msi"&lt;/span&gt;'&lt;span&gt; /&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Exec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Condition&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;"&lt;span&gt;$(X64)&lt;/span&gt;"&lt;span&gt; &lt;/span&gt;&lt;span&gt;Command&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;'&lt;span&gt;msiexec /passive /l* "$(SetupLogDirectory)\SSCERuntime_x64-ENU.log" /i "$(BuildDir)\Vendor\SSCERuntime_x64-ENU.msi"&lt;/span&gt;'&lt;span&gt; /&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That takes care of some of the dependencies but we still have to take care of:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DatabaseSchemaProviders.Extensions.xml &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.ScriptDom.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.ScriptDom.Sql.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Data.Schema.Sql.dll &lt;/li&gt;    &lt;li&gt;Microsoft.SqlServer.BatchParser.dll &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;as well as the actual VSDBCMD.exe file itself. Quite simply we keep those files in SVN and then bundle them along with all our deployment artefacts (I won’t show you how we do that because its out of the scope of this post and besides if you’re at all proficient with msbuild then you’ll know how to do that and if you’re not, well, why are you reading this?)&lt;/p&gt;  &lt;p&gt;&lt;i&gt;==============================================================&lt;/i&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=40711" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Continuous+Integration/default.aspx">Continuous Integration</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/DBPro/default.aspx">DBPro</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item><item><title>Workaround for datadude deployment bug - NullReferenceException</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/11/21/workaround-for-datadude-deployment-bug.aspx</link><pubDate>Mon, 21 Nov 2011 08:56:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39903</guid><dc:creator>jamiet</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/39903.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=39903</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=39903</wfw:comment><description>
&lt;p&gt;I have come across a bug in Visual Studio 2010 Database Projects (&lt;a href="http://www.sqlservercentral.com/questions/tags/visual+studio/" target="_blank"&gt;aka datadude aka DPro aka Visual Studio Database Development Tools aka Visual Studio Team Edition for Database Professionals aka Juneau aka SQL Server Data Tools&lt;/a&gt;) that other people may encounter so, for the purposes of googling, I'm writing this blog post about it. Through my own googling I discovered that a Connect bug had already been raised about it (&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/693158/vs2010-database-project-deploy-sqldeploytask-task-failed-unexpectedly-nullreferenceexception#details" target="_blank"&gt;VS2010 Database project deploy - “SqlDeployTask” task failed unexpectedly, NullReferenceException&lt;/a&gt;), and coincidentally enough it was raised by my former colleague Tom Hunter (whom I have &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/11/25/sql-server-2008-sp1-cu-6-includes-small-changes-to-dtsx-files.aspx" target="_blank"&gt;mentioned here before as the superhuman Tom Hunter&lt;/a&gt;) although it has not (at this time) received a reply from Microsoft. Tom provided a repro, namely that this syntactically valid function definition:&lt;/p&gt;
&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE FUNCTION &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[Function1]&lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;()&lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;RETURNS TABLE&lt;br&gt;AS&lt;br&gt;RETURN &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;WITH &lt;/span&gt;&lt;span style="color:black;"&gt;cte &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[c1]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;[$(Database3)].[dbo].[Table1]&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:gray;"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[c1]&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;cte&lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;/code&gt;

&lt;p&gt;would produce this nasty unhelpful error upon deployment:&lt;br&gt;&lt;/p&gt;
&lt;font color="red"&gt;
&lt;p&gt;C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error MSB4018: The "SqlDeployTask" task failed unexpectedly.&lt;br&gt;&lt;span style="font-weight:bold;"&gt;System.NullReferenceException: Object reference not set to an instance of an object&lt;/span&gt;.&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Sql.SchemaModel.SqlModelComparerBase.VariableSubstitution(SqlScriptProperty propertyValue, IDictionary`2 variables, Boolean&amp;amp; isChanged)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Sql.SchemaModel.SqlModelComparerBase.ArePropertiesEqual(IModelElement source, IModelElement target, ModelPropertyClass propertyClass, ModelComparerConfiguration configuration)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareProperties(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonChangeDefinition changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition&amp;amp; changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareChildren(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareParentElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes, Boolean isComposing)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition&amp;amp; changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareChildren(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareParentElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes, Boolean isComposing)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition&amp;amp; changes)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareAllElementsForOneType(ModelElementClass type, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean compareOrphanedElements)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareStore(ModelStore source, ModelStore target, ModelComparerConfiguration configuration)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Build.SchemaDeployment.CompareModels()&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Build.SchemaDeployment.PrepareBuildPlan()&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Build.SchemaDeployment.Execute(Boolean executeDeployment)&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Build.SchemaDeployment.Execute()&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Data.Schema.Tasks.DBDeployTask.Execute()&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()&lt;br&gt;&amp;nbsp;&amp;nbsp; at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean&amp;amp; taskResult)&lt;br&gt;&amp;nbsp;&amp;nbsp; Done executing task "SqlDeployTask" -- FAILED.&lt;br&gt;&amp;nbsp; Done building target "DspDeploy" in project "Lloyds.UKTax.DB.UKtax.dbproj" -- FAILED.&lt;br&gt;&amp;nbsp;Done executing task "CallTarget" -- FAILED.&lt;br&gt;Done building target "DBDeploy" in project &lt;br&gt;&lt;/p&gt;
&lt;/font&gt;
&lt;p&gt;It turns out there are a certain set of circumstances that need to be met for this error to occur:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The object being deployed is an inline function&amp;nbsp; (may also exist for multistatement and scalar functions - I haven't tested that)&lt;br&gt;&lt;/li&gt;

&lt;li&gt;That object includes SQLCMD variable references&lt;/li&gt;

&lt;li&gt;The object has already been deployed successfully&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just to reiterate that last bullet point, the error does not occur when you deploy the function for the first time, only on the subsequent deployment.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Luckily I have a direct line into a guy on the development team so I fired off an email on Friday evening and today (Monday) I received a reply back telling me that there is a simple fix, one simply has to remove the parentheses that wrap the SQL statement. So, in the case of Tom's repro, the function definition simply needs to be changed to:&lt;/p&gt;
&lt;p&gt;
&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE FUNCTION &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[Function1]&lt;br&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;()&lt;br&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;RETURNS TABLE&lt;br&gt;AS&lt;br&gt;RETURN &lt;/span&gt;&lt;span style="color:green;"&gt;--(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;WITH &lt;/span&gt;&lt;span style="color:black;"&gt;cte &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[c1]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;[$(Database3)].[dbo].[Table1]&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:gray;"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[c1]&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:black;"&gt;cte&lt;br&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;--) &lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;I have commented out the offending parentheses rather than removing them just to emphasize the point.
&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Thereafter the function will deploy fine. I tested this out on my own project this morning and can confirm that this fix does indeed work.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;I have been told that the bug CAN be reproduced in the Release Candidate (RC) 0 build of SQL Server Data Tools in SQL Server 2012 so am hoping that a fix makes it in for the Release-To-Manufacturing (RTM) build.&lt;/p&gt;

&lt;p&gt;Hope this helps&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@jamiet&lt;/a&gt; &lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=39903" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/DBPro/default.aspx">DBPro</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/juneau/default.aspx">juneau</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item><item><title>Building a database installer with WiX, datadude and Visual Studio 2010</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/02/10/building-a-database-installer-with-wix-datadude-and-visual-studio-2010.aspx</link><pubDate>Thu, 10 Feb 2011 21:45:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:33387</guid><dc:creator>jamiet</dc:creator><slash:comments>19</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/33387.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=33387</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=33387</wfw:comment><description>&lt;p&gt;&lt;font size="3"&gt;Today I have been using Windows Installer XML (WiX) to build an installer (.msi file) that would install a SQL Server database on a server of my choosing; the source code for that database lives in datadude (a tool &lt;/font&gt;&lt;a href="http://www.sqlservercentral.com/questions/visual+studio/72236/" target="_blank"&gt;&lt;font size="3"&gt;which you may know by one of quite a few other names&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;). The basis for this work was a most excellent blog post by Duke Kamstra entitled &lt;/font&gt;&lt;a href="http://blogs.msdn.com/b/dukek/archive/2009/10/19/implementing-a-wix-installer-that-calls-the-gdr-version-of-vsdbcmd-exe.aspx" target="_blank"&gt;&lt;font size="3"&gt;Implementing a WIX installer that calls the GDR version of VSDBCMD.EXE&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; which coves the delicate intricacies of doing this – particularly how to call &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx" target="_blank"&gt;&lt;font size="3"&gt;Vsdbcmd.exe&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; in a &lt;/font&gt;&lt;a href="http://wix.sourceforge.net/manual-wix3/wix_xsd_customaction.htm" target="_blank"&gt;&lt;font size="3"&gt;CustomAction&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;. Unfortunately there are a couple of things wrong with Duke’s post:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="3"&gt;Searching for “datadude wix” didn’t turn it up in the first page of search results and hence it took me a long time to find it. And I knew that it existed. If someone else were after a post on using WiX with datadude its likely that they would never have come across Duke’s post and that would be a great shame because its the definitive post on the matter.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3"&gt;It was written in October 2009 and had not been updated for Visual Studio 2010.&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font size="3"&gt;Well, this blog post is an attempt to solve those problems. Hopefully I’ve solved the first one just by following a few of &lt;/font&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/12/21/blogging-tips-for-sql-server-professionals.aspx" target="_blank"&gt;&lt;font size="3"&gt;my blogging SEO tips&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; while writing this blog post, in the rest of it I will explain how I took Duke’s code and updated it to work in Visual Studio 2010.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;If you need to build a database installer using WiX, datadude and Visual Studio 2010 then you still need to follow Duke’s blog post so go and do that now. Below are the amendments that I made that enabled the project to get built in Visual Studio 2010:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="3" face="Calibri"&gt;In VS2010 datadude’s output files have changed from being called Database.&amp;lt;suffix&amp;gt; to &amp;lt;ProjectName&amp;gt;_Database.&amp;lt;suffix&amp;gt;. Duke’s code was referencing the old file name formats.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;Duke used $(var.SolutionDir) and relative paths to point to datadude artefacts I have replaced these with Votive Project References &lt;/font&gt;&lt;a href="http://wix.sourceforge.net/manual-wix3/votive_project_references.htm"&gt;&lt;font size="3"&gt;http://wix.sourceforge.net/manual-wix3/votive_project_references.htm&lt;/font&gt;&lt;/a&gt;&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;I commented out all references to MicrosoftSqlTypesDbschema in DatabaseArtifacts.wxi. I don't think this is produced in VS2010 (I may be wrong about that but it wasn't in the output from my project)&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;Similarly I commented out component MicrosoftSqlTypesDbschema in VsdbcmdArtifacts.wxi. It wasn't where Duke's code said it should have been so am assuming/hoping it isn't needed.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;Duke's &lt;font face="Consolas"&gt;?define&lt;/font&gt; block to work out appropriate SrcArchPath actually wasn't working for me (i.e. &lt;font face="Consolas"&gt;&amp;lt;?if $(var.Platform)=x64 ?&lt;/font&gt;&amp;gt; was evaluating to false)&amp;#160; so I just took out the conditional stuff and declared the path explicitly to the “Program Files (x86)” path. The old code is still there though if you need to put it back.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;None of the &lt;font face="Consolas"&gt;&amp;lt;RegistrySearch&amp;gt;&lt;/font&gt; stuff is needed for VS2010 - so I commented it all out!&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;Changed to use &lt;font face="Consolas"&gt;/manifest &lt;/font&gt;option rather than &lt;font face="Consolas"&gt;/model&lt;/font&gt; option on vsdbcmd.exe command-line. Personal preference is all!&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;Added a new component in order to bundle along the vsdbcmd.exe.config file&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font size="3" face="Calibri"&gt;Made the install of the Custom Action dependent on the relevant feature being selected for install. This one is actually really important – deselecting the database feature for installation does not, by default, stop the CustomAction from executing and so would cause an error - so that scenario needs to be catered for&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font size="3"&gt;I have made my amended solution available for download at: &lt;/font&gt;&lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.zip"&gt;&lt;font size="3"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.zip&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; It contains two projects: the WiX project and the datadude project that is the source to be deployed (for demo purposes it only contains one table).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_640907F6.png"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_4817D2FE.png" width="407" height="335" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;I have also made the .msi available although in order that it gets through file blockers I changed the name from InstallMyDatabase.msi to InstallMyDatabase.ms_ – simply rename the file back once you have downloaded it from: &lt;/font&gt;&lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.ms%5E_" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.ms%5E_"&gt;&lt;font size="3"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110210/InstallMyDatabase.ms%5E_&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; .You can try it out for yourself – the only thing it does is dump the files into %Program Files%\MyDatabase and uses them to install a database onto a server of your choosing with a name of your choosing - no damaging side-affects. I will caveat this by saying “it works on my machine” and, not having access to a plethora of different machines, I haven’t tested it anywhere else. One potential issue that I know of is that Vsdbcmd.exe has a &lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx" target="_blank"&gt;dependency on SQL Server CE&lt;/a&gt; although if you have SQL Server tools or Visual Studio installed you should be fine. Unfortunately its not possible to bundle along the SQL Server CE installer in the .msi because Windows will not allow you to call one installer from inside another – the recommended way to get around this problem is to build a bootstrapper to bundle the whole lot together but doing that is outside the scope of this blog post. If you discover any other issues then please let me know.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;Here are the screenshots from the installer:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_1879B472.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_7DCD1858.png" width="522" height="408" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_14ABE9D5.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_2BF6EE46.png" width="522" height="408" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_029FA648.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_15E05CE7.png" width="524" height="409" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_74148455.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_322D9F07.png" width="524" height="410" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_7765F630.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_0F1D2D97.png" width="524" height="409" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_141F6B46.png"&gt;&lt;font size="3"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_64814CB9.png" width="526" height="411" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;And once installed….&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_7CEF886A.png"&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_109C71FF.png"&gt;&lt;img style="background-image:none;border-right-width: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://sqlblog.com/blogs/jamie_thomson/image_thumb_2808D80F.png" width="322" height="191" /&gt;&lt;/a&gt;&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;Hope this is useful!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;&lt;font size="3"&gt;@jamiet&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=33387" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/msi/default.aspx">msi</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sqlserver/default.aspx">sqlserver</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/vsdbcmd.exe/default.aspx">vsdbcmd.exe</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/VSTS+Database+Edition/default.aspx">VSTS Database Edition</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/wix/default.aspx">wix</category></item><item><title>Generate multiple SqlCmdVars files in your database projects</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/19/generate-multiple-sqlcmdvars-vars-in-your-database-projects.aspx</link><pubDate>Wed, 19 Jan 2011 20:24:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:32757</guid><dc:creator>jamiet</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/32757.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=32757</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=32757</wfw:comment><description>&lt;p&gt;Earlier today I was doing a little work using datadude/DBPro/Visual Studio Database Tools/pick your name and had a need to write a Powershell script that I think might be useful to other folks so I’m sharing it here.&lt;/p&gt;  &lt;p&gt;Often when you’re putting together database projects you will have a need for multiple .sqlcmdvars files – one for each environment that you are deploying to. It can be a real pain in the neck maintaining multiple .sqlcmdvars files because you need to make sure that:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;each file has the same list of sqlcmd variables in it &lt;/li&gt;    &lt;li&gt;the variables that need to be different per environment have got the correct values in them &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you have multiple environments and multiple projects then this can become a real headache to maintain – indeed, the project that I am working on at the moment has got 192 sqlcmdvars files. You can trust me that that is pretty excessive however this problem is still one that many people are going to encounter.&lt;/p&gt;  &lt;p&gt;So, when you have 192 occurences of the same problem it seems logical to write a script to carry out the repetitive task of editing those files and that is exactly what I did today. My Powershell script requires that you maintain ONE .sqlcmdvars file per project and will then take care of generating the others and also replacing environment-specific variable values where appropriate. You need to supply a list of a projects, a list of environments and, for each environment, a value for each variable that you want to change. the example below has only one project, three environments (thus three .sqlcmdvars files) and one environment-specific variable. If you have anything more complex than that then the script is very easy to change and is self-explanatory.&lt;/p&gt;  &lt;p&gt;Here’s a screenshot of my demo project:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_2F9C93E4.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_438600AD.png" width="767" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;There are three sqlcmdvars files {development.sqlcmdvars,production.sqlcmdvars,test.sqlcmdvars} &lt;/li&gt;    &lt;li&gt;development.sqlcmdvars contains a variable called $(EmailAddress) that is not in either of the other two &lt;/li&gt;    &lt;li&gt;My Powershell script is stored as a solution file &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is the script:&lt;/p&gt;  &lt;pre&gt;&lt;font size="2"&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;This script copies the contents of each &amp;lt;defined&amp;gt;.sqlcmdvars into all the other .sqlcmdvars files for that project&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;font size="2"&gt;#&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;&lt;font size="2"&gt;It should live in the root folder of your solution&lt;br /&gt;#If your sqlcmdvars files are under source control don’t forget to check them out&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;&lt;font size="2"&gt;cls&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$masterSqlCmdVars&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;development&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;Edit these two&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$variableName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;EmailAddress&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;values accordingly&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$DbArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;20110119 Test Sqlcmdvars Generator&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;List all your .dbproj files&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Db&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$DbArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
{
    &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;List of environments and the property values for each respective environment&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt; (
                    (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;test&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;test@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;),
                    (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;production&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;production@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
                )
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
    {
        &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;STEP 1 - copy the file&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[0]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[1]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$masterSqlCmdVars.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$EnvName.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Copying $source to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;copy&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;

&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;STEP 2 - edit with new variable values&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; [&lt;/span&gt;&lt;span style="color:#008080;"&gt;xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;](&lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$root&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;get_DocumentElement&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;();
        &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$property&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$root&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Properties&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;ChildNodes&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        {
            &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$property&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;PropertyName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;-eq&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$variableName&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color:#800080;"&gt;$property&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Propertyvalue&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;            }
        }
        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Saving modified XML to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;resolve-path&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Save&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;&lt;font size="2"&gt;)
    }
}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It has an outer loop for all the projects and an inner loop for each environment. On each iteration it copies the contents of development.sqlcmdvars into $EnvName.sqlcmdvars and then updates the file with the new value for $(EmailAddress). If you have more variables that you need to edit then its not a great hardship to adapt the script accordingly.&lt;/p&gt;

&lt;p&gt;Upon completion our test.sqlcmdvars and production.sqlcmdvars files have been edited as so:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_11CAE358.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_2DABF283.png" width="765" height="470" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it. Pretty simple. I won’t go deep into explaining the script because if this is useful to you you will probably want to do that yourself. This demo project, including the Powershell script, is available for download at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UPDATE: I have discovered an alternative method &lt;a href="http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/e3281376-0e18-4494-afbe-a523b0fd1995/" target="_blank"&gt;courtesy of Robert Robelo&lt;/a&gt; and I like this one because it uses XPath which to me feels like a purer way of doing this – I can’t explain why so don’t ask! Here’s is Robert’s code which achieves the same as above:&lt;/p&gt;

&lt;pre&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;&lt;font size="2"&gt;cls&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$masterSqlCmdVars&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;development&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;Edit these two&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$variableName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;EmailAddress&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;values accordingly&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$DbArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;20110119 Test Sqlcmdvars Generator&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;List all your .dbproj files&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Db&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$DbArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
{
    &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;List of environments and the property values for each respective environment&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt; (
                    (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;test&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;test@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;),
                    (&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;production&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;production@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
                )
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
    {
        &lt;/span&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;STEP 1 - copy the file&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[0]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[1]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$masterSqlCmdVars.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$EnvName.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Copying $source to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;copy&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        
        [&lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#008080;"&gt;xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;]&lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$nsMgr&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;New-Object&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;Xml.XmlNamespaceManager&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;NameTable&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$prefix&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;ns&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$uri&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;span style="color:#800000;"&gt;urn:Microsoft.VisualStudio.Data.Schema.Package.SqlCmdVars&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$nsMgr&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;AddNamespace&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$prefix&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;$uri&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xpath&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;//${prefix}:Property[./${prefix}:PropertyName='$variableName']&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$node&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;SelectSingleNode&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$xpath&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;$nsMgr&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$node&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;PropertyValue&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Save&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;    }
}&lt;/font&gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;I have also updated the downloadable file at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip&lt;/a&gt; with Robert’s code.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=32757" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category></item><item><title>Querying Visual Studio project files using T-SQL and Powershell</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/17/querying-visual-studio-project-files.aspx</link><pubDate>Mon, 17 Jan 2011 21:11:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:32686</guid><dc:creator>jamiet</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/32686.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=32686</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=32686</wfw:comment><description>&lt;P&gt;Earlier today I had a need to get some information out of a Visual Studio project file and in this blog post I’m going to share a couple of ways of going about that because I’m pretty sure I won’t be the only person that ever wants to do this. The specific problem I was trying to solve was finding out how many objects in my database project (i.e. in my .dbproj file) had any warnings suppressed but the techniques discussed below will work pretty well for any Visual Studio project file because every such file is simply an XML document, hence it can be queried by anything that can query XML documents.&lt;/P&gt;
&lt;P&gt;Ever heard the phrase “when all you’ve got is hammer everything looks like a nail”? Well that’s me with querying stuff – if I can write SQL then I’m writing SQL. Here’s a little noddy database project I put together for demo purposes:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_003D882B.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;MARGIN:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_7E208961.png" width=211 height=244&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Two views and a stored procedure, nothing fancy. I suppressed warnings for [View1] &amp;amp; [Procedure1] and hence the pertinent part my project file looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;nbsp;&lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Views\View1.view.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT size=3&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;4151,3276&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Views\View2.view.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Programmability\Stored Procedures\Procedure1.proc.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT size=3&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;4151&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Note the &lt;STRONG&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt; &lt;/STRONG&gt;elements – those are the bits of information that I am after.&lt;/P&gt;
&lt;P&gt;With &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlxml/thread/2337b9bf-e123-4004-8af3-06d2b851c7e1/" target=_blank&gt;a lot of help&lt;/A&gt; from folks on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlxml/threads" target=_blank&gt;SQL Server XML forum&lt;/A&gt;&amp;nbsp; I came up with the following query that nailed what I was after. It reads the contents of the .dbproj file into a variable of type XML and then shreds it using T-SQL’s &lt;A href="http://msdn.microsoft.com/en-us/library/ms190798.aspx" target=_blank&gt;XML data type methods&lt;/A&gt;: &lt;/P&gt;
&lt;TABLE cellSpacing=0 cellPadding=2&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:blue;"&gt;DECLARE &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;XML&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;pkgblob.BulkColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS XML&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp; OPENROWSET&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;BULK &lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'C:\temp\QueryingProjectFileDemo\QueryingProjectFileDemo.dbproj' &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;-- &amp;lt;-Change this path! &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;single_blob&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;pkgblob &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WITH &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;XMLNAMESPACES&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'http://schemas.microsoft.com/developer/msbuild/2003' &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ns&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;SUBSTRING&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ObjectPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CHARINDEX&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'\'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ObjectPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)))) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[ObjectName] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[SuppressedWarnings] &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.query&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'.'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[_node] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.value&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'ns:SuppressWarnings[1]'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'nvarchar(100)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[SuppressedWarnings] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.value&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'@Include'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'nvarchar(1000)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[ObjectPath] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;.nodes&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'//ns:Build[ns:SuppressWarnings]'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;R&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;q &lt;BR&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;And here’s the output:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_4E826AD5.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;MARGIN:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_7B9757A3.png" width=533 height=164&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And that’s it – an easy way of discovering which warnings have been suppressed and for which objects in your database projects. I won’t bother going over the code as it is fairly self-explanatory – peruse it at your leisure.&lt;/P&gt;
&lt;P&gt;Once I had the SQL above I figured I’d share it around a little in case it was ever useful to anyone else; hence I’m writing this blog post and I also posted it on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/vstsdb/threads" target=_blank&gt;Visual Studio Database Development Tools forum&lt;/A&gt; at &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/8eacbe76-c6d1-40e2-af15-044903a98c1d/?prof=required" target=_blank&gt;FYI: Discover which objects have had warnings suppressed&lt;/A&gt;. Luckily &lt;A href="http://social.msdn.microsoft.com/profile/kevin%20goode/?type=forum&amp;amp;referrer=http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/8eacbe76-c6d1-40e2-af15-044903a98c1d/?prof=required" target=_blank&gt;Kevin Goode&lt;/A&gt; saw the thread and he posted a different solution to the same problem, one that uses Powershell. The advantage of Kevin’s Powershell approach is that it is easy to analyse many .dbproj files at the same time. Below is Kevin’s code which I have tweaked &lt;EM&gt;ever so slightly&lt;/EM&gt; so that it produces the same results as my SQL script (I just want any object that had had a warning suppressed whereas Kevin was querying specifically for warning 4151):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;cd&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;C:\Temp\QueryingProjectFileDemo\&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;cls&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$projects&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;ls&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-r&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-i&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; *.dbproj
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;Foreach&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$project&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$projects&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;)
{
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;new-object&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;System.Xml.XmlDocument&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;set_PreserveWhiteSpace&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$true&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; )
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;Load&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$project&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;)

  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;$xpath = @{Start="/e:Project/e:ItemGroup/e:Build[e:SuppressWarnings=4151]/@Include"}&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;$xpath = @{Start="/e:Project/e:ItemGroup/e:Build[contains(e:SuppressWarnings,'4151')]/@Include"}&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xpath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; @{Start&lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;/e:Project/e:ItemGroup/e:Build[e:SuppressWarnings]/@Include&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;}
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$ns&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; @{ e &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; }

  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select-Xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-XPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xpath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.Start  &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Namespace&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$ns&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; |&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Expand&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;Node&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-expand&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;Value&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
}

&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;and here’s the output:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_60EABB8A.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;MARGIN:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_4716855B.png" width=765 height=102&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Nice reusable Powershell and SQL scripts – not bad for an evening’s work. Thank you to Kevin for allowing me to share his code.&lt;/P&gt;
&lt;P&gt;Don’t forget that these techniques can easily be adapted to query &lt;EM&gt;any&lt;/EM&gt; Visual Studio project file, they’re only XML documents after all! Doubtless many people out there already have code for doing this but nonetheless here is another offering to the great script library in the sky. Have fun!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This blog post was mentioned on &lt;/EM&gt;&lt;A href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-AutoTuneNET-Portable-Libraries-Facebook--Azure-SQLR2-BI"&gt;&lt;EM&gt;This Week on Channel 9&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;. Fast forward to 10m49s.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=32686" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/t-sql/default.aspx">t-sql</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/XML/default.aspx">XML</category></item><item><title>Maintaining version history in your database using Visual Studio 2010</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/19/maintaining-version-history-in-your-database-using-visual-studio-2010.aspx</link><pubDate>Tue, 19 Oct 2010 19:26:14 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:29503</guid><dc:creator>jamiet</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/29503.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=29503</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=29503</wfw:comment><description>&lt;p&gt;I have written a few blogs lately explaining how my current project is employing the use of datadude (aka the database development tools in Visual Studio 2010) in order to manage our database code, deployment of that code and also testing of it. In this blog post I’m going to share a little technique that we use in order to store a version history of our deployments. Note that this assumes a working knowledge of datadude so if you don’t know what the terms Post-Deployment script, SQLCMD variables, Continuous Integration &amp;amp; msbuild refer to then maybe this blog post is not for you!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;b&gt;Need a table&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;Firstly, we need a table to store our version history, in our case we have called it &lt;font face="Consolas"&gt;[BuildVersion]&lt;/font&gt; and it looks like this:&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:black;"&gt;     &lt;blockquote&gt;       &lt;p&gt;         &lt;br /&gt;&lt;/p&gt;       &lt;span style="color:blue;"&gt;CREATE TABLE &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[BuildVersion]         &lt;br /&gt;&lt;/span&gt;&lt;span style="color:gray;"&gt;(         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[BuildVersion] &lt;/span&gt;&lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;20&lt;/span&gt;&lt;span style="color:gray;"&gt;) NOT NULL,         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[Deployed]&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;DATETIME &lt;/span&gt;&lt;span style="color:gray;"&gt;NOT NULL         &lt;br /&gt;)          &lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;   &lt;/span&gt;&lt;/code&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019schema_view_722CAE33.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019schema_view" border="0" alt="20101019schema_view" src="http://sqlblog.com/blogs/jamie_thomson/20101019schema_view_thumb_0FBE8933.png" width="311" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;Need a project variable&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We have a SQLCMD variable declared as part of our project that is intended to hold a version number. In datadude SQLCMD variables are (by default) declared in a file called &lt;strong&gt;Database.sqlcmdvars&lt;/strong&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019slcmdvars_solnexp_2DBC9727.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019slcmdvars_solnexp" border="0" alt="20101019slcmdvars_solnexp" src="http://sqlblog.com/blogs/jamie_thomson/20101019slcmdvars_solnexp_thumb_53461488.png" width="307" height="256" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In our case we have a variable called ‘BuildVersion’ that we default to the value of “Unknown”&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019sqlcmdvars_vars_55AED07D.jpg"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019sqlcmdvars_vars" border="0" alt="20101019sqlcmdvars_vars" src="http://sqlblog.com/blogs/jamie_thomson/20101019sqlcmdvars_vars_thumb_5391D1B4.jpg" width="476" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;Need to populate the table&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We use the value in our ‘BuildVersion’ variable in order to populate our [BuildVersion] table and we do that within a Post-Deployment script using the following simple code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;INSERT&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[dbo].[BuildVersion]&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;[BuildVersion]&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:black;"&gt;[Deployed]&lt;/span&gt;&lt;span style="color:gray;"&gt;)         &lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;VALUES&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;'$(BuildVersion)'&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:magenta;"&gt;GETDATE&lt;/span&gt;&lt;span style="color:gray;"&gt;())&amp;#160; &lt;/span&gt;&lt;span style="color:green;"&gt;--$(BuildVersion is a SQLCMD variable declared within this project)&lt;/span&gt;&lt;/code&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;b&gt;And of course we need to tell our mechanism what the build number is&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;We need to make sure that $(BuildVersion) has a value in it. As we are deploying our database as part of a continuous integration build (leveraging msbuild) we can pass in a value from the msbuild script. Here’s the code that we use to do that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#c0504d"&gt;Exec &lt;/font&gt;&lt;font color="#ff0000"&gt;Command&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;..\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot&lt;/font&gt;&lt;font color="#ff0000"&gt;;&lt;/font&gt;&lt;font color="#0000ff"&gt;Data Source=$(Server);Integrated Security=True&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt; &lt;font color="#0000ff"&gt;/DeployToDatabase:+ /ManifestFile:&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;..\MyDB.deploymanifest&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt; &lt;u&gt;&lt;font color="#0000ff"&gt;/p:BuildVersion=&lt;/font&gt;&lt;/u&gt;&lt;u&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;/u&gt;&amp;quot; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;pre&gt;&lt;font face="Calibri"&gt;The important bit for what we are discussing herein is that last underlined part:&lt;/font&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;u&gt;&lt;font color="#0000ff"&gt;/p:BuildVersion=&lt;/font&gt;&lt;/u&gt;&lt;u&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;&lt;font color="#ff0000"&gt;&amp;amp;quot;&lt;/font&gt;&lt;/u&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The /p directive is used to populate a named variable (in our case &lt;font color="#0000ff" face="Consolas"&gt;BuildVersion&lt;/font&gt;) with a value. In our case than value is taken from an msbuild property which, in our case, is referred to by &lt;font color="#0000ff"&gt;$(BuildLabel)&lt;/font&gt;. [Note that managing msbuild properties is outside the scope of this blog post.]&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;h3&gt;Wrap-up&lt;/h3&gt;

&lt;p&gt;That’s pretty much all you need. If it all hangs together correctly then &lt;font face="Consolas"&gt;[BuildVersion]&lt;/font&gt; will contain a nice history of all your deployments like so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/20101019results_074A8E0F.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="20101019results" border="0" alt="20101019results" src="http://sqlblog.com/blogs/jamie_thomson/20101019results_thumb_184EBBF2.png" width="461" height="215" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope this is useful! I suspect the same technique will work in earlier versions of datadude but I don’t have any to hand so can’t find out.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=29503" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/t-sql/default.aspx">t-sql</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item><item><title>Enforcing naming conventions using database unit testing</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/06/enforcing-naming-conventions-using-database-unit-testing.aspx</link><pubDate>Tue, 05 Oct 2010 22:42:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:29199</guid><dc:creator>jamiet</dc:creator><slash:comments>6</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/29199.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=29199</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=29199</wfw:comment><description>&lt;h3&gt;My naming convention obsession&lt;/h3&gt;  &lt;p&gt;Anyone that has ever worked with me will tell you that I am a stickler for naming conventions. I have a somewhat obsessive reputation for it; I can’t help it – I seem to have a deep seated uncontrollable desire to ensure that every object in my database(s) is/are named consistently (is there anyone else out there equally as obsessive?). &lt;/p&gt;  &lt;p&gt;I have tried various techniques down the years to try and enforce naming conventions but none of them really worked. I’ve got scripts that alter object names (such a script is in my &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/10/03/take-your-script-library-with-you-t-sql.aspx" target="_blank"&gt;script library&lt;/a&gt; in fact) but these are only any use if they actually get run, they don’t actually &lt;em&gt;enforce &lt;/em&gt;the conventions – that’s a manual step. I’ve thought about using Policy-Based Management (PBM) to enforce naming conventions but given I’m a developer and not a DBA that’s not something that is readily available to me and besides, using PBM to enforce naming conventions is reactive rather than proactive if you are developing the code on a machine where the policies are not enforced.&lt;/p&gt;  &lt;p&gt;Another option I looked into using was Team Foundation Server (TFS) check-in policies; these are policies that can be applied to artefacts when they get checked-in to TFS’s source control system. This option really appealed to me because the naming conventions could be enforced during check-in (i.e. very very early) and didn’t require DBA intervention. In practice though enforcing naming conventions using TFS check-in policies has a few sizable issues:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Its not easy. It would require you to parse the file that was getting checked-in, decide what sort of object is defined in the file, and then check the name of the object based on things like object name, schema, etc... &lt;/li&gt;    &lt;li&gt;TFS check-in policies are not installed on the TFS server, they are installed on the development workstations. This means there is a dependency and, even though the source code for the check-in policies can be distributed with your application source code, I didn’t really like this. &lt;/li&gt;    &lt;li&gt;You’re relying on each developer to enforce the check-in policy and with the greatest will in the world….that aint gonna happen. Its too easy to turn them off. &lt;/li&gt;    &lt;li&gt;There is the obvious dependency on using TFS, not something every development shop uses even in the Microsoft space. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Database unit testing to the rescue&lt;/h3&gt;  &lt;p&gt;No, a better solution was needed and I came up with one in the shape of automated database unit testing. I have spoken recently about how I have become a big fan of database unit testing (see my post &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/18/experiences-from-writing-sp-cascadingdataviewer-db-unit-testing-and-code-distribution.aspx" target="_blank"&gt;Experiences from writing sp_CascadingDataViewer – DB unit testing and code distribution&lt;/a&gt;) and being able to enforce naming conventions is one very good reason for that. Enforcing naming conventions using automated unit tests has a number of advantages:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;They can be written against the metadata of the objects themselves (i.e. by querying SQL Server’s system views) so there’s no parsing that needs to be done. &lt;/li&gt;    &lt;li&gt;They can be employed as part of a Continuous Integration (CI) process and run as a build verification test (BVT). Someone checks-in an object that violates the naming convention? Bang: broken build! &lt;/li&gt;    &lt;li&gt;Developers can’t circumvent the tests. &lt;/li&gt;    &lt;li&gt;Nothing needs to be installed on the development workstations. The tests live wholly as part of your source code. &lt;/li&gt;    &lt;li&gt;Not dependent on use of a particular source control system &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hence I have written some unit tests that enforce the following naming conventions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Check constraints must be of the form CK_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt;_XXX &lt;/li&gt;    &lt;li&gt;Column names must begin with a capital letter &lt;/li&gt;    &lt;li&gt;Column names cannot contain underscores &lt;/li&gt;    &lt;li&gt;Default constraints must be named DF_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt;_&amp;lt;ColumnName&amp;gt; &lt;/li&gt;    &lt;li&gt;Foreign keys must be of the form FK_&amp;lt;parentObjectSchema&amp;gt;&amp;lt;parentObject&amp;gt;_REF_&amp;lt;referencedObjectSchema&amp;gt;&amp;lt;referencedObject&amp;gt;XXX &lt;/li&gt;    &lt;li&gt;Non-unique clustered keys must be of the form IXC_&amp;lt;schemaName&amp;lt;TableName&amp;gt;_&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;… &lt;/li&gt;    &lt;li&gt;Non-unique non-clustered keys must be of the form IX_&amp;lt;schemaName&amp;gt;&amp;lt;TableName&amp;gt;_&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;... &lt;/li&gt;    &lt;li&gt;Unique clustered keys must be of the form IXUN_&amp;lt;schemaName&amp;gt;&amp;lt;TableName&amp;gt;_&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;&amp;lt;Column&amp;gt;… &lt;/li&gt;    &lt;li&gt;Unique non-clustered keys must be of the form IXUN_&amp;lt;schemaName&amp;gt;&amp;lt;TableName&amp;gt;_&amp;lt;ColumnColumnColumn&amp;gt;...      &lt;ul&gt;&lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Primary keys must be of the form PK_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt; &lt;/li&gt;    &lt;li&gt;Stored procedure names should not contain underscores &lt;/li&gt;    &lt;li&gt;Stored procedure names must begin with a capital letter &lt;/li&gt;    &lt;li&gt;Table names must not contain underscores &lt;/li&gt;    &lt;li&gt;Table names must begin with a capital letter &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I’m not stating that you should agree with these naming conventions (I don’t necessarily agree with them myself – they were defined before I arrived on my current project), the point here is that all of these rules can be enforced and its very easy to do it. Here’s the code for the unit test that enforces the&amp;#160; primary key naming convention:&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:black;"&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;&lt;font face="Consolas"&gt;/*PK name is PK_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt;*/       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font face="Consolas"&gt;&lt;span style="color:blue;"&gt;SET NOCOUNT ON       &lt;br /&gt;&amp;#160;&amp;#160; DECLARE &lt;/span&gt;&lt;span style="color:#434343;"&gt;@cnt&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;;       &lt;br /&gt;        &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;*       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;INTO&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:#434343;"&gt;#t       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT&amp;#160; &lt;/span&gt;&lt;span style="color:magenta;"&gt;OBJECT_NAME&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;c.[parent_object_id]&lt;/span&gt;&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[TableName]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;OBJECT_SCHEMA_NAME&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;c.[parent_object_id]&lt;/span&gt;&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[SchemaName]&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;c.&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;*       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;[sys].[key_constraints] c       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;INNER JOIN &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;[sys].[tables] t        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;ON&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;c.[parent_object_id] &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;t.[object_id]&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:magenta;"&gt;LEFT &lt;/span&gt;&lt;span style="color:gray;"&gt;OUTER &lt;/span&gt;&lt;span style="color:blue;"&gt;JOIN &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;sys.extended_properties ep       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;ON&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;t.[object_id] &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;ep.major_id       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;AND &lt;/span&gt;&lt;span style="color:black;"&gt;ep.[name] &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:red;"&gt;'microsoft_database_tools_support'       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color:black;"&gt;ep.[major_id] &lt;/span&gt;&lt;span style="color:blue;"&gt;IS &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;NULL       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AND &lt;/span&gt;&lt;span style="color:black;"&gt;c.[type] &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:red;"&gt;'PK'       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;)&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;q       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;WHERE&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;[name] &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;&amp;gt; &lt;/span&gt;&lt;span style="color:red;"&gt;N'PK_' &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:black;"&gt;[SchemaName] &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;[TableName]       &lt;br /&gt;        &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SET&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:#434343;"&gt;@cnt &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;span style="color:#434343;"&gt;@@ROWCOUNT&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;;       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;IF&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:#434343;"&gt;@cnt &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;&lt;span style="color:black;"&gt;0&lt;/span&gt;&lt;/font&gt;&lt;span style="color:gray;"&gt;&lt;font face="Consolas"&gt;)       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font face="Consolas"&gt;&lt;span style="color:blue;"&gt;BEGIN       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DECLARE &lt;/span&gt;&lt;span style="color:#434343;"&gt;@msg &lt;/span&gt;&lt;span style="color:blue;"&gt;NVARCHAR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:black;"&gt;2048&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT&amp;#160; &lt;/span&gt;&lt;span style="color:#434343;"&gt;@msg &lt;/span&gt;&lt;span style="color:blue;"&gt;= &lt;/span&gt;&lt;span style="color:red;"&gt;'%d Primary Keys do not conform to naming convention (PK_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt;):' &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:magenta;"&gt;STUFF&lt;/span&gt;&lt;span style="color:gray;"&gt;((&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:red;"&gt;', ' &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:black;"&gt;[name] &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:#434343;"&gt;#t &lt;/span&gt;&lt;span style="color:black;"&gt;a &lt;/span&gt;&lt;span style="color:blue;"&gt;FOR XML &lt;/span&gt;&lt;span style="color:black;"&gt;PATH&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:red;"&gt;''&lt;/span&gt;&lt;span style="color:gray;"&gt;) ),&lt;/span&gt;&lt;span style="color:black;"&gt;1&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;2&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:red;"&gt;''&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT&amp;#160; &lt;/span&gt;&lt;span style="color:black;"&gt;1 &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;&lt;span style="color:black;"&gt;[Id]&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;,*       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;FROM&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:#434343;"&gt;#t &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;t       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:gray;"&gt;)&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;q       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;GROUP&amp;#160;&amp;#160; BY &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:black;"&gt;q.[Id]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:#434343;"&gt;@msg       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;RAISERROR&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:#434343;"&gt;@msg&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;11&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:black;"&gt;1&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt;&lt;span style="color:#434343;"&gt;@cnt&lt;/span&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;span style="color:gray;"&gt;);       &lt;br /&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;&lt;/font&gt;&lt;/code&gt;  &lt;p&gt;Essentially all it does is pull all of the primary keys out of &lt;font size="1" face="Consolas"&gt;&lt;span style="color:black;"&gt;[sys].[key_constraints]&lt;/span&gt;&lt;/font&gt;, checks to see what the name &lt;em&gt;should &lt;/em&gt;be, then if it finds any that violate the naming convention raise an error containing the names of all the primary keys in question. Here’s the error obtained when running the test against [AdventureWorks] (I’ve highlighted the pertinent bit):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Test method Prs.SchemaTests.NamingConventions.PrimaryKeys threw exception:      &lt;br /&gt;System.Data.SqlClient.SqlException: &lt;strong&gt;70 Primary Keys do not conform to naming convention (PK_&amp;lt;schemaName&amp;gt;&amp;lt;tableName&amp;gt;)&lt;/strong&gt;:PK_ErrorLog_ErrorLogID, PK_Address_AddressID, PK_AddressType_AddressTypeID, PK_AWBuildVersion_SystemInformationID, PK_BillOfMaterials_BillOfMaterialsID, PK_Contact_ContactID, PK_ContactCreditCard_ContactID_CreditCardID, PK_ContactType_ContactTypeID, PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode, PK_CountryRegion_CountryRegionCode, PK_CreditCard_CreditCardID, PK_Culture_CultureID, PK_Currency_CurrencyCode, PK_CurrencyRate_CurrencyRateID, PK_Customer_CustomerID, PK_CustomerAddress_CustomerID_AddressID, PK_DatabaseLog_DatabaseLogID, PK_Department_DepartmentID, PK_Document_DocumentID, PK_Employee_EmployeeID, PK_EmployeeAddress_EmployeeID_AddressID, PK_EmployeeDepartmentHistory_EmployeeID_StartDate_DepartmentID, PK_EmployeePayHistory_EmployeeID_RateChangeDate, PK_Illustration_IllustrationID, PK_Individual_CustomerID, PK_JobCandidate_JobCandidateID, PK_Location_LocationID, PK_Product_ProductID, PK_ProductCategory_ProductCategoryID, PK_ProductCostHistory_ProductID_StartDate, PK_ProductDescription_ProductDescriptionID, PK_ProductDocument_ProductID_DocumentID, PK_ProductInventory_ProductID_LocationID, PK_ProductListPriceHistory_ProductID_StartDate, PK_ProductModel_ProductModelID, PK_ProductModelIllustration_ProductModelID_IllustrationID, PK_ProductModelProductDescriptionCulture_ProductModelID_ProductDescriptionID_CultureID, PK_ProductPhoto_ProductPhotoID, PK_ProductProductPhoto_ProductID_ProductPhotoID, PK_ProductReview_ProductReviewID, PK_ProductSubcategory_ProductSubcategoryID, PK_ProductVendor_ProductID_VendorID, PK_PurchaseOrderDetail_PurchaseOrderID_PurchaseOrderDetailID, PK_PurchaseOrderHeader_PurchaseOrderID, PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID, PK_SalesOrderHeader_SalesOrderID, PK_SalesOrderHeaderSalesReason_SalesOrderID_SalesReasonID, PK_SalesPerson_SalesPersonID, PK_SalesPersonQuotaHistory_SalesPersonID_QuotaDate, PK_SalesReason_SalesReasonID, PK_SalesTaxRate_SalesTaxRateID, PK_SalesTerritory_Territor...&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I am currently including these tests inside a C# test project inside Visual Studio 2010. Visual Studio has a rather nice feature that allows you to link to artefacts in other projects and hence we can host our single test class containing all of these tests in one place and link to it from whichever test project we want (typically you will have a test project per database) thus following the &lt;a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank"&gt;DRY principle&lt;/a&gt;. Here I show the dialog that demonstrates adding a link to an existing test class:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_799DEAA6.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_55B5134C.png" width="619" height="424" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And how it appears in the project. Note that NamingConventions.cs exists in both test projects but one is just a link to the other:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_12F5C814.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5FB98EAA.png" width="244" height="229" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;Wrap-up&lt;/h3&gt;  &lt;p&gt;I’m not sure my colleagues are too happy about these new tests given that they’re now breaking the build more often but nonetheless I think they realise the value (I guess I’ll find out tomorrow when they read this!!!) &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_7770C610.png" /&gt; All-in-all its working very well for us and I’m now a very happy bunny knowing that naming conventions are being enforced and will continue to be so with zero effort from here on in. I have made the test class that contains all of the tests that I detailed above available on my SkyDrive at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20101005/MIControlTest.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20101005/MIControlTest.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20101005/MIControlTest.zip&lt;/a&gt;. If you want to use it you should simply be able to drop it into an existing C# database test project and away you go (change the tests to suit your naming conventions of course though).&lt;/p&gt;  &lt;p&gt;Hope this helps. If it does please let me know, I’d really love some feedback on this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=29199" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/naming+conventions/default.aspx">naming conventions</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/unit+testing/default.aspx">unit testing</category></item><item><title>Experiences from writing sp_CascadingDataViewer – DB unit testing and code distribution</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/09/18/experiences-from-writing-sp-cascadingdataviewer-db-unit-testing-and-code-distribution.aspx</link><pubDate>Sat, 18 Sep 2010 16:41:55 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28849</guid><dc:creator>jamiet</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/28849.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=28849</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=28849</wfw:comment><description>&lt;p&gt;Its now been a month since I &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2010/08/11/introducing-sp-cascadingdataviewer.aspx" target="_blank"&gt;introduced sp_CascadingDataViewer&lt;/a&gt; and I wanted to take the opportunity to talk about a couple of my experiences while writing it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;SQL Server needs packages&lt;/h2&gt;  &lt;p&gt;Version 1 of sp_CascadingDataViewer is an 899 line stored procedure (view the code at &lt;a href="http://cascadingdataviewer.codeplex.com/SourceControl/changeset/view/58999#1568990" target="_blank"&gt;changeset 58999&lt;/a&gt;), that’s a lot of code and much of it is repeated. I would have loved to have hived off different parts into dedicated functions but I couldn’t do that because my aim was to keep everything in a single stored procedure thus making it as easy as possible for someone to add it to their SQL Server instance. That is an unfortunate trade-off that we have to make with SQL Server.&lt;/p&gt;  &lt;p&gt;Oracle has a solution to this problem called packages. A package is ostensibly a collection of stored procedures and functions that can be distributed and installed as a single unit. That makes them extremely portable and would be an ideal mechanism for me to distribute a collection of stored procedures and functions that make up Cascading Data Viewer.&lt;/p&gt;  &lt;p&gt;SQL Server needs something equivalent to Oracle packages.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h2&gt;You need to be doing automated database unit testing&lt;/h2&gt;  &lt;p&gt;sp_CascadingDataViewer wouldn’t exist without automated database unit testing in Visual Studio. Period.&lt;/p&gt;  &lt;p&gt;With something as complicated as sp_CascadingDataViewer there were many many combinations of code, schema and data that could cause is to break. I had to deal with all those combinations and have a way of ensuring that any changes that I made did not break something else and automated testing was the means with which I did that.&lt;/p&gt;  &lt;p&gt;I wrote the code for sp_CascadingDataViewer in Visual Studio rather than SQL Server Management Studio (as I do for all my T-SQL code these days) which meant that my code and the tests lived in the same solution. At the time of writing that solution includes 30 tests and all are available in &lt;a href="http://cascadingdataviewer.codeplex.com/SourceControl/list/changesets" target="_blank"&gt;the source code on Codeplex&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5F31D6E2.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:;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://sqlblog.com/blogs/jamie_thomson/image_thumb_79CE4D2E.png" width="529" height="628" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;With a simple key chord (CTRL+R, CTRL+A) I could deploy my code and run all my tests against it – that’s an incredibly powerful mechanism and I actually find it to be very productive method of development even if you have many tests that need to be run.&lt;/p&gt;  &lt;p&gt;Writing sp_CascadingDataViewer switched me on to the value of automated database unit testing and I now advocate its use wherever I go.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=28849" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item></channel></rss>