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-transactions.md
+28-19Lines changed: 28 additions & 19 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
-
title: Using transactions
3
-
description: Tips for implementing transactions in Azure SQL Data Warehouse for developing solutions.
2
+
title: Use transactions in Synapse SQL pool
3
+
description: This article includes tips for implementing transactions and developing solutions in Synapse SQL pool.
4
4
services: synapse-analytics
5
5
author: XiaoyuMSFT
6
6
manager: craigg
@@ -13,19 +13,23 @@ ms.reviewer: igorstan
13
13
ms.custom: seo-lt-2019
14
14
---
15
15
16
-
# Using transactions in SQL Data Warehouse
17
-
Tips for implementing transactions in Azure SQL Data Warehouse for developing solutions.
16
+
# Use transactions in Synapse SQL pool
17
+
This article includes tips for implementing transactions and developing solutions in SQL pool.
18
18
19
19
## What to expect
20
-
As you would expect, SQL Data Warehouse supports transactions as part of the data warehouse workload. However, to ensure the performance of SQL Data Warehouse is maintained at scale some features are limited when compared to SQL Server. This article highlights the differences and lists the others.
20
+
As you would expect, SQL pool supports transactions as part of the data warehouse workload. However, to ensure SQL pool is maintained at scale, some features are limited when compared to SQL Server. This article highlights the differences.
21
21
22
22
## Transaction isolation levels
23
-
SQL Data Warehouse implements ACID transactions. The isolation level of the transactional support is default to READ UNCOMMITTED. You can change it to READ COMMITTED SNAPSHOT ISOLATION by turning ON the READ_COMMITTED_SNAPSHOT database option for a user database when connected to the master database. Once enabled, all transactions in this database are executed under READ COMMITTED SNAPSHOT ISOLATION and setting READ UNCOMMITTED on session level will not be honored. Check [ALTER DATABASE SET options (Transact-SQL)](https://docs.microsoft.com/sql/t-sql/statements/alter-database-transact-sql-set-options?view=azure-sqldw-latest) for details.
23
+
SQL pool implements ACID transactions. The isolation level of the transactional support is default to READ UNCOMMITTED. You can change it to READ COMMITTED SNAPSHOT ISOLATION by turning ON the READ_COMMITTED_SNAPSHOT database option for a user database when connected to the master database.
24
+
25
+
Once enabled, all transactions in this database are executed under READ COMMITTED SNAPSHOT ISOLATION and setting READ UNCOMMITTED on session level will not be honored. Check [ALTER DATABASE SET options (Transact-SQL)](https://docs.microsoft.com/sql/t-sql/statements/alter-database-transact-sql-set-options?view=azure-sqldw-latest) for details.
24
26
25
27
## Transaction size
26
-
A single data modification transaction is limited in size. The limit is applied per distribution. Therefore, the total allocation can be calculated by multiplying the limit by the distribution count. To approximate the maximum number of rows in the transaction divide the distribution cap by the total size of each row. For variable length columns, consider taking an average column length rather than using the maximum size.
28
+
A single data modification transaction is limited in size. The limit is applied per distribution. Therefore, the total allocation can be calculated by multiplying the limit by the distribution count.
29
+
30
+
To approximate the maximum number of rows in the transaction divide the distribution cap by the total size of each row. For variable length columns, consider taking an average column length rather than using the maximum size.
27
31
28
-
In the table below the following assumptions have been made:
32
+
In the following table, two assumptions have been made:
29
33
30
34
* An even distribution of data has occurred
31
35
* The average row length is 250 bytes
@@ -79,14 +83,17 @@ To optimize and minimize the amount of data written to the log, please refer to
79
83
>
80
84
81
85
## Transaction state
82
-
SQL Data Warehouse uses the XACT_STATE() function to report a failed transaction using the value -2. This value means the transaction has failed and is marked for rollback only.
86
+
SQL pool uses the XACT_STATE() function to report a failed transaction using the value -2. This value means the transaction has failed and is marked for rollback only.
83
87
84
88
> [!NOTE]
85
-
> The use of -2 by the XACT_STATE function to denote a failed transaction represents different behavior to SQL Server. SQL Server uses the value -1 to represent an uncommittable transaction. SQL Server can tolerate some errors inside a transaction without it having to be marked as uncommittable. For example `SELECT 1/0` would cause an error but not force a transaction into an uncommittable state. SQL Server also permits reads in the uncommittable transaction. However, SQL Data Warehouse does not let you do this. If an error occurs inside a SQL Data Warehouse transaction it will automatically enter the -2 state and you will not be able to make any further select statements until the statement has been rolled back. It is therefore important to check that your application code to see if it uses XACT_STATE() as you may need to make code modifications.
86
-
>
87
-
>
89
+
> The use of -2 by the XACT_STATE function to denote a failed transaction represents different behavior to SQL Server. SQL Server uses the value -1 to represent an uncommittable transaction. SQL Server can tolerate some errors inside a transaction without it having to be marked as uncommittable. For example, `SELECT 1/0` would cause an error but not force a transaction into an uncommittable state.
88
90
89
-
For example, in SQL Server you might see a transaction that looks like the following:
91
+
SQL Server also permits reads in the uncommittable transaction. However, SQL pool does not let you do this. If an error occurs inside a SQL pool transaction, it will automatically enter the -2 state and you will not be able to make any further select statements until the statement has been rolled back.
92
+
93
+
As such, it's important to check that your application code to see if it uses XACT_STATE() as you may need to make code modifications.
94
+
95
+
96
+
For example, in SQL Server, you might see a transaction that looks like the following:
90
97
91
98
```sql
92
99
SET NOCOUNT ON;
@@ -127,11 +134,11 @@ SELECT @xact_state AS TransactionState;
127
134
The preceding code gives the following error message:
128
135
129
136
Msg 111233, Level 16, State 1, Line 1
130
-
111233; The current transaction has aborted, and any pending changes have been rolled back. Cause: A transaction in a rollback-only state was not explicitly rolled back before a DDL, DML, or SELECT statement.
137
+
111233; The current transaction has aborted, and any pending changes have been rolled back. The cause of this issue is that a transaction in a rollback-only state not being explicitly rolled back before a DDL, DML, or SELECT statement.
131
138
132
139
You won't get the output of the ERROR_* functions.
133
140
134
-
In SQL Data Warehouse the code needs to be slightly altered:
141
+
In SQL pool the code needs to be slightly altered:
135
142
136
143
```sql
137
144
SET NOCOUNT ON;
@@ -173,17 +180,19 @@ The expected behavior is now observed. The error in the transaction is managed a
173
180
All that has changed is that the ROLLBACK of the transaction had to happen before the read of the error information in the CATCH block.
174
181
175
182
## Error_Line() function
176
-
It is also worth noting that SQL Data Warehouse does not implement or support the ERROR_LINE() function. If you have this in your code, you need to remove it to be compliant with SQL Data Warehouse. Use query labels in your code instead to implement equivalent functionality. For more details, see the [LABEL](sql-data-warehouse-develop-label.md) article.
183
+
It is also worth noting that SQL pool does not implement or support the ERROR_LINE() function. If you have this in your code, you need to remove it to be compliant with SQL pool.
184
+
185
+
Use query labels in your code instead to implement equivalent functionality. For more details, see the [LABEL](sql-data-warehouse-develop-label.md) article.
177
186
178
187
## Using THROW and RAISERROR
179
-
THROW is the more modern implementation for raising exceptions in SQL Data Warehouse but RAISERROR is also supported. There are a few differences that are worth paying attention to however.
188
+
THROW is the more modern implementation for raising exceptions in SQL pool but RAISERROR is also supported. There are a few differences that are worth paying attention to however.
180
189
181
190
* User-defined error messages numbers cannot be in the 100,000 - 150,000 range for THROW
182
191
* RAISERROR error messages are fixed at 50,000
183
192
* Use of sys.messages is not supported
184
193
185
194
## Limitations
186
-
SQL Data Warehouse does have a few other restrictions that relate to transactions.
195
+
SQL pool does have a few other restrictions that relate to transactions.
187
196
188
197
They are as follows:
189
198
@@ -195,5 +204,5 @@ They are as follows:
195
204
* No support for DDL such as CREATE TABLE inside a user-defined transaction
196
205
197
206
## Next steps
198
-
To learn more about optimizing transactions, see [Transactions best practices](sql-data-warehouse-develop-best-practices-transactions.md). To learn about other SQL Data Warehouse best practices, see [SQL Data Warehouse best practices](sql-data-warehouse-best-practices.md).
207
+
To learn more about optimizing transactions, see [Transactions best practices](sql-data-warehouse-develop-best-practices-transactions.md). To learn about other SQL pool best practices, see [SQL pool best practices](sql-data-warehouse-best-practices.md).
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-user-defined-schemas.md
+22-20Lines changed: 22 additions & 20 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 user-defined schemas
3
-
description: Tips for using T-SQL user-defined schemas in Azure SQL Data Warehouse for developing solutions.
3
+
description: Tips for using T-SQL user-defined schemas to develop solutions in Synapse SQL pool.
4
4
services: synapse-analytics
5
5
author: XiaoyuMSFT
6
6
manager: craigg
@@ -13,42 +13,44 @@ ms.reviewer: igorstan
13
13
ms.custom: seo-lt-2019
14
14
---
15
15
16
-
# Using user-defined schemas in SQL Data Warehouse
17
-
Tips for using T-SQL user-defined schemas in Azure SQL Data Warehouse for developing solutions.
16
+
# User-defined schemas in Synapse SQL pool
17
+
This article focuses on providing several tips for using T-SQL user-defined schemas to develop solutions in Synapse SQL pool.
18
18
19
19
## Schemas for application boundaries
20
20
21
-
Traditional data warehouses often use separate databases to create application boundaries based on either workload, domain or security. For example, a traditional SQL Server data warehouse might include a staging database, a data warehouse database, and some data mart databases. In this topology each database operates as a workload and security boundary in the architecture.
21
+
Traditional data warehouses often use separate databases to create application boundaries based on either workload, domain or security.
22
22
23
-
By contrast, SQL Data Warehouse runs the entire data warehouse workload within one database. Cross database joins are not permitted. Therefore SQL Data Warehouse expects all tables used by the warehouse to be stored within the one database.
23
+
As an example, a traditional SQL Server data warehouse might include a staging database, a data warehouse database, and some data mart databases. In this topology, each database operates as a workload and security boundary in the architecture.
24
+
25
+
By contrast, SQL pool runs the entire data warehouse workload within one database. Cross database joins aren't permitted. SQL pool expects all tables used by the warehouse to be stored within the one database.
24
26
25
27
> [!NOTE]
26
-
> SQL Data Warehouse does not support cross database queries of any kind. Consequently, data warehouse implementations that leverage this pattern will need to be revised.
28
+
> SQL pool does not support cross database queries of any kind. Consequently, data warehouse implementations that leverage this pattern will need to be revised.
27
29
>
28
30
>
29
31
30
32
## Recommendations
31
-
These are recommendations for consolidating workloads, security, domain and functional boundaries by using userdefined schemas
33
+
What follows are recommendations for consolidating workloads, security, domain, and functional boundaries by using user-defined schemas:
32
34
33
-
1. Use one SQL Data Warehouse database to run your entire data warehouse workload
34
-
2. Consolidate your existing data warehouse environment to use one SQL Data Warehouse database
35
-
3. Leverage **user-defined schemas** to provide the boundary previously implemented using databases.
35
+
- Use one SQL pool database to run your entire data warehouse workload.
36
+
- Consolidate your existing data warehouse environment to use one SQL pool database.
37
+
- Leverage **user-defined schemas** to provide the boundary previously implemented using databases.
36
38
37
-
If user-defined schemas have not been used previously then you have a clean slate. Simply use the old database name as the basis for your user-defined schemas in the SQL Data Warehouse database.
39
+
If user-defined schemas have not been used previously, then you have a clean slate. Use the old database name as the basis for your user-defined schemas in the SQL pool database.
38
40
39
-
If schemas have already been used then you have a few options:
41
+
If schemas have already been used, then you have a few options:
40
42
41
-
1. Remove the legacy schema names and start fresh
42
-
2. Retain the legacy schema names by pre-pending the legacy schema name to the table name
43
-
3. Retain the legacy schema names by implementing views over the table in an extra schema to re-create the old schema structure.
43
+
- Remove the legacy schema names and start fresh.
44
+
- Retain the legacy schema names by pre-pending the legacy schema name to the table name.
45
+
- Retain the legacy schema names by implementing views over the table in an extra schema to re-create the old schema structure.
44
46
45
47
> [!NOTE]
46
-
> On first inspection option 3 may seem like the most appealing option. However, the devil is in the detail. Views are read only in SQL Data Warehouse. Any data or table modification would need to be performed against the base table. Option 3 also introduces a layer of views into your system. You might want to give this some additional thought if you are using views in your architecture already.
48
+
> On first inspection option 3 may seem like the most appealing option. However, the devil is in the detail. Views are read only in SQL pool. Any data or table modification would need to be performed against the base table. Option 3 also introduces a layer of views into your system. You might want to give this some additional thought if you are using views in your architecture already.
47
49
>
48
50
>
49
51
50
52
### Examples:
51
-
Implement user-defined schemas based on database names
53
+
Implement user-defined schemas based on database names:
52
54
53
55
```sql
54
56
CREATE SCHEMA [stg]; -- stg previously database name for staging database
@@ -66,7 +68,7 @@ CREATE TABLE [edw].[customer] -- create data warehouse tables in the edw schema
66
68
);
67
69
```
68
70
69
-
Retain legacy schema names by pre-pending them to the table name. Use schemas for the workload boundary.
71
+
Keep legacy schema names by pre-pending them to the table name. Use schemas for the workload boundary:
70
72
71
73
```sql
72
74
CREATE SCHEMA [stg]; -- stg defines the staging boundary
@@ -84,7 +86,7 @@ CREATE TABLE [edw].[dim_customer] --pre-pend the old schema name to the table an
84
86
);
85
87
```
86
88
87
-
Retain legacy schema names using views
89
+
Keep legacy schema names using views:
88
90
89
91
```sql
90
92
CREATE SCHEMA [stg]; -- stg defines the staging boundary
@@ -112,7 +114,7 @@ FROM [edw].customer
112
114
```
113
115
114
116
> [!NOTE]
115
-
> Any change in schema strategy needs a review of the security model for the database. In many cases you might be able to simplify the security model by assigning permissions at the schema level. If more granular permissions are required then you can use database roles.
117
+
> Any change in schema strategy needs a review of the security model for the database. In many cases, you might be able to simplify the security model by assigning permissions at the schema level. If more granular permissions are required, then you can use database roles.
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-variable-assignment.md
+9-9Lines changed: 9 additions & 9 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: Assign variables
3
-
description: Tips for assigning T-SQL variables in Azure SQL Data Warehouse for developing solutions.
3
+
description: In this article, you'll find essential tips for assigning T-SQL variables in SQL pool.
4
4
services: synapse-analytics
5
5
author: XiaoyuMSFT
6
6
manager: craigg
@@ -13,36 +13,36 @@ ms.reviewer: igorstan
13
13
ms.custom: seo-lt-2019
14
14
---
15
15
16
-
# Assigning variables in Azure SQL Data Warehouse
16
+
# Assign variables in Synapse SQL pool
17
17
18
-
Tips for assigning T-SQL variables in Azure SQL Data Warehouse for developing solutions.
18
+
In this article, you'll find essential tips for assigning T-SQL variables in SQL pool.
19
19
20
-
## Setting variables with DECLARE
20
+
## Set variables with DECLARE
21
21
22
-
Variables in SQL Data Warehouse are set using the `DECLARE` statement or the `SET` statement. Initializing variables with DECLARE is one of the most flexible ways to set a variable value in SQL Data Warehouse.
22
+
Variables in SQL pool are set using the `DECLARE` statement or the `SET` statement. Initializing variables with DECLARE is one of the most flexible ways to set a variable value in SQL pool.
23
23
24
24
```sql
25
25
DECLARE @v int=0
26
26
;
27
27
```
28
28
29
-
You can also use DECLARE to set more than one variable at a time. You cannot use SELECT or UPDATE to do the following:
29
+
You can also use DECLARE to set more than one variable at a time. You can't use SELECT or UPDATE to do the following:
30
30
31
31
```sql
32
32
DECLARE @v INT= (SELECT TOP 1 c_customer_sk FROM Customer where c_last_name ='Smith')
33
33
, @v1 INT= (SELECT TOP 1 c_customer_sk FROM Customer where c_last_name ='Jones')
34
34
;
35
35
```
36
36
37
-
You cannot initialize and use a variable in the same DECLARE statement. To illustrate the point, the following example is **not** allowed since @p1 is both initialized and used in the same DECLARE statement. The following example gives an error.
37
+
You can't initialize and use a variable in the same DECLARE statement. To illustrate the point, the following example is **not** allowed since @p1 is both initialized and used in the same DECLARE statement. As such, the following example gives an error:
0 commit comments