Windows Azure Platform体验(2):SQL Azure

Windows Azure Platform have Windows Azure, SQL Azure, Azure AppFabric three parts.

SQL Azure is a cloud relational database. Your data: management anytime, anywhere. SQL Azure is a fully relational database in the cloud.

This section of our experience SQL Azure, the necessary software:

  • Microsoft SQL Server 2008 R2
  • Windows Azure Platform account

This experience are the following steps, namely:

Initialization SQL Azure

First, we use the account to log SQL Azure portal site at http://sql.azure.com , you can see the following page. We click on the project name.

SQL Azure

Terms page appears. After reading, if you agree to accept these terms, click "I accept" (I accept), start using the actual SQL Azure database.

SQL Azure

The Create Server Pages. We begin by creating an actual server. On the type of server, the server usually familiar to us may be physical or virtual server, here we create a virtual server that SQL Azure server. That is to say it is a combination of the database by logically grouped together, rather than by physically combined. Specifies the administrator user name and password to create this actual servers on which SQL Azure data center database group. If in mainland China, you can select East Asia. I chose the "East Asian" data center, click Create server.

SQL Azure

当我完成后,出现服务器详细信息页面,这个页面显示了登录到这台服务器的详细信息和已有的数据库以及防火墙配置。页面的顶部提供了唯一的ID和 “.database.windows.net”的组合是服务器地址。页面的底部,我们可以看到所有已经创建的数据库。现在只有用来存储其他数据库记录的 默认SQL主数据库,我们还没有创建任何数据库。接下来我创建的所有数据库都在这个服务器账户中。

SQL Azure

点击“Create Database”创建一个数据库,出现下面页面,这里我将其命名为“lyjDB”,选择版本类型和数据库大小。这些是由你购买的的选择决定,Web版本 有1G和5G两个容量,Business版本有10G、20G、30G、40G、50G的大容量。由于这个账户没有限制,我选择最小的配置体验下。

SQL Azure

创建完之后,我们可以点击“Connection Strings”连接字符串。SQL Azure为我们提供了两种数据库连接:

SQL Azure

我们单击底部的“Test Connectivity”(测试连接)按钮,输入用户名和密码,点击连接,提示下面错误提示框。因为在默认情况下,SQL Azure安全设置不允许任何计算机、服务器或者客户端连接到SQL Azure。

SQL Azure

这时我们点击“Firewall Settings”(防火墙设置)选项卡。

你会发现SQL Azure安全设置默认不允许Microsoft服务都无法连接到这个服务器或者数据库,这时我选择“Allow Microsoft Services access to this service”(允许Microsoft服务访问这台服务器)复选框允许连接。这时网站会刷新,并且为我创建一条新的规则,出现一个特定 MicrosoftServices条目,允许Microsoft服务本身进行连接,这样我们就可以进行连接了。

SQL Azure

返回“Databases”(数据库)选项卡,单击底部的“Test Connectivity”(测试连接)按钮,输入用户名和密码,然后就可以启动测试连接,并看到连接成功。

SQL Azure

连接到SQL Azure

1.防火墙设置

打开SQL Server Management Studio R2,用指定的用户名和密码进行登录,连接到这台服务器。注意必须使用R2版本才能连接到云中的SQL Azure数据库。不过登录到SQL Azure与登录内部部署SQL数据库方式的登录名的约定略有不同。除了需要指定用户名还需要加上“@”符号,然后是服务器名称的唯一的ID的部分。

SQL Azure

单击“连接”按钮,我们尝试进行连接。出现下面对话框提示连接失败,原因是因为在默认情况下,SQL Azure安全设置不允许任何计算机、服务器或者客户端连接到SQL Azure。

SQL Azure

我们需要配置防火墙,返回门户,并转到“Firewall Settings”(防火墙设置)选项卡,配置防火墙规则设置为允许特定连接通过,为我的本地创建一条规则。这样,我们就可以在本地通过SQL Server Management Studio R2进行实际连接了。输入规则名称和IP地址或者IP范围。系统已经识别了我正在连接的IP地址。

SQL Azure

创建完成之后,在防火墙规则中出现新增了一条规则。

SQL Azure

2.与SQL Azure交互

切换到SQL Server Management Studio R2尝试再次连接,这一次一切都设置好了,现在成功实现连接,它连接了实际的SQL Azure实例。请注意,这台服务器的图标略有不同。它显示的是一个小小的蓝色数据库符号,表示这是一个Azure连接,而不是一个标准的内部部署SQL 服务器连接。进入数据库组,你会看到我们刚刚创建的lyjDB数据库。

SQL Azure

我现在可以通过SQL Server Management Studio R2和SQL Azure数据库进行交互,方式与使用内部部署数据库方式非常像,也就是我在Management Studio R2中的惯用方式。但是,设计体验略微有些不同,这是因为我们使用的是基于云的数据库。因此,它只具备SQL Server 2008的部分功能,例如,我们无法获得拖放式设计图面。大多数是使用实际的SQL脚本语言来指定表的架构。

在数据库上右击并执行常规的脚本操作,比如Select命令。执行这个命令,并在底部查看显示的结果,与我们使用内部部署数据库非常类似。因此,对于那些标准操作,这与我所习惯的使用和执行方式非常类似。

3.连接到master数据库

我们执行“SELECT @@version”查询,查看SQL Azure的版本。可以看到它返回一个信息:SQL Azure由Microsoft SQL Server 2008派生的。

SQL Azure

我们使用master数据库查询sys.databases视图,我们能够看到我们的服务器上创建的所有数据库。

SQL Azure

4.创建一个新数据库

我们使用Management Studio R2在SQL Azure中创建一个新数据库。这一步非常简单。在SQL Azure中,我们使用简单的创建数据库执行语句,将立即创建一个新的数据库。

执行“CREATE DATABASE yjingleeDB”

SQL Azure

再次查询服务器上数据库,注意我们刚刚创建的yjingleeDB数据库在这个列表中了。

SQL Azure

5.连接到新数据库

为了连接到新的数据库,我们必须断开当前连接并重新打开新连接。因为在SQL Azure中,我们的数据库不一定储存在相同的物理服务器上面的。

这点与SQL Server有点不同,SQL Server中,我们可以使用USE语句来更改数据库,在SQL Azure中,我们需要重新连接一次以确保重新连接到SQL Azure的物理服务器群集节点客户端是正确的。我们关闭查询标签,单击更改连接图标。

使用相同账户登录,由于我们想要连接到制定数据库,所以需要点击选项按钮,指定“yjingleeDB”数据库。

SQL Azure

连接成功了,我们调用DB_NAME()函数查看当前数据库名称。

SQL Azure

配置SQL Azure数据库安全

我们将配置yjingleeDB数据库的安全。学习一下如何为一个数据库创建和配置一个新的登录用户。

我们使用服务器用户名和密码登录默认SQL Azure数据库,创建一个登录用户。

SQL Azure

We then use the server user name and password to log back yjingleeDB database. We create a user login and user added to the db_owner role that has the operating authority for the database yjingleeDB database. Which in turn execute the following two lines of script.

SQL Azure

We have created, using this new database account login yjingleeDB it.

SQL Azure

Execute a query, verify the current user.

SQL Azure

Create database objects in SQL Azure

1. Create a simple table

We created a simple table, only a single column of type int. Here it must be noted, SQL Azure inside the table must have a clustered index. If not, you can not insert any data. Clustered index is not necessarily the primary key column. For performance reasons, the best in the other columns.

SQL Azure

Then insert three items of data, and then execute the query, retrieve the data.

SQL Azure

2. create complex tables and indexes

I have this in turn created a Customer table, and then add an index, and finally inserted into a packet of data and query it.

SQL Azure

3. Check the query plan

We look at the query data from the Customer table to experience SQL Azure query plan. We first perform a number of differences between T-SQL insert 10000 rows of data.

1 line data query plan:

SQL Azure

10,000 lines of data query plan

SQL Azure

Call the "Ctrl + L" Visualization:

SQL Azure

Reproduced in: https: //www.cnblogs.com/Tim_Liu/archive/2011/01/25/1944497.html

Guess you like

Origin blog.csdn.net/weixin_33692284/article/details/94724545