Skip to content

Commit a362e6c

Browse files
authored
Merge pull request #26961 from rwestMSFT/rw-0503-refresh-some-stored-procedures
Refresh some ledger stored procedure articles
2 parents a8897ef + 7ec4100 commit a362e6c

4 files changed

Lines changed: 82 additions & 71 deletions

docs/relational-databases/system-stored-procedures/sys-sp-copy-data-in-batches-transact-sql.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
---
22
title: "sys.sp_copy_data_in_batches (Transact-SQL)"
3-
description: "sys.sp_copy_data_in_batches (Transact-SQL)"
3+
description: "Copies data from the source table to the target table after verifying that their schema is identical in terms of number of columns, column names and their data types."
44
author: VanMSFT
55
ms.author: vanto
6-
ms.date: "05/24/2022"
6+
ms.reviewer: randolphwest
7+
ms.date: 05/03/2023
78
ms.service: sql
89
ms.subservice: system-objects
910
ms.topic: "reference"
1011
dev_langs:
1112
- "TSQL"
1213
monikerRange: "= azuresqldb-current||>= sql-server-ver16||>= sql-server-linux-ver16"
1314
---
14-
1515
# sys.sp_copy_data_in_batches (Transact-SQL)
1616

1717
[!INCLUDE [SQL Server 2022 Azure SQL Database](../../includes/applies-to-version/sqlserver2022-asdb.md)]
1818

19-
Copies data from the source table to the target table after verifying that their schema is identical in terms of number of columns, column names and their data types. `TRANSACTION ID`, `SEQUENCE NUMBER`, and `GENERATED ALWAYS` columns are ignored since they're system generated and this allows copying data from a regular table to a ledger table and vice versa. Indexes between the tables can be different but the target table can only be a Heap or have a clustered index. The data is copied in batches in individual transactions. If the operation fails, the target table will be partially populated.
19+
Copies data from the source table to the target table after verifying that their schema is identical in terms of number of columns, column names and their data types. `TRANSACTION ID`, `SEQUENCE NUMBER`, and `GENERATED ALWAYS` columns are ignored since they're system generated and this allows copying data from a regular table to a ledger table and vice versa. Indexes between the tables can be different but the target table can only be a heap or have a clustered index. The data is copied in batches in individual transactions. If the operation fails, the target table is partially populated.
20+
21+
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview).
2022

21-
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview)
23+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
2224

23-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
25+
## Syntax
2426

25-
## Syntax
26-
2727
```syntaxsql
28-
sp_copy_data_in_batches [@source_table_name = ] N'source_table_name' , [@target_table_name = ] N'target_table_name'
28+
sp_copy_data_in_batches [ @source_table_name = ] N'source_table_name' , [ @target_table_name = ] N'target_table_name'
2929
```
3030

3131
## Arguments
3232

33-
[ @source_table_name = ] N'source_table_name'
33+
#### [ @source_table_name = ] N'*source_table_name*'
34+
3435
The name of the table to be used as the source of the data copy.
3536

36-
[ @target_table_name = ] N'target_table_name'
37+
#### [ @target_table_name = ] N'*target_table_name*'
38+
3739
The name of the table to be used as the target of the data copy.
3840

3941
## Return code values
@@ -46,9 +48,9 @@ None.
4648

4749
## Permissions
4850

49-
This operation requires **SELECT** on the source table, **INSERT** in the target table, and **ALTER** on the target table if there are Foreign Key or Check constraints that will be disabled or an Identity column that will be adjusted.
51+
This operation requires **SELECT** on the source table, **INSERT** in the target table, and **ALTER** on the target table if there are foreign key or check constraints that will be disabled, or an identity column that will be adjusted.
5052

51-
## See also
53+
## Next steps
5254

5355
- [Ledger considerations and limitations](../security/ledger/ledger-limits.md)
5456
- [Ledger overview](../security/ledger/ledger-overview.md)
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
---
22
title: "sys.sp_generate_database_ledger_digest (Transact-SQL)"
3-
description: "sys.sp_generate_database_ledger_digest (Transact-SQL)"
3+
description: "Generates the ledger digest, which is the hash of the last block in sys.database_ledger_blocks."
44
author: VanMSFT
55
ms.author: vanto
6-
ms.date: "05/24/2022"
6+
ms.reviewer: randolphwest
7+
ms.date: 05/03/2023
78
ms.service: sql
89
ms.subservice: system-objects
910
ms.topic: "reference"
1011
dev_langs:
1112
- "TSQL"
1213
monikerRange: "= azuresqldb-current||>= sql-server-ver16||>= sql-server-linux-ver16"
1314
---
14-
1515
# sys.sp_generate_database_ledger_digest (Transact-SQL)
1616

1717
[!INCLUDE [SQL Server 2022 Azure SQL Database](../../includes/applies-to-version/sqlserver2022-asdb.md)]
1818

19-
Generates the ledger digest, which is the hash of the last block in sys.database_ledger_blocks. If the last block is open (transactions have been grouped to the block but no final block hash has been generated), this stored procedure will close the block and generate the hash. Future transactions will then be assigned to the next block.
19+
Generates the ledger digest, which is the hash of the last block in `sys.database_ledger_blocks`. If the last block is open (transactions have been grouped to the block but no final block hash has been generated), this stored procedure closes the block and generates the hash. Future transactions will then be assigned to the next block.
20+
21+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
2022

21-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
23+
## Syntax
2224

23-
## Syntax
24-
2525
```syntaxsql
26-
EXEC sys.sp_generate_database_ledger_digest
26+
sys.sp_generate_database_ledger_digest
2727
```
28+
2829
## Arguments
29-
None
30+
31+
None.
3032

3133
## Return code values
3234

3335
0 (success) or 1 (failure).
3436

3537
## Result sets
3638

37-
|Column name|Description|
38-
|-----------------|---------------|
39-
|**latest_digest**|A JSON document containing the following data:<br/><br/>`database_name` - the name of the database. <br/>`block_id` – same as block_id from the last row in sys.database_ledger_blocks.<br/>`hash` – a hexadecimal string representing a SHA-256 hash of the last row in sys.database_ledger_blocks.<br/>`last_transaction_commit_time` - same as commit_time from the last row in sys.database_ledger_blocks in the ISO 8601 format.<br/>`digest_time` – the time when the digest was generated in the ISO 8601 format.
39+
| Column name | Description |
40+
| --- | --- |
41+
|**latest_digest**|A JSON document containing the following data:<br/><br/>`database_name` - the name of the database. <br/>`block_id` – same as block_id from the last row in `sys.database_ledger_blocks`.<br/>`hash` – a hexadecimal string representing the SHA-256 hash of the last row in `sys.database_ledger_blocks`.<br/>`last_transaction_commit_time` - same as commit_time from the last row in `sys.database_ledger_blocks` in the ISO 8601 format.<br/>`digest_time` – the time when the digest was generated in the ISO 8601 format.
4042

41-
**Example JSON**
43+
**Example of the JSON**
4244

4345
```json
4446
{
45-
"database_name": "contoso",
46-
"block_id": 0,
47-
"hash": "0x6D7D609DE43DDBF84A0346463D6F93CA979846CD5609E02E4FFC96338FC64DD5",
48-
"last_transaction_commit_time": "2020-10-06T16:50:55.1066667",
49-
"digest_time": "2020-10-07T01:13:23.3601279"
47+
"database_name": "contoso",
48+
"block_id": 0,
49+
"hash": "0x6D7D609DE43DDBF84A0346463D6F93CA979846CD5609E02E4FFC96338FC64DD5",
50+
"last_transaction_commit_time": "2020-10-06T16:50:55.1066667",
51+
"digest_time": "2020-10-07T01:13:23.3601279"
5052
}
5153
```
5254

5355
## Permissions
5456

5557
Users with the **public** role are allowed to execute this stored procedure.
5658

57-
## See also
59+
## Next steps
5860

5961
- [Digest management](../security/ledger/ledger-digest-management.md)
6062
- [Ledger overview](../security/ledger/ledger-overview.md)

docs/relational-databases/system-stored-procedures/sys-sp-verify-database-ledger-from-digest-storage-transact-sql.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
---
22
title: "sys.sp_verify_database_ledger_from_digest_storage (Transact-SQL)"
3-
description: "sys.sp_verify_database_ledger_from_digest_storage (Transact-SQL)"
3+
description: "Verifies the database ledger and the table ledgers using digests at the specified external digest storage locations."
44
author: VanMSFT
55
ms.author: vanto
6-
ms.date: "05/24/2022"
6+
ms.reviewer: randolphwest
7+
ms.date: 05/03/2023
78
ms.service: sql
89
ms.subservice: system-objects
910
ms.topic: "reference"
1011
dev_langs:
1112
- "TSQL"
1213
monikerRange: "=azuresqldb-current"
1314
---
14-
1515
# sys.sp_verify_database_ledger_from_digest_storage (Transact-SQL)
1616

1717
[!INCLUDE [Azure SQL Database](../../includes/applies-to-version/asdb.md)]
1818

1919
Verifies the database ledger and the table ledgers using digests at the specified external digest storage locations.
2020

21-
This stored procedure implements the same ledger verification algorithm as [sp_verify_database_ledger](sys-sp-verify-database-ledger-transact-sql.md). A caller is expected to provider a JSON, which contains the paths pointing to digest storage locations, such as [Azure Blob storage](/azure/storage/blobs/storage-blobs-introduction) containers.
21+
This stored procedure implements the same ledger verification algorithm as [sp_verify_database_ledger](sys-sp-verify-database-ledger-transact-sql.md). A caller is expected to provide a JSON document that contains the paths pointing to digest storage locations, such as [Azure Blob storage](/azure/storage/blobs/storage-blobs-introduction) containers.
22+
23+
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview).
2224

23-
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview)
25+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
2426

25-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
27+
## Syntax
2628

27-
## Syntax
28-
2929
```syntaxsql
30-
sp_verify_database_ledger_from_digest_storage [@locations = ] 'JSON_document_with_digest_storage_locations' [ , [@table_name = ] 'table_name' ]
30+
sp_verify_database_ledger_from_digest_storage [ @locations = ] 'JSON_document_with_digest_storage_locations' [ , [ @table_name = ] 'table_name' ]
3131
```
3232

3333
## Arguments
3434

35-
[ @locations = ] '*JSON_document_with_digest_storage_locations*'
35+
#### [ @locations = ] '*JSON_document_with_digest_storage_locations*'
3636

3737
A JSON document containing a list of ledger digests locations:
3838

39-
|Column name|JSON data type|Description|
40-
|-----------------|---------------|-----------------|
41-
|**path**|**string**|The location of storage digests. For example, a path for a container in Azure Blob Storage.|
42-
|**last_digest_block_id**|**int**|The block ID for the last digest uploaded.|
43-
|**is_current**|**boolean**|Indicates whether this is the current path or a path used in the past.|
39+
| Column name | JSON data type | Description |
40+
| --- | --- | --- |
41+
| **path** | **string** | The location of storage digests. For example, a path for a container in Azure Blob Storage. |
42+
| **last_digest_block_id** | **int** | The block ID for the last digest uploaded. |
43+
| **is_current** | **boolean** | Indicates whether this is the current path or a path used in the past. |
44+
45+
#### [ @table_name = ] '*table_name*'
4446

45-
[ @table_name = ] '*table_name*'
46-
47-
The name of the ledger table you want to verify. This is an optional argument, if this is not specified the whole database ledger and the ledger tables are verified.
47+
The name of the ledger table you want to verify. This argument is optional. If this isn't specified, the whole database ledger and the ledger tables are verified.
4848

4949
Example of the input JSON document:
5050

5151
```json
52-
[{"path": "https://mystorage.blob.core.windows.net/sqldbledgerdigests/serverName/DatabaseName/2020-1-1 00:00:00Z", "last_digest_block_id":42, "is_current:true"} , ]
52+
[
53+
{
54+
"path": "https://mystorage.blob.core.windows.net/sqldbledgerdigests/serverName/DatabaseName/2020-1-1 00:00:00Z",
55+
"last_digest_block_id": 42,
56+
"is_current:true"
57+
},
58+
...
59+
]
5360
```
5461

5562
## Return code values
@@ -58,13 +65,13 @@ Example of the input JSON document:
5865

5966
## Result sets
6067

61-
1 row with 1 column called: last_verified_block_id
68+
One row, with one column called `last_verified_block_id`.
6269

6370
## Permissions
6471

6572
Requires the **VIEW LEDGER CONTENT** permission.
6673

67-
## See also
74+
## Next steps
6875

6976
- [Database Verification](../security/ledger/ledger-database-verification.md)
7077
- [Verify a ledger table to detect tampering](../security/ledger/ledger-verify-database.md)

docs/relational-databases/system-stored-procedures/sys-sp-verify-database-ledger-transact-sql.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
---
22
title: "sys.sp_verify_database_ledger (Transact-SQL)"
3-
description: "sys.sp_verify_database_ledger (Transact-SQL)"
3+
description: "Verifies the database ledger and the table ledgers."
44
author: VanMSFT
55
ms.author: vanto
6-
ms.date: "05/24/2022"
6+
ms.reviewer: randolphwest
7+
ms.date: 05/03/2023
78
ms.service: sql
89
ms.subservice: system-objects
910
ms.topic: "reference"
1011
dev_langs:
1112
- "TSQL"
1213
monikerRange: "= azuresqldb-current||>= sql-server-ver16||>= sql-server-linux-ver16"
1314
---
14-
1515
# sys.sp_verify_database_ledger (Transact-SQL)
1616

1717
[!INCLUDE [SQL Server 2022 Azure SQL Database](../../includes/applies-to-version/sqlserver2022-asdb.md)]
1818

19-
Verifies the database ledger and the table ledgers. For each row in the sys.database_ledger view, the stored procedure:
19+
Verifies the database ledger and the table ledgers. For each row in the `sys.database_ledger` view, the stored procedure:
2020

2121
1. Recomputes a value stored in the previous_block_hash column of the row.
2222
1. Checks if the recomputed value matches the value currently stored in the previous_block_hash column.
2323
1. If the specified list of digests contains a digest for the ledger block the row represents, it verifies the recomputed value matches the hash in the digest.
24-
1. If a ledger table name is specified using the `table_name` argument, the stored procedure verifies a table hash for the specified table, if it exists in the table_hashes column of sys.database_ledger. Otherwise, it verifies all table hashes existing in the table_hashes column of sys.database_ledger, except table hashes for non-existing (dropped) tables. When verifying a table hash for a ledger table, the stored procedure:
25-
1. Scans the history table of the ledger table to recompute the table hash, which is a hash of all rows updated by the transaction represented by the current row in sys.database_ledger in the ledger table.
26-
1. Checks if the recomputed table hash matches the value stored in the table_hashes column of sys.database_ledger for the given ledger table.
24+
1. If a ledger table name is specified using the `table_name` argument, the stored procedure verifies a table hash for the specified table, if it exists in the table_hashes column of `sys.database_ledger`. Otherwise, it verifies all table hashes existing in the table_hashes column of `sys.database_ledger`, except table hashes for non-existing (dropped) tables. When verifying a table hash for a ledger table, the stored procedure:
25+
1. Scans the history table of the ledger table to recompute the table hash, which is a hash of all rows updated by the transaction represented by the current row in `sys.database_ledger` in the ledger table.
26+
1. Checks if the recomputed table hash matches the value stored in the table_hashes column of `sys.database_ledger` for the given ledger table.
27+
28+
In addition, the stored procedure verifies all nonclustered indexes are consistent with the specified ledger table. If no ledger table is specified, it verifies all nonclustered indexes for each existing ledger table referenced in the table_hashes column in any row of `sys.database_ledger`.
2729

28-
In addition, the stored procedure verifies all non-clustered indexes are consistent with the specified ledger table. If no ledger table is specified, it verifies all non-clustered indexes for each existing ledger table referenced in the table_hashes column in any row of sys.database_ledger.
30+
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview).
2931

30-
For more information on database ledger, see [Ledger](/azure/azure-sql/database/ledger-overview)
32+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
3133

32-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
34+
## Syntax
3335

34-
## Syntax
35-
3636
```syntaxsql
37-
sp_verify_database_ledger [@digests = ] 'digests' [ , [@table_name = ] 'table_name' ]
37+
sp_verify_database_ledger [ @digests = ] 'digests' [ , [ @table_name = ] 'table_name' ]
3838
```
3939

4040
## Arguments
4141

42-
[ @digests = ] '*digests*'
42+
#### [ @digests = ] '*digests*'
4343

44-
A JSON document containing a list of transaction digests, each of which has been obtained by querying the sys.database_ledger_latest_digest view. The JSON document must contain at least one digest.
44+
A JSON document containing a list of transaction digests, each of which has been obtained by querying the `sys.database_ledger_latest_digest` view. The JSON document must contain at least one digest.
4545

46-
[ @table_name = ] '*table_name*'
46+
#### [ @table_name = ] '*table_name*'
4747

4848
The name of the table that you want to verify.
4949

@@ -53,13 +53,13 @@ The name of the table that you want to verify.
5353

5454
## Result sets
5555

56-
1 row with 1 column called: last_verified_block_id
56+
One row, with one column called `last_verified_block_id`.
5757

5858
## Permissions
5959

6060
Requires the **VIEW LEDGER CONTENT** permission.
6161

62-
## See also
62+
## Next steps
6363

6464
- [Database Verification](../security/ledger/ledger-database-verification.md)
6565
- [Verify a ledger table to detect tampering](../security/ledger/ledger-verify-database.md)

0 commit comments

Comments
 (0)