Skip to content

Commit 6f0b797

Browse files
committed
Updates for Azure SQL Database
1 parent ca2befa commit 6f0b797

17 files changed

Lines changed: 1482 additions & 1537 deletions

Instructions/Labs/00-setup.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
lab:
3-
title: 'Lab Environment Setup'
3+
title: 'Lab Environment Setup - Local SQL Server'
44
module: 'Setup'
55
---
66

@@ -47,3 +47,18 @@ The labs use a lightweight version of the AdventureWorks sample database. Note t
4747
- **Server group**: <Default>
4848
- **Name**: AdventureWorks
4949

50+
## Explore the *AdventureWorks* database
51+
52+
We'll use the **AdventureWorks** database in this lab, so let's start by exploring it in Azure Data Studio.
53+
54+
1. Start Azure Data Studio if it's not already started, and in the **Connections** tab, select the **AdventureWorks** connection by clicking on the arrow just to the left of the name. This will connect to the SQL Server instance and show the objects in the **AdventureWorks** database.
55+
2. Expand the **Tables** folder to see the tables that are defined in the database. Note that there are a few tables in the **dbo** schema, but most of the tables are defined in a schema named **SalesLT**.
56+
3. Expand the **SalesLT.Product** table and then expand its **Columns** folder to see the columns in this table. Each column has a name, a data type, an indication of whether it can contain *null* values, and in some cases an indication that the columns is used as a primary key (PK) or foreign key (FK).
57+
4. Right-click the **SalesLT.Product** table and use the **SELECT TOP (1000)** option to create and run a new query script that retrieves the first 1000 rows from the table.
58+
5. Review the query results, which consist of 1000 rows - each row representing a product that is sold by the fictitious *Adventure Works Cycles* company.
59+
6. Close the **SQLQuery_1** pane that contains the query and its results.
60+
7. Explore the other tables in the database, which contain information about product details, customers, and sales orders. The tables are related through primary and foreign keys, as shown here (you may need to resize the pane to see them clearly):
61+
62+
![An entity relationship diagram of the AdventureWorks database](./images/adventureworks-erd.png)
63+
64+
> **Note**: If you're familiar with the standard **AdventureWorks** sample database, you may notice that in this lab we are using a simplified version that makes it easier to focus on learning Transact-SQL syntax.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
lab:
3+
title: 'Lab Environment Setup - Azure SQL Database'
4+
module: 'Setup'
5+
---
6+
7+
# Lab Environment Setup
8+
9+
You can complete the Transact-SQL exercises in a sample database in Microsoft Azure SQL Database. Use the instructions in this page to prepare a suitable Azure SQL Database environment.
10+
11+
> **Note**: You will need a [Microsoft Azure subscription](https://azure.microsoft.com/free) in which you have sufficient permissions to create and configure the required resources.
12+
13+
## Provision Azure SQL Database
14+
15+
First, you need to provision an instance of Azure SQL Database with a sample database that you can query.
16+
17+
1. In a web browser, navigate to the [Azure portal](https://portal.azure.com) at `https://portal.azure.com` and sign in using the credentials associated with your Azure subscription.
18+
1. On the **Home** page, create a **SQL Database** resource with the following settings (be sure to select the **sample** database option on the **Additional settings** tab!):
19+
- **Basics**:
20+
- **Subscription**: *Select your Azure subscription*
21+
- **Resource group**: *Create or select a resource group where you want to create the SQL Database resource*
22+
- **Database name**: `Adventureworks`
23+
- **Server**: Create a new server with the following settings:
24+
- **Server name**: *A unique name*
25+
- **Location**: *Select any available region*
26+
- **Authentication method**: Use Microsoft Entra-only authentication
27+
- **Select Microsoft Entra admin**: *Select your own user account*
28+
- **Want to use SQL elastic pool?**: No
29+
- **Workload environment**: Development
30+
- **Compute + storage**: General purpose - serverless *(with the default configuration)*
31+
- **Backup storage redundancy**: Locally-redundant backup storage
32+
- **Networking**:
33+
- **Connectivity method**: Public endpoint
34+
- **Firewall rules**:
35+
- **Allow Azure services and resources to access this server**: Yes
36+
- **Add current client IP address**: Yes
37+
- **Connection policy**: Default
38+
- **Minimum TLS version**: TLS 1.2
39+
- **Security**:
40+
- **Enable Microsoft Defender for SQL**: Not now
41+
- **Ledger**: Not configured
42+
- **Server identity**: Not configured
43+
- **Transparent data encryption key management**:
44+
- **Server level key**: Service-managed key selected
45+
- **Database level key**: Not configured
46+
- **Enable secure enclaves**: Off
47+
- **Additional settings**:
48+
- **Use existing data**: Sample *(Confirm that **AdventureWorksLT** database will be created)*
49+
- **Tags**:
50+
- None
51+
1. Wait for deployment to complete. Then go to the **Adventureworks** SQL Database resource you deployed.
52+
53+
## Open the query editor
54+
55+
The query editor is a browser-based interface that you can use to run Transact-SQL statements in your database.
56+
57+
1. In the Azure portal, on the page for your **Adventureworks** SQL Database, in the pane on the left, select **Query editor**.
58+
1. On the welcome page, sign into your database using Entra authentication (if necessary, allow access from your client IP address first).
59+
1. In the query editor, expand the **Tables** folder to view the tables in the database.
60+
61+
> **Note**: If you're familiar with the standard **AdventureWorks** sample database for Microsoft SQL Server, you may notice that we are using a simplified, lightweight (*LT*) version with fewer tables.
62+
63+
1. In the **Query 1** pane, enter the following Transact-SQL code:
64+
65+
```sql
66+
SELECT * FROM SalesLT.Product;
67+
```
68+
69+
1. Use the **▷ Run** button to run the query, and and after a few seconds, review the results, which includes all columns for all products.
70+
1. Close the Query editor page, discarding your changes if prompted.
71+
72+
Now that you've created the database and learned how to use the query editor to run Transact-SQL code, you can return to the query editor in the Azure Portal at any time to complete the lab exercises.
73+
74+
> **Tip**: When you've finished with the database, delete the resources you created in your Azure subscription to avoid unnecessary charges.

Instructions/Labs/01-get-started-with-tsql.md

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,54 @@ lab:
66

77
# Get Started with Transact-SQL
88

9-
In this lab, you will use some basic SELECT queries to retrieve data from the **AdventureWorks** database.
9+
In this exercise, you will use some basic SELECT queries to retrieve data from the **AdventureWorks** database.
1010

11-
## Explore the *AdventureWorks* database
12-
13-
We'll use the **AdventureWorks** database in this lab, so let's start by exploring it in Azure Data Studio.
14-
15-
1. Start Azure Data Studio, and in the **Connections** tab, select the **AdventureWorks** connection by clicking on the arrow just to the left of the name. This will connect to the SQL Server instance and show the objects in the **AdventureWorks** database.
16-
2. Expand the **Tables** folder to see the tables that are defined in the database. Note that there are a few tables in the **dbo** schema, but most of the tables are defined in a schema named **SalesLT**.
17-
3. Expand the **SalesLT.Product** table and then expand its **Columns** folder to see the columns in this table. Each column has a name, a data type, an indication of whether it can contain *null* values, and in some cases an indication that the columns is used as a primary key (PK) or foreign key (FK).
18-
4. Right-click the **SalesLT.Product** table and use the **SELECT TOP (1000)** option to create and run a new query script that retrieves the first 1000 rows from the table.
19-
5. Review the query results, which consist of 1000 rows - each row representing a product that is sold by the fictitious *Adventure Works Cycles* company.
20-
6. Close the **SQLQuery_1** pane that contains the query and its results.
21-
7. Explore the other tables in the database, which contain information about product details, customers, and sales orders. The tables are related through primary and foreign keys, as shown here (you may need to resize the pane to see them clearly):
22-
23-
![An entity relationship diagram of the AdventureWorks database](./images/adventureworks-erd.png)
24-
25-
> **Note**: If you're familiar with the standard **AdventureWorks** sample database, you may notice that in this lab we are using a simplified version that makes it easier to focus on learning Transact-SQL syntax.
11+
> **Note**: This exercise assumes you have created the sample **AdventureWorks** database.
2612
2713
## Use SELECT queries to retrieve data
2814

29-
Now that you've had a chance to explore the **AdventureWorks** database, it's time to dig a little deeper into the product data it contains by querying the **Product** table.
15+
The SELECT statement is the primary Transact-SQL statement used to query tables in a database.
3016

31-
1. In Azure Data Studio, create a new query (you can do this from the **File** menu or on the *welcome* page).
32-
2. In the new **SQLQuery_...** pane, ensure that the **AdventureWorks** database is selected at the top of the query pane. If not, use the **Connect** button to connect the query to the **AdventureWorks** saved connection.
33-
3. In the query editor, enter the following code:
17+
1. Open a query editor for your **AdventureWorks** database, and create a new query.
18+
1. In the query editor, enter the following code:
3419

3520
```sql
3621
SELECT * FROM SalesLT.Product;
3722
```
3823

39-
4. Use the **⏵Run** button to run the query, and and after a few seconds, review the results, which includes all columns for all products.
40-
5. In the query editor, modify the query as follows:
24+
1. Run the query, and and after a few seconds, review the results, which includes all columns for all products.
25+
1. In the query editor, modify the query as follows:
4126

4227
```sql
4328
SELECT Name, StandardCost, ListPrice
4429
FROM SalesLT.Product;
4530
```
4631

47-
6. Use the **⏵Run** button to re-run the query, and and after a few seconds, review the results, which this time include only the **Name**, **StandardCost**, and **ListPrice** columns for all products.
48-
7. Modify the query as shown below to include an expression that results in a calculated column, and then re-run the query:
32+
1. Re-run the query, and and after a few seconds, review the results, which this time include only the **Name**, **StandardCost**, and **ListPrice** columns for all products.
33+
1. Modify the query as shown below to include an expression that results in a calculated column, and then re-run the query:
4934

5035
```sql
5136
SELECT Name, ListPrice - StandardCost
5237
FROM SalesLT.Product;
5338
```
5439

55-
8. Note that the results this time include the **Name** column and an unnamed column containing the result of subtracting the **StandardCost** from the **ListPrice**.
56-
9. Modify the query as shown below to assign names to the columns in the results, and then re-run the query.
40+
1. Note that the results this time include the **Name** column and an unnamed numeric column containing the result of subtracting the **StandardCost** from the **ListPrice**.
41+
1. Modify the query as shown below to assign names to the columns in the results, and then re-run the query.
5742

5843
```sql
5944
SELECT Name AS ProductName, ListPrice - StandardCost AS Markup
6045
FROM SalesLT.Product;
6146
```
6247

63-
10. Note that the results now include columns named **ProductName** and **Markup**. The **AS** keyword has been used to assign an *alias* for each column in the results.
64-
11. Replace the existing query with the following code, which also includes an expression that produces a calculated column in the results:
48+
1. Note that the results now include columns named **ProductName** and **Markup**. The **AS** keyword has been used to assign an *alias* for each column in the results.
49+
1. Replace the existing query with the following code, which also includes an expression that produces a calculated column in the results:
6550

6651
```sql
6752
SELECT ProductNumber, Color, Size, Color + ', ' + Size AS ProductDetails
6853
FROM SalesLT.Product;
6954
```
7055

71-
12. Run the query, and note that the **+** operator in the calculated **ProductDetails** column is used to *concatenate* the **Color** and **Size** column values (with a literal comma between them). The behavior of this operator is determined by the data types of the columns - had they been numeric values, the **+** operator would have *added* them. Note also that some results are *NULL* - we'll explore NULL values later in this lab.
56+
1. Run the query, and note that the **+** operator in the calculated **ProductDetails** column is used to *concatenate* the **Color** and **Size** column values (with a literal comma between them). The behavior of this operator is determined by the data types of the columns - had they been numeric values, the **+** operator would have *added* them. Note also that some results are *NULL* - we'll explore NULL values later in this lab.
7257
7358
## Work with data types
7459
@@ -230,7 +215,7 @@ As you continue to work with the Adventure Works customer data, you must create
230215
- You have been asked to provide a list of all customer companies in the format *Customer ID* : *Company Name* - for example, *78: Preferred Bikes*.
231216
2. Retrieve a list of sales order revisions
232217
- The **SalesLT.SalesOrderHeader** table contains records of sales orders. You have been asked to retrieve data for a report that shows:
233-
- The sales order number and revision number in the format <Order Number> (<Revision>) – for example SO71774 (2).
218+
- The purchase order number and revision number in the format *<Order Number> (<Revision>)* – for example *PO348186287 (2)*.
234219
- The order date converted to ANSI standard *102* format (*yyyy.mm.dd* – for example *2015.01.31*).
235220
236221
### Challenge 3: Retrieve customer contact details
@@ -299,7 +284,7 @@ This section contains suggested solutions for the challenge queries.
299284
2. Retrieve a list of sales order revisions:
300285
301286
```sql
302-
SELECT SalesOrderNumber + ' (' + STR(RevisionNumber, 1) + ')' AS OrderRevision,
287+
SELECT PurchaseOrderNumber + ' (' + STR(RevisionNumber, 1) + ')' AS OrderRevision,
303288
CONVERT(nvarchar(30), OrderDate, 102) AS OrderDate
304289
FROM SalesLT.SalesOrderHeader;
305290
```

0 commit comments

Comments
 (0)