You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
31
33
32
34
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.
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-loops.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
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.
4
4
services: synapse-analytics
5
5
author: XiaoyuMSFT
6
6
manager: craigg
@@ -13,17 +13,21 @@ ms.reviewer: igorstan
13
13
ms.custom: seo-lt-2019
14
14
---
15
15
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.
18
18
19
19
## Purpose of WHILE loops
20
20
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.
22
22
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.
25
24
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.
27
31
28
32
First, create a temporary table containing a unique row number used to identify the individual statements:
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-stored-procedures.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
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.
4
4
services: synapse-analytics
5
5
author: XiaoyuMSFT
6
6
manager: craigg
@@ -13,27 +13,29 @@ ms.reviewer: igorstan
13
13
ms.custom: seo-lt-2019
14
14
---
15
15
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.
18
18
19
19
## What to expect
20
20
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.
22
22
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.
24
24
25
25
26
26
## Introducing stored procedures
27
27
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.
28
28
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.
30
30
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.
32
34
33
35
## Nesting stored procedures
34
36
When stored procedures call other stored procedures, or execute dynamic SQL, then the inner stored procedure or code invocation is said to be nested.
35
37
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.
37
39
38
40
The top-level stored procedure call equates to nest level 1.
39
41
@@ -59,15 +61,13 @@ GO
59
61
EXEC prc_nesting
60
62
```
61
63
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.
63
65
64
66
## 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).
66
68
67
69
## 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:
0 commit comments