Database development with SSDT and Azure

One of the new things in the development tool to SQL server 2012 (SSDT) is the database project as shown in the picture below. Before 2012 it was a part of visual studio, but now you can get it for free in the data tools.

I’m guessing that that is one of the reasons for the name change from BIDS 🙂

But I’m rambling. Let me start by describing a typically way of database development.

  • You develop your database  in a development environment with management studio
  • When you want to deploy, you create a change script that will be executed on the production server.(There may be servers in between like test, preprod etc., but let’s not add those into the mix)

Well, that’s pretty much it.

The updated database might be used by a lot of other applications. Maybe the database is even the main part of a specific application.

There are a lot of problems in regards to this way of developing. Some of them are

  • There is no test of references in Management studio. If you change a table that is used by for instance a view, you won’t automatically catch it.
  • The change script might be error prone. Especially if there is no connection between develop and production servers, so you can’t compare them with a tool like Redgate or Atlantis.
  • There may be a “drift” in the production database, which mean that a DBA for instance can have added an index to the production server, because he wrongly thinks he knows more about it than you 🙂 or Maybe someone created a view to be used for reporting etc.
  • You don’t have source control.

That’s just some of the problem you will have with that kind of database development. The above problems and many others are addressed in the SQL server database project.

Let me demonstrate some of it with an example.

Let’s first create the project. If you look at the screenshot below you’ll see that there are 2 SQL server menus. The reason for that, is that I have visual studio 2010 installed along side with data tools. The project that is marked is the new one from data tools, and is of course a newer and better version. Select that one.

Figure 1 – Create the project

When you have created the project, you have an empty project. In my case I want to continue working on the Azure SQL project I started on in a previous blog post. So I just right click the project, click import, and type in the connection to my Azure database, and click start.

Figure 2 – Import the Azure database

And badabim. Now I have my database in my development tool, and I can add it to source control alongside my other projects. All my database objects are now shown in the solution explorer. There are about 100 different object types. Right now, I only have one table, but that is fine for my example.

If I double click the product table, I get the view as shown below.

Figure 3 – The designer

You can edit the table either in the designer at the top, or in SQL at the bottom.

You can build your project, and you will get errors, if you are using keywords that are not available in the target platform or have an invalid reference etc.

And regarding the target platform. You can change it in the properties window. As shown below.

Figure 4 – Change the target platform

If you change the target to Azure, you will get errors if you don’t have a clustered index on all of your tables, since that is a requirement in SQL Azure. Likewise, if you use file groups in Azure, you will get a compile error since that of course make no sense in Azure etc.

In my example, I would like to work with stocks. I delete the product table, and add two new, so I get what is shown below.

Figure 5 – The new tables

I can now from my development tool, do a schema compare and synchronize with the development/production server.

Figure 6 – Schema compare

In my example, I just have the Azure database, so I just synchronize that.

I can look at my azure database and see that it has been synchronized.

Figure 7 – The azure database have been updated. Nice 🙂

So the conclusion: I must admit I’m really exited about the update of the database project, and the fact that it is now free to use along with the other data tools.

It addresses a lot of common problems when doing database development that you would normally have.

I can’t imagine myself starting a 2012 database project, and then not use this tool. No matter if it is a DWH, BI or application project I will be working on.

Change ”select top 1000” to ”Select top XXX”

In SQL server management studio, when you right click on a table, there is a shortcut to select top 1000 or edit top 200 rows. Se pic below.

It is an easy way, when you just want to see some of the data in a table, or if you want to edit some values in a small table. If you are using the 2 shortcuts you can change 1000 and 200 to values that make sense to you.

Click options->SQL Server Object Explorer. Then you get the options as shown in the pic below.

Change the values to your needs, and voila, now you have select top yyyy 🙂

Unboxing Azure part 1: The new Portal & how to create an Azure SQL database

Not so long ago, Microsoft(MS) announced a lot of new and cool features to their Azure platform at their event “Meet windows Azure”

There is no doubt that MS is expanding fast in the cloud, and with this blog series I will try to give a short overview of the business intelligence(BI) capabilities that are currently available in Azure.

The new Portal

MS have updated there portal, so that it is now primarily is using HTML5. It looks like this.

The new portal is intuitive and easy to use. One of the new exiting things is the virtual machines, where you for instance can create a windows server, and do the stuff that are not currently supported in other services in Azure. In the BI world, that could be installing a SQL server to use the SQL server agent to run SSIS packages or to host analysis services, since these services are not supported other places in Azure right now.

The new portal is still in “Preview”. I don’t know precisely what that means, but if there is something you are missing, you can go to the old Silverlight portal by clicking on the portal link in the top right corner.

SQL Azure

But first things first. When we are talking BI we have to start with a database. Click the SQL databases item, and click create database, and follow the instructions. For information regarding edition and pricing, read here

When you create a SQL azure database, it comes with a firewall that blocks all traffic. To get access to it, you need to open for the IP addresses that need to access it. In the new portal that is hard to find. Click “SQL databases”->”Servers”->Click on the server name-> Clik configure and add the IP addresses. While you’re developing, you can start by adding your own IP.

When you have done that, you can start designing your database. There is a management tool in Azure you can use. Just click the manage database link in the portal.

From the management tool you can design tables(See below), views and SP’s.

You can also create new databases and deploy databases from your database projects in Visual studio, which is the correct way to develop SQL databases. (I’ll cover that in a later blog post)

You can off course also logon to the database from management studio. Get the connection string from the portal, and type it in. See example below.

As before it is very limited what you can do from management studio. You can’t design anything with the designer. You have to do everything in SQL, and there is also something you can’t do with SQL either. (Again the correct way to develop database projects is to use the database project in visual studio.)

But to conclude on this first look. We have created a SQL database using the new portal. From what we have seen up until not, not so much have changed since the last version. How we can do SQL development have however changed, and I’ll cover that in the next blog post in the series.