-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzure SQL Databases
More file actions
67 lines (57 loc) · 2.71 KB
/
Azure SQL Databases
File metadata and controls
67 lines (57 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Exercise: Azure SQL Databases
In this exercise, you will create an Azure SQL Database and add data to it. In a later exercise, you will connect an app to the database, so that you can both get and post data from the app into the database.
Deploy a SQL Database in Azure called “database-west” to the “resource-group-west” resource group (or whichever resource group you have been using in earlier exercises).
Within the Azure portal, add the data from the script in the sql_scripts directory here to the database. You should be able to run a SELECT query afterward on the animals table to see the example animals populated in your database.
Note: Azure free accounts only allow 250GB of free storage using SQL Databases. Once you get to the end of this lesson, you will want to delete the SQL Database and SQL Server to avoid incurring any charges, as you'll create a different SQL Database in the final course project.
Create SQL Server
az sql server create \
--admin-user udacityadmin \
--admin-password p@ssword1234 \
--name hello-world-server \
--resource-group resource-group-west \
--location westus2 \
--enable-public-network true \
--verbose
Create Firewall rule
Next, we have to create two firewall rules. These are the same two rules we checked as yes when we used the portal.
The first one is to allow Allow Azure services and resources to access the server we just created.
az sql server firewall-rule create \
-g resource-group-west \
-s hello-world-server \
-n azureaccess \
--start-ip-address 0.0.0.0 \
--end-ip-address 0.0.0.0 \
--verbose
This second rule is to set your computer's public Ip address to the server's firewall. You'll need to find your computer's public ip address for this part.
I'm using macOS, so I used the command curl ifconfig.me; you can use ipconfig in the command prompt if you are on Windows.
Create clientIp firewall rule
az sql server firewall-rule create \
-g resource-group-west \
-s hello-world-server \
-n clientip \
--start-ip-address <PUBLIC-IP-ADDRESS> \
--end-ip-address <PUBLIC_IP_ADDRESS> \
--verbose
Create SQL Database
Finally, to create the database itself, I used the below command.
az sql db create \
--name hello-world-db \
--resource-group resource-group-west \
--server hello-world-server \
--tier Basic \
--verbose
Adding Data
We'll again add data to the database through the portal, as that's the most straightforward method for now (until we connect to an app).
Cleanup
You can find the CLI commands for cleaning up the SQL resources below.
Delete DB
az sql db delete \
--name hello-world-db \
--resource-group resource-group-west \
--server hello-world-server \
--verbose
Delete SQL Server
az sql server delete \
--name hello-world-server \
--resource-group resource-group-west \
--verbose