Skip to content

Commit 89b6f65

Browse files
Merge pull request #35778 from rwestMSFT/rw-1106-fix-10214
Fix T-SQL credential creation and clipboard command (PR 10214)
2 parents 70d47ce + c061276 commit 89b6f65

1 file changed

Lines changed: 43 additions & 32 deletions

File tree

docs/relational-databases/tutorial-use-azure-blob-storage-service-with-sql-server.md

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Tutorial: Use Azure Blob Storage with SQL Server"
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
66
ms.reviewer: randolphwest
7-
ms.date: 08/11/2025
7+
ms.date: 11/06/2025
88
ms.service: sql
99
ms.topic: tutorial
1010
ms.custom:
@@ -15,7 +15,7 @@ ms.custom:
1515

1616
[!INCLUDE [sqlserver 2016 and later versions](../includes/applies-to-version/sqlserver2016.md)]
1717

18-
This tutorial helps you understand how to use the Azure Blob Storage for data files and backups in SQL Server 2016 and later versions.
18+
This tutorial helps you understand how to use the Azure Blob Storage for data files and backups in [!INCLUDE [sssql16-md](../includes/sssql16-md.md)] and later versions.
1919

2020
Support for Azure Blob Storage in SQL Server was introduced in [!INCLUDE [sssql11-md](../includes/sssql11-md.md)] Service Pack 1 CU2, and enhanced in later versions. For an overview of the functionality and benefits of using this feature, see [SQL Server data files in Microsoft Azure](databases/sql-server-data-files-in-microsoft-azure.md).
2121

@@ -25,7 +25,7 @@ This tutorial shows you how to work with SQL Server data files in Azure Blob Sto
2525

2626
To complete this tutorial, you must be familiar with [!INCLUDE [ssNoVersion](../includes/ssnoversion-md.md)] backup and restore concepts and T-SQL syntax.
2727

28-
To use this tutorial, you need an Azure storage account, SQL Server Management Studio (SSMS), access to an instance of SQL Server on-premises, access to an Azure virtual machine (VM) running an instance of SQL Server 2016 or later version, and an [!INCLUDE [sssampledbobject-md](../includes/sssampledbobject-md.md)] database. Additionally, the account used to issue the `BACKUP` and `RESTORE` commands should be in the **db_backupoperator** database role with **alter any credential** permissions.
28+
To use this tutorial, you need an Azure storage account, SQL Server Management Studio (SSMS), access to an instance of SQL Server on-premises, access to an Azure virtual machine (VM) running an instance of [!INCLUDE [sssql16-md](../includes/sssql16-md.md)] or later version, and an [!INCLUDE [sssampledbobject-md](../includes/sssampledbobject-md.md)] database. Additionally, the account used to issue the `BACKUP` and `RESTORE` commands should be in the **db_backupoperator** database role with **alter any credential** permissions.
2929

3030
- Get a free [Azure Account](https://azure.microsoft.com/offers/ms-azr-0044p/).
3131
- Create an [Azure storage account](/azure/storage/common/storage-quickstart-create-account?tabs=portal).
@@ -70,12 +70,12 @@ To create a policy on the container and generate a Shared Access Signature (SAS)
7070

7171
```powershell
7272
# Define global variables for the script
73-
$prefixName = '<a prefix name>' # used as the prefix for the name for various objects
74-
$subscriptionID = '<your subscription ID>' # the ID of subscription name you will use
75-
$locationName = '<a data center location>' # the data center region you will use
73+
$prefixName = '<a prefix name>' # used as the prefix for the name for various objects
74+
$subscriptionID = '<your subscription ID>' # the ID of subscription name you will use
75+
$locationName = '<a data center location>' # the data center region you will use
7676
$storageAccountName = $prefixName + 'storage' # the storage account name you will create or use
77-
$containerName = $prefixName + 'container' # the storage container name to which you will attach the SAS policy with its SAS token
78-
$policyName = $prefixName + 'policy' # the name of the SAS policy
77+
$containerName = $prefixName + 'container' # the storage container name to which you will attach the SAS policy with its SAS token
78+
$policyName = $prefixName + 'policy' # the name of the SAS policy
7979
8080
# Set a variable for the name of the resource group you will create or use
8181
$resourceGroupName = $prefixName + 'rg'
@@ -102,7 +102,7 @@ To create a policy on the container and generate a Shared Access Signature (SAS)
102102
$container = New-AzStorageContainer -Context $storageContext -Name $containerName
103103
104104
# Sets up a Stored Access Policy and a Shared Access Signature for the new container
105-
$policy = New-AzStorageContainerStoredAccessPolicy -Container $containerName -Policy $policyName -Context $storageContext -StartTime $(Get-Date). ToUniversalTime().AddMinutes(-5) -ExpiryTime $(Get-Date).ToUniversalTime().AddYears(10) -Permission rwld
105+
$policy = New-AzStorageContainerStoredAccessPolicy -Container $containerName -Policy $policyName -Context $storageContext -StartTime $(Get-Date).ToUniversalTime().AddMinutes(-5) -ExpiryTime $(Get-Date).ToUniversalTime().AddYears(10) -Permission rwld
106106
107107
# Gets the Shared Access Signature for the policy
108108
$sas = New-AzStorageContainerSASToken -name $containerName -Policy $policyName -Context $storageContext
@@ -114,8 +114,8 @@ To create a policy on the container and generate a Shared Access Signature (SAS)
114114
115115
# Outputs the Transact SQL to the clipboard and to the screen to create the credential using the Shared Access Signature
116116
Write-Host 'Credential T-SQL'
117-
$tSql = "CREATE CREDENTIAL [{0}] WITH IDENTITY='Shared Access Signature', SECRET='{1}'" -f $cbc.Uri, $sas.Substring(1)
118-
$tSql | clip
117+
$tSql = "CREATE CREDENTIAL [{0}] WITH IDENTITY='SHARED ACCESS SIGNATURE', SECRET='{1}'" -f $cbc.Uri, $sas
118+
Set-Clipboard -Value $tSql
119119
Write-Host $tSql
120120
121121
# Once you're done with the tutorial, remove the resource group to clean up the resources.
@@ -186,8 +186,8 @@ To back up a database to blob storage, follow these steps:
186186
```sql
187187
-- To permit log backups, before the full database backup, modify the database to use the full recovery model.
188188
USE master;
189-
190-
ALTER DATABASE AdventureWorks2022 SET RECOVERY FULL;
189+
ALTER DATABASE AdventureWorks2022
190+
SET RECOVERY FULL;
191191

192192
-- Back up the full AdventureWorks2022 database to the container that you created in section 1
193193
BACKUP DATABASE AdventureWorks2022
@@ -218,9 +218,9 @@ To restore the [!INCLUDE [sssampledbobject-md](../includes/sssampledbobject-md.m
218218
-- Restore AdventureWorks2022 from URL to SQL Server instance using Azure Blob Storage for database files
219219
RESTORE DATABASE AdventureWorks2022
220220
FROM URL = 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_onprem.bak'
221-
WITH MOVE 'AdventureWorks2022_data' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_Data.mdf',
222-
MOVE 'AdventureWorks2022_log' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_Log.ldf'
223-
--, REPLACE;
221+
WITH MOVE 'AdventureWorks2022_data' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_Data.mdf',
222+
MOVE 'AdventureWorks2022_log' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_Log.ldf';
223+
--, REPLACE
224224
```
225225

226226
1. Open Object Explorer and connect to your Azure SQL Server instance.
@@ -314,8 +314,12 @@ To generate activity in the [!INCLUDE [sssampledbobject-md](../includes/sssample
314314
SET @inner = 1;
315315
WHILE @inner <= 75
316316
BEGIN
317-
INSERT INTO AdventureWorks2022.Production.Location
318-
(Name, CostRate, Availability, ModifiedDate)
317+
INSERT INTO AdventureWorks2022.Production.Location (
318+
Name,
319+
CostRate,
320+
Availability,
321+
ModifiedDate
322+
)
319323
VALUES (NEWID(), .5, 5.2, GETDATE());
320324
SET @inner = @inner + 1;
321325
END
@@ -324,7 +328,8 @@ To generate activity in the [!INCLUDE [sssampledbobject-md](../includes/sssample
324328
SET @count = @count + 1;
325329
END
326330

327-
SELECT COUNT(*) FROM AdventureWorks2022.Production.Location;
331+
SELECT COUNT(*)
332+
FROM AdventureWorks2022.Production.Location;
328333
```
329334

330335
```sql
@@ -371,7 +376,8 @@ To restore a database to a specified point in time from file snapshot backup set
371376

372377
```sql
373378
-- Verify row count at start
374-
SELECT COUNT(*) FROM AdventureWorks2022.Production.Location;
379+
SELECT COUNT(*)
380+
FROM AdventureWorks2022.Production.Location;
375381
```
376382

377383
:::image type="content" source="media/tutorial-use-azure-blob-storage-service-with-sql-server/29-thousand-rows.png" alt-text="Screenshot of the SSMS results showing a row count of 29,939.":::
@@ -380,18 +386,22 @@ To restore a database to a specified point in time from file snapshot backup set
380386

381387
```sql
382388
-- restore and recover to a point in time between the times of two transaction log backups, and then verify the row count
383-
ALTER DATABASE AdventureWorks2022 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
389+
ALTER DATABASE AdventureWorks2022
390+
SET SINGLE_USER
391+
WITH ROLLBACK IMMEDIATE;
384392

385393
RESTORE DATABASE AdventureWorks2022 FROM URL = 'https://<storage-account>.blob.core.windows.net/<container-name>/<firstbackupfile>.bak'
386394
WITH NORECOVERY, REPLACE;
387395

388396
RESTORE LOG AdventureWorks2022 FROM URL = 'https://<storage-account>.blob.core.windows.net/<container-name>/<secondbackupfile>.bak'
389397
WITH RECOVERY, STOPAT = 'June 26, 2018 01:48 PM';
390398

391-
ALTER DATABASE AdventureWorks2022 SET MULTI_USER;
399+
ALTER DATABASE AdventureWorks2022
400+
SET MULTI_USER;
392401

393402
-- get new count
394-
SELECT COUNT(*) FROM AdventureWorks2022.Production.Location;
403+
SELECT COUNT(*)
404+
FROM AdventureWorks2022.Production.Location;
395405
```
396406

397407
1. Review the output. After the restore the row count is 18,389, which is a row count number between log backup 5 and 6 (your row count can vary).
@@ -419,11 +429,11 @@ To restore a database to a new database from a transaction log backup using file
419429
```sql
420430
-- restore as a new database from a transaction log backup file
421431
RESTORE DATABASE AdventureWorks2022_EOM
422-
FROM URL = 'https://<storage-account>.blob.core.windows.net/<container-name>/<logbackupfile.bak>'
423-
WITH MOVE 'AdventureWorks2022_data' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_EOM_Data.mdf',
424-
MOVE 'AdventureWorks2022_log' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_EOM_Log.ldf',
425-
RECOVERY
426-
--, REPLACE;
432+
FROM URL = 'https://<storage-account>.blob.core.windows.net/<container-name>/<logbackupfile.bak>'
433+
WITH MOVE 'AdventureWorks2022_data' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_EOM_Data.mdf',
434+
MOVE 'AdventureWorks2022_log' TO 'https://<storage-account>.blob.core.windows.net/<container-name>/AdventureWorks2022_EOM_Log.ldf',
435+
RECOVERY;
436+
--, REPLACE
427437
```
428438

429439
1. Review the output to verify the restore was successful.
@@ -463,7 +473,8 @@ To delete a file-snapshot backup set, follow these steps:
463473

464474
```sql
465475
-- verify that two file snapshots have been removed
466-
SELECT * FROM sys.fn_db_backup_file_snapshots('AdventureWorks2022');
476+
SELECT *
477+
FROM sys.fn_db_backup_file_snapshots('AdventureWorks2022');
467478
```
468479

469480
:::image type="content" source="media/tutorial-use-azure-blob-storage-service-with-sql-server/results-of-two-deleted-snapshot-files.png" alt-text="Screenshot of the SSMS results pane showing two file snapshots deleted." lightbox="media/tutorial-use-azure-blob-storage-service-with-sql-server/results-of-two-deleted-snapshot-files.png":::
@@ -476,10 +487,10 @@ To delete the resource group, run the following PowerShell code:
476487

477488
```powershell
478489
# Define global variables for the script
479-
$prefixName = '<prefix name>' # should be the same as the beginning of the tutorial
490+
$prefixName = '<prefix name>' # should be the same as the beginning of the tutorial
480491
481492
# Set a variable for the name of the resource group you will create or use
482-
$resourceGroupName=$prefixName + 'rg'
493+
$resourceGroupName = $prefixName + 'rg'
483494
484495
# Adds an authenticated Azure account for use in the session
485496
Connect-AzAccount
@@ -495,7 +506,7 @@ To delete the resource group, run the following PowerShell code:
495506

496507
- [SQL Server data files in Microsoft Azure](databases/sql-server-data-files-in-microsoft-azure.md)
497508
- [File-Snapshot Backups for Database Files in Azure](backup-restore/file-snapshot-backups-for-database-files-in-azure.md)
498-
- [SQL Server backup to URL for Microsoft Azure Blob Storage](backup-restore/sql-server-backup-to-url.md)
509+
- [SQL Server backup to URL for Azure Blob Storage](backup-restore/sql-server-backup-to-url.md)
499510
- [Shared Access Signatures, Part 1: Understanding the SAS Model](/azure/storage/common/storage-sas-overview)
500511
- [Create Container](/rest/api/storageservices/Create-Container)
501512
- [Set Container ACL](/rest/api/storageservices/Set-Container-ACL)

0 commit comments

Comments
 (0)