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
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-group-by-options.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ The [GROUP BY](/sql/t-sql/queries/select-group-by-transact-sql) T-SQL clause agg
27
27
28
28
## Rollup and grouping sets options
29
29
30
-
The simplest option here is to use UNION ALL instead to perform the rollup rather than relying on the explicit syntax. The result is exactly the same.
30
+
The simplest option here is to use UNION ALL to perform the rollup rather than relying on the explicit syntax. The result is exactly the same.
31
31
32
32
The following example using the GROUP BY statement with the ROLLUP option:
33
33
```sql
@@ -79,11 +79,11 @@ JOIN dbo.DimSalesTerritory t ON s.SalesTerritoryKey = t.SalesTerritor
79
79
To replace GROUPING SETS, the sample principle applies. You only need to create UNION ALL sections for the aggregation levels you want to see.
80
80
81
81
## Cube options
82
-
It is possible to create a GROUP BY WITH CUBE using the UNION ALL approach. The problem is that the code can quickly become cumbersome and unwieldy. To mitigate this issue, you can use this more advanced approach.
82
+
It's possible to create a GROUP BY WITH CUBE using the UNION ALL approach. The problem is that the code can quickly become cumbersome and unwieldy. To mitigate this issue, you can use this more advanced approach.
83
83
84
84
Using the previous example, the first step is to define the 'cube' that defines all the levels of aggregation that we want to create.
85
85
86
-
It is important to take note of the CROSS JOIN of the two derived tables. This generates all the levels for us. The rest of the code is there for formatting:
86
+
Take note of the CROSS JOIN of the two derived tables since this generates all the levels for us. The rest of the code is there for formatting:
87
87
88
88
```sql
89
89
CREATE TABLE #Cube
@@ -141,7 +141,7 @@ WITH
141
141
;
142
142
```
143
143
144
-
The third step is to loop over our cube of columns performing the aggregation. The query will run once for every row in the #Cube temporary table and store the results in the #Results temp table:
144
+
The third step is to loop over our cube of columns performing the aggregation. The query will run once for every row in the #Cube temporary table. The results are stored in the #Results temp table:
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.
30
+
The last line tags the string 'My Query Label' to the query. This tag is helpful because the label is query-able through the DMVs.
31
31
32
32
Querying for labels provides a mechanism for locating problem queries and helping to identify progress through an ELT run.
33
33
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.
34
+
A good naming convention really helps. For example, starting the label with PROJECT, PROCEDURE, STATEMENT, or COMMENT uniquely identifies the query among all the code in source control.
35
35
36
36
The following query uses a dynamic management view to search by label.
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-loops.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,13 @@ ms.custom: seo-lt-2019
14
14
---
15
15
16
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.
17
+
Included in this article are tips for SQL pool solution development using T-SQL loops and replacing cursors.
18
18
19
19
## Purpose of WHILE loops
20
20
21
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
-
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.
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. So, WHILE loops are a great alternative for replacing cursors.
24
24
25
25
## Replacing cursors in Synapse SQL pool
26
26
However, before diving in head first you should ask yourself the following question: "Could this cursor be rewritten to use set-based operations?"
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-stored-procedures.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,22 +20,22 @@ This article provides tips for developing SQL pool solutions by implementing sto
20
20
21
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 pool there are also some features and functionality that have behavioral differences and others that are not supported.
23
+
Also, to help you maintain the scale and performance of SQL pool, there are additional features and functionalities that have behavioral differences.
24
24
25
25
26
26
## Introducing stored procedures
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.
27
+
Stored procedures are a great way for encapsulating your SQL code, which is stored close to your SQL pool data. Stored procedures also help developers modularize their solutions by encapsulating the code into manageable units, thus facilitating greater code reusability. Each stored procedure can also accept parameters to make them even more flexible.
28
28
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.
29
+
SQL pool provides a simplified and streamlined stored procedure implementation. The biggest difference compared to SQL Server is that the stored procedure isn't pre-compiled code.
30
30
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.
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's 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. So, it's helpful to think of stored procedures as containers for SQL logic.
32
32
33
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.
34
34
35
35
## Nesting stored procedures
36
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.
37
37
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.
38
+
SQL pool supports a maximum of eight nesting levels. In contrast, the nest level in SQL Server is 32.
39
39
40
40
The top-level stored procedure call equates to nest level 1.
41
41
@@ -61,13 +61,13 @@ GO
61
61
EXEC prc_nesting
62
62
```
63
63
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.
64
+
SQL pool doesn't currently support [@@NESTLEVEL](/sql/t-sql/functions/nestlevel-transact-sql). As such, you need to track the nest level. It's 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.
65
65
66
66
## INSERT..EXECUTE
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).
67
+
SQL pool doesn't permit you to consume the result set of a stored procedure with an INSERT statement. There is, however, an alternative approach you can use. For an example, see the article on [temporary tables](sql-data-warehouse-tables-temporary.md).
68
68
69
69
## Limitations
70
-
There are some aspects of Transact-SQL stored procedures that are not implemented in SQL pool, and they are as follows:
70
+
There are some aspects of Transact-SQL stored procedures that aren't implemented in SQL pool, which are as follows:
0 commit comments