-
Book Overview & Buying
-
Table Of Contents
Professional Azure SQL Database Administration [Instructor Edition]
By :
Provisioning an Azure SQL database refers to creating a new and blank Azure SQL database.
In this section, we'll create a new SQL database in Azure using the Azure portal:


A resource group is a logical container that is used to group Azure resources required to run an application.
For example, the toystore retail web application uses different Azure resources such as Azure SQL Database, Azure VMs, and Azure Storage. All of these resources can be grouped in a single resource group, say, toystore.
The SQL database name should be unique across Microsoft Azure and should follow the following naming rules and conventions: https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions.

On the New server page, provide the following details and click Select at the bottom of the page: Server name, Server admin login, Password, Confirm password, and Location.
The server name should be unique across Microsoft Azure and should follow the following naming rules and conventions: https://docs.microsoft.com/en-us/azure/architecture/best-practices/naming-conventions.


Note that you will have to click the Looking for basic, standard, premium? link for the standard option to be available:



Provisioning may take 2-5 minutes. Once the resources are provisioned, you'll get a notification, as shown in the following screenshot:

In this section, we'll learn how to connect and query the SQL database from the Azure portal:


Select OK to authenticate and return to the Query editor (preview) pane:
The query creates a new table (orders), populates it with sample data, and returns the top 10 rows from the orders table:
-- create a new orders table
CREATE TABLE orders
(
orderid INT IDENTITY(1, 1) PRIMARY KEY,
quantity INT, sales MONEY
);
--populate Orders table with sample data
;
WITH t1
AS (SELECT 1 AS a
UNION ALL
SELECT 1),
t2
AS (SELECT 1 AS a
FROM t1
CROSS JOIN t1 AS b),
t3
AS (SELECT 1 AS a
FROM t2
CROSS JOIN t2 AS b),
t4
AS (SELECT 1 AS a
FROM t3
CROSS JOIN t3 AS b),
t5
AS (SELECT 1 AS a
FROM t4
CROSS JOIN t4 AS b),
nums
AS (SELECT Row_number()
OVER (
ORDER BY (SELECT NULL)) AS n
FROM t5)
INSERT INTO orders SELECT n,
n * 10
FROM nums;
GO
SELECT TOP 10 * from orders;
In this section, we'll connect to and query an Azure SQL database from SQL Server Management Studio (SSMS):


You'll get an error saying Your client IP address does not have access to the server. To connect to Azure SQL Server, you must add the IP of the system you want to connect from under the firewall rule of Azure SQL Server. You can also provide a range of IP addresses to connect from:

To add your machine's IP to the Azure SQL Server firewall rule, switch to the Azure portal.
Open the toystore SQL database Overview pane, if it's not already open.
From the Overview pane, select Set server firewall:


If you wish to rename the rule, you can do so by providing a meaningful name in the RULE NAME column.
All machines with IPs between START IP and END IP are allowed to access all of the databases on the toyfactory server.
The virtual network can be used to add a SQL database in Azure to a given network. A detailed explanation of virtual networks is out of the scope of this book.

Click Save to save the firewall rule.

To open a new query window in the master database context, in Object Explorer, expand Databases, then expand System Databases. Right-click the master database and select New Query.
SELECT * FROM sys.firewall_rules
You should get the following output:

The AzureAllWindowsAzureIps firewall is the default firewall, which allows resources within Microsoft to access Azure SQL Server.
The rest are user-defined firewall rules. The firewall rules for you will be different from what is shown here.
You can use sp_set_firewall_rule to add a new firewall rule and sp_delete_firewall_rule to delete an existing firewall rule.

SELECT COUNT(*) AS OrderCount FROM orders;
The query will return the total number of orders from the orders table. You should get the following output:
To delete an Azure SQL database, an Azure SQL server, and Azure resource groups, perform the following steps:
All resources must be deleted to successfully complete the activity at the end of this lesson.


To only delete an Azure SQL database, check the Azure SQL database checkbox.


Change the font size
Change margin width
Change background colour