Search results matching tags 'developer', 'Tutorials', and 'Development'http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&tag=developer,Tutorials,Development&orTags=0Search results matching tags 'developer', 'Tutorials', and 'Development'en-USCommunityServer 2.1 SP2 (Build: 61129.1)Windows Azure End to End Exampleshttp://sqlblog.com/blogs/buck_woody/archive/2012/05/29/windows-azure-end-to-end-examples.aspxTue, 29 May 2012 13:45:59 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:43642BuckWoody<p>I’m fascinated by the way people learn. I’m told there are several methods people use to understand new information, from reading to watching, from experiencing to exploring. </p> <p>Personally, I use multiple methods of learning when I encounter a new topic, usually starting with reading a bit about the concepts. I quickly want to put those into practice, however, especially in the technical realm. I immediately look for examples where I can start trying out the concepts. But I often want a “real” example – not just something that represents the concept, but something that is real-world, showing some feature I could actually use. </p> <p>And it’s no different with the Windows Azure platform – I like finding things I can do now, and actually use. So when I started learning Windows Azure, <a href="http://www.microsoft.com/en-us/download/details.aspx?id=8396" target="_blank">I of course began with the Windows Azure Training Kit</a> – which has lots of examples and labs, presentations and so on. But from there, I wanted more examples I could learn from, and eventually teach others with. I was asked if I would write a few of those up, so here are the ones I use. </p> <h2>CodePlex</h2> <p><a href="http://www.codeplex.com/" target="_blank">CodePlex is Microsoft’s version of an “Open Source” repository</a>. Anyone can start a project, add code, documentation and more to it and make it available to the world, free of charge, using various licenses as they wish. Microsoft also uses this location for most of the examples we publish, and sample databases for SQL Server. </p> <p>If you search in CodePlex for “Azure”, you’ll come back with a list of projects that folks have posted, including those of us at Microsoft. The source code and documentation are there, so you can learn using actual examples of code that will do what you need. There’s everything from a simple table query to <a href="http://blobshare.codeplex.com/" target="_blank">a full project that is sort of a “Corporate Dropbox” that uses Windows Azure Storage</a>. </p> <p>The advantage is that this code is immediately usable. It’s searchable, and you can often find a complete solution to meet your needs. The disadvantage is that the code is pretty specific – it may not cover a huge project like you’re looking for. Also, depending on the author(s), you might not find the documentation level you want. </p> <p><strong><em>Link: <a href="http://azureexamples.codeplex.com/site/search?query=Azure&amp;ac=8">http://azureexamples.codeplex.com/site/search?query=Azure&amp;ac=8</a>&#160;</em></strong></p> <p>&#160;</p> <h2>Tailspin</h2> <p><a href="http://msdn.microsoft.com/en-us/practices/default" target="_blank">Microsoft Patterns and Practices</a> is a group here that does an amazing job at sharing standard ways of doing IT – from operations to coding. If you’re not familiar with this resource, make sure you read up on it. Long before I joined Microsoft I used their work in my daily job – saved a ton of time. It has resources not only for Windows Azure but other Microsoft software as well. </p> <p>The Patterns and Practices group also publishes full books – you can buy these, but many are also online for free. There’s an end-to-end example for Windows Azure using a company called “Tailspin”, and the work covers not only the code but the design of the full solution. If you really want to understand the thought that goes into a Platform-as-a-Service solution, this is an excellent resource. </p> <p>The advantages are that this is a book, it’s complete, and it includes a discussion of design decisions. The disadvantage is that it’s a little over a year old – and in “Cloud” years that’s a lot. So many things have changed, improved, and have been added that you need to treat this as a resource, but not the only one. Still, highly recommended. </p> <p><strong><em>Link: <a href="http://msdn.microsoft.com/en-us/library/ff728592.aspx">http://msdn.microsoft.com/en-us/library/ff728592.aspx</a></em></strong></p> <h2>Azure Stock Trader</h2> <p>Sometimes you need a mix of a CodePlex-style application, and a little more detail on how it was put together. And it would be great if you could actually play with the completed application, to see how it really functions on the actual platform.</p> <p>That’s the Azure Stock Trader application. There’s a place where you can read about the application, and then it’s been published to Windows Azure – the production platform – and you can use it, explore, and see how it performs. </p> <p>I use this application all the time to demonstrate Windows Azure, or a particular part of Windows Azure.</p> <p>The advantage is that this is an end-to-end application, and online as well. The disadvantage is that it takes a bit of self-learning to work through.&#160; </p> <p><strong><em>Links: Learn it: <a href="http://msdn.microsoft.com/en-us/netframework/bb499684">http://msdn.microsoft.com/en-us/netframework/bb499684</a> Use it: <a href="https://azurestocktrader.cloudapp.net/">https://azurestocktrader.cloudapp.net/</a></em></strong></p>Code that Writes Codehttp://sqlblog.com/blogs/buck_woody/archive/2009/11/25/code-that-writes-code.aspxWed, 25 Nov 2009 14:01:40 GMT21093a07-8b3d-42db-8cbf-3350fcbf5496:19171BuckWoody<p>I have scripts that re-create my databases for testing and development purposes. But sometimes I want to take the data from a set of tables and move it as well – I could use SSIS, or a SELECT INTO statement, but what if I want to “re-set” the data to a point in time? In other words, load it with some “base data”? </p> <p>I thought this might be a good place to demonstrate “code that writes code”. No, it isn’t that big of a deal – most DBAs know how to do this, but in the interest of those who don’t, I thought I would share.</p> <p>So the end result I want in this case is to have a bunch of INSERT statements that contain my base data from a table where that data already exists. I could script out the table from SSMS and use the replacement parameter feature to fill out each record individually:</p> <p>I have a table in one of my databases that I right-clicked to show the INSERT statement:</p> <font color="#008000" size="2"><font color="#008000" size="2"> <p>-- Person</p> </font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> <p>INSERT</p> </font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INTO</font></font><font color="#000000" size="2"> [WAVS]</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">[dbo]</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">[Person]</font></font></font><font size="2"><font size="2"> <p></p> </font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2"><font color="#000000">[PersonName]</font></font> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2">[Street]</font> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2">[CityStateZip]</font> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2">[PersonType]</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></font><font size="2"> <p></p> <font color="#0000ff" size="2"><font color="#0000ff" size="2">VALUES</font> <p></p> </font><font color="#808080" size="2"><font color="#808080" size="2">(&lt;</font></font><font color="#000000" size="2">PersonName</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">varchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">150</font><font color="#808080" size="2"><font color="#808080" size="2">),&gt;</font></font></font><font size="2"> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,&lt;</font></font><font size="2">PersonStreet</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">varchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),&gt;</font></font></font><font size="2"> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,&lt;</font></font><font size="2">PersonCityStateZip</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">varchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">),&gt;</font></font></font><font size="2"> <p></p> <font color="#808080" size="2"><font color="#808080" size="2">,&lt;</font></font><font size="2">PersonPersonType</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">varchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),&gt;)</font></font></font> <p><font color="#808080"><font color="#808080"><font color="#333333" size="2">I can use the CTRL-SHIFT-M keys to replace the VALUES part with the values I want.&#160; </font></font></font></p> <p><font color="#808080"><font color="#808080"><font color="#333333" size="2">But I already had a copy of that “base” data before I turned the database over to the testers. Before I give it to them, I run code like this on each table – this one is for the <em>Person</em> table above (note that there should only be two lines here):</font></font></font></p> <font color="#808080"><font color="#808080"><font color="#333333"><font color="#0000ff"><font color="#0000ff"> <p><font size="2">SELECT</font></p> </font><font size="2"><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">'INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES ('</font></font><font color="#000000"> </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> </font><font color="#ff00ff"><font color="#ff00ff">CAST</font></font><font color="#808080"><font color="#808080">(</font></font><font color="#000000">[PersonID] </font><font color="#0000ff"><font color="#0000ff">AS</font></font><font color="#000000"> </font><font color="#0000ff"><font color="#0000ff">VARCHAR</font></font><font color="#808080"><font color="#808080">(</font></font><font color="#000000">5</font><font color="#808080"><font color="#808080">))+</font></font><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">', '''</font></font><font color="#000000"> </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> [PersonName]</font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">''', '''</font></font><font color="#000000"> </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> [Street]</font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">''', '''</font></font><font color="#000000"> </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> [CityStateZip] </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">''', '''</font></font><font color="#000000"> </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> [PersonType] </font><font color="#808080"><font color="#808080">+</font></font><font color="#000000"> </font><font color="#ff0000"><font color="#ff0000">''')'</font></font></font></font><font color="#0000ff"><font color="#0000ff"> <p><font size="2">FROM</font></p> </font><font size="2"><font color="#000000"> [WAVS]</font><font color="#808080"><font color="#808080">.</font></font><font color="#000000">[dbo]</font><font color="#808080"><font color="#808080">.</font></font><font color="#000000">[Person]</font></font></font> <p><font color="#000000" size="2">When I run this code, I get these statements:</font></p> <p><font color="#0080c0" size="2">INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (1, 'Buck Woody', '123 Here Street', 'Covington, WA 98042', 'Vet') <br />INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (2, 'Jane Doe', '231 Function Ave', 'Redmond, WA 98052', 'Vet') <br />INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (3, 'Diane Wilson', '34251 Appt 3 7th Street', 'Seattle, WA 98061', 'Vet') <br />INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (4, 'John Kelso', '89734 Country Lane', 'Covington, WA 98042', 'Farmer') <br />INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (5, 'Marjorie Christian', '9893452 Changein Lane', 'Maple Valley, WA 98072', 'Farmer') <br />INSERT INTO [WAVS].[dbo].[Person] ([PersonID], [PersonName], [Street], [CityStateZip], [PersonType]) VALUES (6, 'Joanne Lister', '98904 Mapelwood Drive', 'Spokanne, WA 98045', 'Zoo Worker')</font></p> <p><font size="2">All I have to do is copy those statements into my “initialization” scripts just after the table creations, and then I can run them at will to create my new database (I know I can take a backup – I have reasons for not doing that).</font></p> <p><font size="2">There are two keys for writing code that writes code: The first is to simply use the single tick (') to write out what the end code should say (INSERT INTO, in my case) and then to use multiple ticks (''') when you want the code to contain the ticks themselves. This “escapes” the characters so that you can embed them. If you use SSMS to write your queries, the color coding will look as mine does above. You’ll also need to remember to CAST or CONVERT any data types that don’t concatenate (+) together well. In my case I had to CAST an integer value – but that’s OK, since it is only printing to the screen and I don’t include the ticks, the INSERT works fine.</font></p> <p><font size="2">You can use this method not only with INSERTS, but with lots of operations. And you can also even fire off the code once you create it – but that’s another post :)</font></p> <p><font size="2">&#160;</font></p> </font></font></font>