Skip to content

Commit de3ab62

Browse files
committed
label loops and procedures
1 parent 2a4f994 commit de3ab62

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-label.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using labels to instrument queries
3-
description: Tips for using labels to instrument queries in Azure SQL Data Warehouse for developing solutions.
3+
description: Tips for using labels to instrument queries in Synapse SQL pool for developing solutions.
44
services: synapse-analytics
55
author: XiaoyuMSFT
66
manager: craigg
@@ -13,12 +13,12 @@ ms.reviewer: igorstan
1313
ms.custom: seo-lt-2019
1414
---
1515

16-
# Using labels to instrument queries in Azure SQL Data Warehouse
17-
Tips for using labels to instrument queries in Azure SQL Data Warehouse for developing solutions.
16+
# Using labels to instrument queries in Synapse SQL pool
17+
Included in this article are tips for developing solutions using labels to instrument queries in SQL pool.
1818

1919

2020
## What are labels?
21-
SQL Data Warehouse supports a concept called query labels. Before going into any depth, let's look at an example:
21+
SQL pool supports a concept called query labels. Before going into any depth, let's look at an example:
2222

2323
```sql
2424
SELECT *
@@ -27,7 +27,9 @@ OPTION (LABEL = 'My Query Label')
2727
;
2828
```
2929

30-
The last line tags the string 'My Query Label' to the query. This tag is particularly helpful since the label is query-able through the DMVs. Querying for labels provides a mechanism for locating problem queries and helping to identify progress through an ELT run.
30+
The last line tags the string 'My Query Label' to the query. This tag is particularly helpful since the label is query-able through the DMVs.
31+
32+
Querying for labels provides a mechanism for locating problem queries and helping to identify progress through an ELT run.
3133

3234
A good naming convention really helps. For example, starting the label with PROJECT, PROCEDURE, STATEMENT, or COMMENT helps to uniquely identify the query among all the code in source control.
3335

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-loops.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using T-SQL loops
3-
description: Tips for using T-SQL loops and replacing cursors in Azure SQL Data Warehouse for developing solutions.
3+
description: Tips for solution development using T-SQL loops and replacing cursors in Synapse SQL pool.
44
services: synapse-analytics
55
author: XiaoyuMSFT
66
manager: craigg
@@ -13,17 +13,21 @@ ms.reviewer: igorstan
1313
ms.custom: seo-lt-2019
1414
---
1515

16-
# Using T-SQL loops in SQL Data Warehouse
17-
Tips for using T-SQL loops and replacing cursors in Azure SQL Data Warehouse for developing solutions.
16+
# Using T-SQL loops in Synapse SQL pool
17+
Included in this article are tips for solution development using T-SQL loops and replacing cursors in SQL pool.
1818

1919
## Purpose of WHILE loops
2020

21-
SQL Data Warehouse supports the [WHILE](/sql/t-sql/language-elements/while-transact-sql) loop for repeatedly executing statement blocks. This WHILE loop continues for as long as the specified conditions are true or until the code specifically terminates the loop using the BREAK keyword. Loops are useful for replacing cursors defined in SQL code. Fortunately, almost all cursors that are written in SQL code are of the fast forward, read-only variety. Therefore, [WHILE] loops are a great alternative for replacing cursors.
21+
Synapse SQL pool supports the [WHILE](https://docs.microsoft.com/sql/t-sql/language-elements/while-transact-sql?view=sql-server-ver15) loop for repeatedly executing statement blocks. This WHILE loop continues for as long as the specified conditions are true or until the code specifically terminates the loop using the BREAK keyword.
2222

23-
## Replacing cursors in SQL Data Warehouse
24-
However, before diving in head first you should ask yourself the following question: "Could this cursor be rewritten to use set-based operations?." In many cases, the answer is yes and is often the best approach. A set-based operation often performs faster than an iterative, row by row approach.
23+
Loops are useful for replacing cursors defined in SQL code. Fortunately, almost all cursors that are written in SQL code are of the fast forward, read-only variety. Therefore, WHILE loops are a great alternative for replacing cursors.
2524

26-
Fast forward read-only cursors can be easily replaced with a looping construct. The following is a simple example. This code example updates the statistics for every table in the database. By iterating over the tables in the loop, each command executes in sequence.
25+
## Replacing cursors in Synapse SQL pool
26+
However, before diving in head first you should ask yourself the following question: "Could this cursor be rewritten to use set-based operations?"
27+
28+
In many cases, the answer is yes and is frequently the best approach. A set-based operation often performs faster than an iterative, row by row approach.
29+
30+
Fast forward read-only cursors can be easily replaced with a looping construct. The following example is a simple one. This code example updates the statistics for every table in the database. By iterating over the tables in the loop, each command executes in sequence.
2731

2832
First, create a temporary table containing a unique row number used to identify the individual statements:
2933

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-stored-procedures.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using stored procedures
3-
description: Tips for implementing stored procedures in Azure SQL Data Warehouse for developing solutions.
3+
description: Tips for developing solutions by implementing stored procedures in Synapse SQL pool.
44
services: synapse-analytics
55
author: XiaoyuMSFT
66
manager: craigg
@@ -13,27 +13,29 @@ ms.reviewer: igorstan
1313
ms.custom: seo-lt-2019
1414
---
1515

16-
# Using stored procedures in SQL Data Warehouse
17-
Tips for implementing stored procedures in Azure SQL Data Warehouse for developing solutions.
16+
# Using stored procedures in Synapse SQL pool
17+
This article provides tips for developing SQL pool solutions by implementing stored procedures.
1818

1919
## What to expect
2020

21-
SQL Data Warehouse supports many of the T-SQL features that are used in SQL Server. More importantly, there are scale-out specific features that you can use to maximize the performance of your solution.
21+
SQL pool supports many of the T-SQL features that are used in SQL Server. More importantly, there are scale-out specific features that you can use to maximize the performance of your solution.
2222

23-
However, to maintain the scale and performance of SQL Data Warehouse there are also some features and functionality that have behavioral differences and others that are not supported.
23+
However, to maintain the scale and performance of SQL pool there are also some features and functionality that have behavioral differences and others that are not supported.
2424

2525

2626
## Introducing stored procedures
2727
Stored procedures are a great way for encapsulating your SQL code; storing it close to your data in the data warehouse. Stored procedures help developers modularize their solutions by encapsulating the code into manageable units; facilitating greater reusability of code. Each stored procedure can also accept parameters to make them even more flexible.
2828

29-
SQL Data Warehouse provides a simplified and streamlined stored procedure implementation. The biggest difference compared to SQL Server is that the stored procedure is not pre-compiled code. In data warehouses, the compilation time is small in comparison to the time it takes to run queries against large data volumes. It is more important to ensure the stored procedure code is correctly optimized for large queries. The goal is to save hours, minutes, and seconds, not milliseconds. It is therefore more helpful to think of stored procedures as containers for SQL logic.
29+
SQL pool provides a simplified and streamlined stored procedure implementation. The biggest difference compared to SQL Server is that the stored procedure is not pre-compiled code.
3030

31-
When SQL Data Warehouse executes your stored procedure, the SQL statements are parsed, translated, and optimized at run time. During this process, each statement is converted into distributed queries. The SQL code that is executed against the data is different than the query submitted.
31+
In general, for data warehouses, the compilation time is small in comparison to the time it takes to run queries against large data volumes. It is more important to ensure the stored procedure code is correctly optimized for large queries. The goal is to save hours, minutes, and seconds, not milliseconds. It is therefore more helpful to think of stored procedures as containers for SQL logic.
32+
33+
When SQL pool executes your stored procedure, the SQL statements are parsed, translated, and optimized at run time. During this process, each statement is converted into distributed queries. The SQL code that is executed against the data is different than the query submitted.
3234

3335
## Nesting stored procedures
3436
When stored procedures call other stored procedures, or execute dynamic SQL, then the inner stored procedure or code invocation is said to be nested.
3537

36-
SQL Data Warehouse supports a maximum of eight nesting levels. This is slightly different to SQL Server. The nest level in SQL Server is 32.
38+
SQL pool supports a maximum of eight nesting levels. This is slightly different to SQL Server. The nest level in SQL Server is 32.
3739

3840
The top-level stored procedure call equates to nest level 1.
3941

@@ -59,15 +61,13 @@ GO
5961
EXEC prc_nesting
6062
```
6163
62-
Note, SQL Data Warehouse does not currently support [@@NESTLEVEL](/sql/t-sql/functions/nestlevel-transact-sql). You need to track the nest level. It is unlikely for you to exceed the eight nest level limit, but if you do, you need to rework your code to fit the nesting levels within this limit.
64+
Note, SQL pool does not currently support [@@NESTLEVEL](/sql/t-sql/functions/nestlevel-transact-sql). You need to track the nest level. It is unlikely that you'll exceed the eight nest level limit, but if you do, you need to rework your code to fit the nesting levels within this limit.
6365

6466
## INSERT..EXECUTE
65-
SQL Data Warehouse does not permit you to consume the result set of a stored procedure with an INSERT statement. However, there is an alternative approach you can use. For an example, see the article on [temporary tables](sql-data-warehouse-tables-temporary.md).
67+
SQL pool does not permit you to consume the result set of a stored procedure with an INSERT statement. However, there is an alternative approach you can use. For an example, see the article on [temporary tables](sql-data-warehouse-tables-temporary.md).
6668

6769
## Limitations
68-
There are some aspects of Transact-SQL stored procedures that are not implemented in SQL Data Warehouse.
69-
70-
They are:
70+
There are some aspects of Transact-SQL stored procedures that are not implemented in SQL pool, and they are as follows:
7171

7272
* temporary stored procedures
7373
* numbered stored procedures

0 commit comments

Comments
 (0)