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

<channel>
	<title>SQL Server &#8211; Cognim &#8211; Internet development</title>
	<atom:link href="https://www.cognim.co.uk/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.cognim.co.uk</link>
	<description>Enterprise system implementation. Making the complex simple</description>
	<lastBuildDate>Mon, 27 Jul 2015 16:59:11 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">91553907</site>	<item>
		<title>How to export a lot of data from on-prem SQL Server to Azure SQL for testing</title>
		<link>https://www.cognim.co.uk/how-to-export-a-lot-of-data-from-on-prem-sql-server-to-azure-for-testing/</link>
					<comments>https://www.cognim.co.uk/how-to-export-a-lot-of-data-from-on-prem-sql-server-to-azure-for-testing/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Thu, 02 Jul 2015 09:52:06 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[data warehouse]]></category>
		<category><![CDATA[SSIS]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=4929</guid>

					<description><![CDATA[Lately we have created several data marts in Azure SQL that will be fed from a data warehouse hosted on premises. The data mart is first created and tested locally so that we can get the structure and required stored procs correct. Whilst we are doing this it is easy to quickly transfer representative data to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Lately we have created several data marts in Azure SQL that will be fed from a data warehouse hosted on premises. The data mart is first created and tested locally so that we can get the structure and required stored procs correct. Whilst we are doing this it is easy to quickly transfer representative data to test the efficiency. Every now and then though we need to test everything on Azure so that we can be sure we are still operating at an acceptable speed. This is where the problems begin. Linked servers are a no-go if you are transferring large amounts of data to Azure which will treat every insert as a separate transaction. We could back up the database, copy it to blob storage and restore from there but that takes a while as well and sometimes it is just a single large staging table that we want to populate. We could hand craft an SSIS package which would be fast but seems overkill considering the amount of times we adjust and retest.</p>
<p>The answer is actually quite simple thanks to a little promoted feature of SSMS. Follow the steps below to see how</p>
<ol>
<li>Right click the database you wish to export data from</li>
<li>Select &#8216;Tasks&#8217; then &#8216;Export Data&#8217;<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4937 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Tasks-ExportData.png?resize=516%2C530&#038;ssl=1" alt="Tasks-ExportData" width="516" height="530" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Tasks-ExportData.png?w=516&amp;ssl=1 516w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Tasks-ExportData.png?resize=292%2C300&amp;ssl=1 292w" sizes="auto, (max-width: 516px) 100vw, 516px" /></li>
<li>You will see theSQL Server Import and Export Wizard. Click &#8216;Next&#8217; to go past the welcome screen and make sure your source is correctly selected (it will have been if you started by right clicking the database), then click &#8216;Next&#8217; again<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4938 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/YourSource.png?resize=566%2C579&#038;ssl=1" alt="YourSource" width="566" height="579" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/YourSource.png?w=566&amp;ssl=1 566w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/YourSource.png?resize=293%2C300&amp;ssl=1 293w" sizes="auto, (max-width: 566px) 100vw, 566px" /></li>
<li>Now you can choose the destination database, note that for Azure you need to select &#8216;Net Framework Data Provider for SqlServer&#8217; in the destination drop down</li>
<li>This will cause connection properties to appear. For Azure you need to set the data source,userid, password andinitial catalog. I would also recommend setting connection encryption as I have below.<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4932 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/AzureConnection.png?resize=566%2C1027&#038;ssl=1" alt="AzureConnection" width="566" height="1027" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/AzureConnection.png?w=566&amp;ssl=1 566w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/AzureConnection.png?resize=165%2C300&amp;ssl=1 165w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/AzureConnection.png?resize=564%2C1024&amp;ssl=1 564w" sizes="auto, (max-width: 566px) 100vw, 566px" /></li>
<li>You can now either copy data directly from a table or view or write your own query. Such power! Here I have elected to copy data from a table in the source database, but bear in mind that you could easily write a query to limit the number of rows or transform the data in some way.<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4935 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTable.png?resize=566%2C604&#038;ssl=1" alt="SelectTable" width="566" height="604" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTable.png?w=566&amp;ssl=1 566w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTable.png?resize=281%2C300&amp;ssl=1 281w" sizes="auto, (max-width: 566px) 100vw, 566px" /></li>
<li>Choose the table or tables with data you want to copy. The wizard will automatically try to choose a matching table on your destination database or suggest auto creating it if it does not exist. Click &#8216;Edit Mappings&#8217; for each table you are transferring to see where your data will go.<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4936 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTablesToExport.png?resize=566%2C604&#038;ssl=1" alt="SelectTablesToExport" width="566" height="604" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTablesToExport.png?w=566&amp;ssl=1 566w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/SelectTablesToExport.png?resize=281%2C300&amp;ssl=1 281w" sizes="auto, (max-width: 566px) 100vw, 566px" /><br /> Here I have chosen two tables that exist in both source and destination and have the same structure and a third table that is different on the destination database. By highlighting that row and clicking &#8216;Edit Mappings&#8217; you can choose exactly where your data will go on a row by row basis. Again, the wizard will auto suggest the best fits.<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4933 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Mappings.png?resize=609%2C506&#038;ssl=1" alt="Mappings" width="609" height="506" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Mappings.png?w=609&amp;ssl=1 609w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/Mappings.png?resize=300%2C249&amp;ssl=1 300w" sizes="auto, (max-width: 609px) 100vw, 609px" /><br /> Here there are no columns that are named the same so the wizard leaves it entirely up to you. You can also choose to preview the data.</li>
<li>Having mapped your source to your destination, click &#8216;Next&#8217;. Thefinal step is to either run the package immediately or save it as a package toSSIS. I usually run immediately if it is just a quick transfer I am after. Here I have selected both.<img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-4934 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/RunOrSave.png?resize=566%2C604&#038;ssl=1" alt="RunOrSave" width="566" height="604" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/RunOrSave.png?w=566&amp;ssl=1 566w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/07/RunOrSave.png?resize=281%2C300&amp;ssl=1 281w" sizes="auto, (max-width: 566px) 100vw, 566px" /></li>
<li>Finally you can click &#8216;Finish&#8217; to execute the package. Note that you have created an SSIS package and you will see feedback on the progress as it goes, including number of rows transferred. If it encounters any problems it will stop and tell you.</li>
</ol>
<p>Overall an excellent way to quickly transfer data from one system to another. Especially useful where you need to transform that data, map between two different schemas or send it to Azure.</p>
<p>What are you waiting for? Go Play!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/how-to-export-a-lot-of-data-from-on-prem-sql-server-to-azure-for-testing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4929</post-id>	</item>
		<item>
		<title>Adding tables of static data to an SSDT project</title>
		<link>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/</link>
					<comments>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Mon, 15 Sep 2014 15:54:06 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[data warehouse]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=71</guid>

					<description><![CDATA[Quite often when creating a database you will need tables of static data.  These range from simple lookups to date dimensions in a data warehouse.  You can easily create these in an SSDT project. Presuming you have already designed your tables and they are present in your project; Create a folder in your project called [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Quite often when creating a database you will need tables of static data.  These range from simple lookups to date dimensions in a data warehouse.  You can easily create these in an SSDT project.</p>
<p>Presuming you have already designed your tables and they are present in your project;</p>
<ul>
<li>Create a folder in your project called StaticData then add a sql script to generate the data you require, one for each table.  For instance I have a date dimension table called Dim_Date and have created a script called Populate_Dim_Date.sql.<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/staticsqlscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-76" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/staticsqlscript.png?resize=244%2C258&#038;ssl=1" alt="StaticSQLScript" width="244" height="258" /></a></li>
<li>Next create a script called &#8216;Script.PostDeployment.sql&#8217; in the root of your project by right clicking your project and choosing &#8216;Add&#8217; then &#8216;Script&#8217;<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-75" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?resize=300%2C146&#038;ssl=1" alt="AddScript" width="300" height="146" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?w=665&amp;ssl=1 665w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/addscript.png?resize=300%2C147&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><br /> and choosing &#8216;user scripts&#8217; in the SQL Server section, followed by &#8216;Post-Deployment Script&#8217;, then clicking the Add button.<br /> <a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-74" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?resize=300%2C207&#038;ssl=1" alt="PostDeploymentScript" width="300" height="207" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?w=955&amp;ssl=1 955w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdeploymentscript.png?resize=300%2C207&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></li>
</ul>
<p>This will create a script that runs following the full deployment of your project and you can direct it to step through each of your sql creation scripts in the StaticData folder we created earlier. To do this you simply add a SQLCMD read command to the post deployment script for each of the sql files you want to execute. Here I have added a command to read (include) the script I created for the date dimension.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-77" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?resize=300%2C135&#038;ssl=1" alt="PostDepScript" width="300" height="135" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?w=776&amp;ssl=1 776w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2014/09/postdepscript.png?resize=300%2C135&amp;ssl=1 300w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>Note that to prevent an infestation of the red squigglies you will need to select the icon that represents placing the editor in SQLCMD Mode, in my image above it is the icon with a blue border.</p>
<p>Now when you publish your project your tables will be populated according to your scripts &#8211; easy peasy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">71</post-id>	</item>
		<item>
		<title>Adding database references to a sql server project</title>
		<link>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/</link>
					<comments>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 09 Sep 2014 11:24:33 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=57</guid>

					<description><![CDATA[If you are creating a sql server project with SSDT (see here) and your sql refers to another database you will need to add a database reference to allow the project to build. You can do this by right clicking your references folder and selecting &#8216;Add Database Reference&#8217; If the database you are referring to is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you are creating a sql server project with SSDT (<a title="Creating a SQL Project from an existing database" href="https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/">see here</a>) and your sql refers to another database you will need to add a database reference to allow the project to build. You can do this by right clicking your references folder and selecting &#8216;Add Database Reference&#8217;</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/adddatabasereference.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-62" src="http://makesharp.files.wordpress.com/2014/09/adddatabasereference.png?resize=244%2C166" alt="AddDatabaseReference" width="244" height="166" /></a></p>
<p>If the database you are referring to is also a part of the solution &#8211; for instance if you are creating a data warehouse and you have a supporting staging database, it is very similar to the process of adding an external project reference to a c# project. you just need to select &#8216;Database projects in the current solution&#8217; and choose your database from the dropdown list.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/database-project-in-the-current-solution.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-63" src="http://makesharp.files.wordpress.com/2014/09/database-project-in-the-current-solution.png?w=300&#038;resize=300%2C93" alt="Database project in the current solution" width="300" height="93" /></a></p>
<p>You can also reference a system database here. Occasionally however you will need to reference a database that is neither of the above.  If the database you need to reference is already a data tier application you can browse for the dacpac but if it is not (for instance it may be a legacy database) you will need to create a data tier application from it first.</p>
<p>To extract a dacpac from an existing database, open the sql server object explorer in Visual Studio, connect to the server, right click the database and choose &#8216;Extract Data-tier application&#8217;.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/extract-data-tier-app.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-64" src="http://makesharp.files.wordpress.com/2014/09/extract-data-tier-app.png?w=262&#038;resize=262%2C300" alt="Extract Data Tier app" width="262" height="300" /></a></p>
<p>Choose where to save the dacpac, then select &#8216;Extract Schema Only&#8217; and decide whether you need the additional options such as user login mappings etc. Once you have created the dacpac you can go back to the add database reference dialog and select the dacpac you just created.</p>
<p><strong>Database Location</strong></p>
<p>In the Database Location section of the Add Database Reference dialog set the location of the referenced database e.g. &#8216;Different database, same server&#8217;, the name of the database (should be pre-filled) and whether you want to add a database variable to embed into your sql instead of a hardcoded path.  Finally (and often very importantly!) you may want to check the &#8216;Supress errors caused by unresolved references in the referenced project&#8217; option at the bottom of the dialog.  This is especially useful in legacy databases that themselves reference other databases.</p>
<p><a href="http://makesharp.files.wordpress.com/2014/09/add-database-reference.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-61" src="http://makesharp.files.wordpress.com/2014/09/add-database-reference.png?w=300&#038;resize=300%2C210" alt="Add Database Reference" width="300" height="210" /></a></p>
<p>After clicking ok you should be good to go. This reference is there just to allow the application to compile, it does not get included in the deployment, but is an excellent way of making sure that your external references are correct.</p>
<p>As a final note, you need to ensure that your references are kept up to date if you are working on a project.  Although you can create a NuGet feed for your created dacpacs, as of Sept 2014 NuGet does not yet support importing to an SSDT project. For now you will have to keep a manual check.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">57</post-id>	</item>
		<item>
		<title>Creating a Visual Studio SQL Project from an existing database</title>
		<link>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/</link>
					<comments>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 29 Jul 2014 15:24:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=23</guid>

					<description><![CDATA[There are all sorts of reasons why this is a good idea.  Not least because you can version control, unit test and tie into your CI system any existing database. How many times have you found inconsistencies between a test and live database, not known which one is right and been unsure who to ask [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>There are all sorts of reasons why this is a good idea.  Not least because you can version control, unit test and tie into your CI system any existing database.</p>
<p>How many times have you found inconsistencies between a test and live database, not known which one is right and been unsure who to ask on your team?  In my experience, especially in smaller teams with no DBA, this happens a lot and people do bad things like edit the live database directly (&#8220;Hmmm, according to the query plan I need to add an index.  I&#8217;ll just do that now.&#8221;).</p>
<p>By creating a SQL Server project using SSDT</p>
<ul>
<li>You will know exactly who changed what and when.</li>
<li>You can fail a publish if database drift is detected (ie the database you are publishing to is different from the last time you published because someone changed something directly).</li>
<li>You can create unit tests with standardised data that run against a fresh database.</li>
<li>You can track database refactoring (ie changing a column name) so that tables are not dropped and rebuilt when published.</li>
<li>You can fail a publish if data loss will occur.</li>
<li>You can fully automate deployment to multiple servers and bring them all to a standard level regardless of their current version.</li>
</ul>
<p>So much good stuff!</p>
<h2>Here&#8217;s how you do it.</h2>
<p>First, make sure you have the <a href="http://msdn.microsoft.com/en-us/data/gg427686">latest version of SSDT</a>.</p>
<p><strong>Create the project</strong></p>
<ol>
<li>In Visual Studio, select File / New Project.</li>
<li>Under Templates. click &#8216;SQL Server&#8217; and choose &#8216;SQL Server Database Project&#8217;</li>
<li>Name your project according to the database you are importing and also name your solution, then click OK.<br />
<a href="http://makesharp.files.wordpress.com/2014/07/filenew.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-25" src="http://makesharp.files.wordpress.com/2014/07/filenew.png?w=300&#038;resize=300%2C188" alt="FileNew" width="300" height="188" /></a></li>
</ol>
<p><strong>Import your database</strong></p>
<ol>
<li>Right click the project you just created and select Import, then Database</li>
<li>Select your database from the Source Database Connection dropdown list, or use the New Connection button to add it.</li>
<li>In addition to the default Import Settings that are selected I usually also select &#8216;Import Database Settings&#8217; so that the correct database version is chosen in the project properties. Otherwise you can usually leave everything else as is.<a href="https://makesharp.files.wordpress.com/2014/07/import.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-medium wp-image-33" src="http://makesharp.files.wordpress.com/2014/07/import.png?w=300&#038;resize=300%2C257" alt="Import" width="300" height="257" /></a></li>
</ol>
<p><strong>Check your folders and files</strong></p>
<p>At this point you will have a folder structure based on the database schema &#8211; if you only use dbo then you will only see that, otherwise you will see a folder per schema and an additional security folder where sql for creating your schemas has been put. (This is also where you put sql for new schemas)<a href="https://makesharp.files.wordpress.com/2014/07/structure.png"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter size-full wp-image-41" src="http://makesharp.files.wordpress.com/2014/07/structure.png?resize=289%2C252" alt="Structure" width="289" height="252" /></a> Here you can see that my database has two schemas &#8211; dbo and IntegrationTest. SSDT also separates out your functions, stored procs and tables. In the Security folder you can see the sql for creating the IntegrationTest schema.</p>
<p>If there is anything missing at this point you may want to check the import settings. You can always delete all the added files and folders and do the import again.</p>
<p><strong>Build and be happy!</strong></p>
<p>Right click your project and select Build.</p>
<ul>
<li>If there are no external references the project will build and create a dacpac. This will be saved in your bin directory in the appropriate configuration folder.</li>
<li>If there are external references required you will need to add them. <a title="Adding database references to a sql server project" href="https://www.cognim.co.uk/adding-database-references-to-a-sql-server-project/">I have blogged how to do this here</a>.</li>
</ul>
<p>You can also add static data such as lookup tables or date dimensions and again <a title="Adding tables of static data to an SSDT project" href="https://www.cognim.co.uk/adding-tables-of-static-data-to-an-ssdt-project/">I have blogged about this here</a>.</p>
<p>We are now at a stage where you can version control your database and to publish it to a particular server you just need to right click the project and select &#8216;Publish&#8217;. Note that there are several options when publishing and you can create profiles for different servers.  <a href="https://www.cognim.co.uk/ssdt-using-publishing-profiles-and-teamcity-integration/">I have blogged about how to do that here.</a></p>
<p>Good luck!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/creating-a-sql-project-from-an-existing-database/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">23</post-id>	</item>
		<item>
		<title>Visual Studio SSDT and TeamCity &#8211; What you need to do.</title>
		<link>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/</link>
					<comments>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Mon, 28 Jul 2014 11:44:20 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Team City]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/2014/07/28/ssdt-and-teamcity-what-you-need-to-do/</guid>

					<description><![CDATA[I have just spent the last few days trying to get a SQL Project to build, deploy, run unit tests and create a dacpac on our build server which uses TeamCity. It wasn&#8217;t a simple process and I had to accept a few conditions that I wasn&#8217;t overly keen on but the upshot is that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I have just spent the last few days trying to get a SQL Project to build, deploy, run unit tests and create a dacpac on our build server which uses TeamCity. It wasn&#8217;t a simple process and I had to accept a few conditions that I wasn&#8217;t overly keen on but the upshot is that it works now and it works well.</p>
<p>Here is the outline of how it all hangs together, I will do a few more detailed posts to follow up.</p>
<p>The solution itself consists of three projects. Two database projects and a unit test project.  They are checked into GIT (using <a href="https://bitbucket.org/">BitBucket</a>) and <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> watches the repository to trigger a build.  The build creates a dacpac for each database, publishes the changes to the appropriate server, runs the unit tests and saves the dacpacs into a nuget package that is <a href="http://confluence.jetbrains.com/display/TCD8/NuGet?_ga=1.7707770.999349697.1405089901">published by TeamCity itself</a>.</p>
<p>Out of the box, TeamCity can handle the build but you need MSTest and SSDT installed on the build server.  That is where your troubles begin.  You can download an MSTest agent as I wrote about <a href="https://www.cognim.co.uk/teamcity-and-msbuild-mstest/">here</a>.  You can even <a href="http://stackoverflow.com/questions/22241295/build-sql-server-data-tools-for-visual-studio-2013-project-on-build-server-wit">install the SSDT tools for VS2012</a> (though that was a bit hit and miss for me). The real problem is that with VS2013 the SSDT tools are integrated and no longer available as a separate download.  In the end I had to settle for installing VS2013 on the build server.  Microsoft allows your developer license to be used on the build server and at least I can easily update the SSDT version &#8211; I&#8217;m not particularly happy about having to do it though.</p>
<p>In order to publish your database to the correct server you just need to include appropriate <a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/09/publish-profile-files-in-sql-server-data-tools-ssdt.aspx">publish profile files </a>and Microsoft have provided the ability in database unit tests to switch config files according to the build server machine name. The publishing part worked fine for me but the config switching seems flaky and if you put a whitespace in the wrong place your config will be ignored.  My workaround here was to resort to <a href="https://www.nuget.org/packages/SlowCheetah/">Slow Cheetah</a> &#8211; a plugin from NuGet that allows config switching for app.config in the same way that you can achieve it with web.config. This works well but remember to restore your nuget packages as the first build step in TeamCity. It&#8217;s not so restrictive as a config that switches based on machine name (we only have a single build server so would be unable to test on multiple platforms).</p>
<p>The result is that on every check in, the dacpacs are built, deployed to a test environment, tested and if they pass, made available via a nuget feed for other projects.</p>
<p>It feels good when it all just starts working!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/ssdt-and-teamcity-what-you-need-to-do/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">20</post-id>	</item>
		<item>
		<title>Go to SQLBits!</title>
		<link>https://www.cognim.co.uk/go-to-sqlbits/</link>
					<comments>https://www.cognim.co.uk/go-to-sqlbits/#respond</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Mon, 21 Jul 2014 21:17:57 +0000</pubDate>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://makesharp.wordpress.com/?p=8</guid>

					<description><![CDATA[Ok, so you&#8217;ve missed it this year, but next year&#8230; Go to SQLBits! I can&#8217;t say it enough.  It is the best conference in Europe for learning SQL, it is extremely cheap. it is non-profit and it&#8217;s a lot of fun.  I&#8217;ve been going for the past 5 years and have never regretted it. This [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Ok, so you&#8217;ve missed it this year, but next year&#8230;</p>
<p>Go to <a href="http://www.sqlbits.com/" target="_blank">SQLBits</a>!</p>
<p>I can&#8217;t say it enough.  It is the best conference in Europe for learning SQL, it is extremely cheap. it is non-profit and it&#8217;s a lot of fun.  I&#8217;ve been going for the past 5 years and have never regretted it. This year was no exception, the conference itself runs from Thursday to Saturday with (this year) a pub quiz night (attended by several hundred people) on the Thursday and a big party on the Friday.  All of Saturday is free to attend and of course lunch and drinks are provided.</p>
<p>As a professional developer I consider it essential to attend conferences and try to make it to two or three a year, if your company considers itself professional too, it should pay for you to go. Speak to your manager, colleagues, friends, pets &#8211; whomever it takes &#8211; and get yourself a place at SQLBits next year, you won&#8217;t regret it.</p>
<p>Highlights from this year for me included <a href="http://www.brentozar.com/" target="_blank">Brent Ozars</a> excellent session &#8216;Watch Brent Tune Queries&#8217;, <a href="http://tsqlninja.wordpress.com/" target="_blank">David Morrisons</a> &#8216;SQL Tips, Tricks and Misconceptions&#8217; and <a href="http://mvp.microsoft.com/en-us/mvp/Peter%20ter%20Braake-4039720" target="_blank">Peter Ter Braakes</a> &#8216;Power BI from Zero to Expert&#8217;.</p>
<p>See you there next year!</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/go-to-sqlbits/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8</post-id>	</item>
	</channel>
</rss>
