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-tables-partition.md
+16-23Lines changed: 16 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,8 +76,7 @@ WITH
76
76
,20030101,20040101,20050101
77
77
)
78
78
)
79
-
)
80
-
;
79
+
);
81
80
```
82
81
83
82
## Migrate partitions from SQL Server
@@ -87,7 +86,7 @@ To migrate SQL Server partition definitions to dedicated SQL pool simply:
87
86
- Eliminate the SQL Server [partition scheme](/sql/t-sql/statements/create-partition-scheme-transact-sql?toc=/azure/synapse-analytics/sql-data-warehouse/toc.json&bc=/azure/synapse-analytics/sql-data-warehouse/breadcrumb/toc.json&view=azure-sqldw-latest&preserve-view=true).
88
87
- Add the [partition function](/sql/t-sql/statements/create-partition-function-transact-sql?toc=/azure/synapse-analytics/sql-data-warehouse/toc.json&bc=/azure/synapse-analytics/sql-data-warehouse/breadcrumb/toc.json&view=azure-sqldw-latest&preserve-view=true) definition to your CREATE TABLE.
89
88
90
-
If you are migrating a partitioned table from a SQL Server instance, the following SQL can help you to figure out the number of rows that in each partition. Keep in mind that if the same partitioning granularity is used in dedicated SQL pool, the number of rows per partition decreases by a factor of 60.
89
+
If you are migrating a partitioned table from a SQL Server instance, the following SQL can help you to figure out the number of rows in each partition. Keep in mind that if the same partitioning granularity is used in dedicated SQL pool, the number of rows per partition decreases by a factor of 60.
91
90
92
91
```sql
93
92
-- Partition information for a SQL Server Database
@@ -119,15 +118,14 @@ GROUP BY s.[name]
119
118
, p.[partition_number]
120
119
, p.[rows]
121
120
, rv.[value]
122
-
, p.[data_compression_desc]
123
-
;
121
+
, p.[data_compression_desc];
124
122
```
125
123
126
124
## Partition switching
127
125
128
126
Dedicated SQL pool supports partition splitting, merging, and switching. Each of these functions is executed using the [ALTER TABLE](/sql/t-sql/statements/alter-table-transact-sql?toc=/azure/synapse-analytics/sql-data-warehouse/toc.json&bc=/azure/synapse-analytics/sql-data-warehouse/breadcrumb/toc.json&view=azure-sqldw-latest&preserve-view=true) statement.
129
127
130
-
To switch partitions between two tables, you must ensure that the partitions align on their respective boundaries and that the table definitions match. As check constraints are not available to enforce the range of values in a table, the source table must contain the same partition boundaries as the target table. If the partition boundaries are not then same, then the partition switch will fail as the partition metadata will not be synchronized.
128
+
To switch partitions between two tables, you must ensure that the partitions align on their respective boundaries and that the table definitions match. As check constraints are not available to enforce the range of values in a table, the source table must contain the same partition boundaries as the target table. If the partition boundaries are not the same, then the partition switch will fail as the partition metadata will not be synchronized.
131
129
132
130
A partition split requires the respective partition (not necessarily the whole table) to be empty if the table has a clustered columnstore index (CCI). Other partitions in the same table can contain data. A partition that contains data cannot be split, it will result in error: `ALTER PARTITION statement failed because the partition is not empty. Only empty partitions can be split in when a columnstore index exists on the table. Consider disabling the columnstore index before issuing the ALTER PARTITION statement, then rebuilding the columnstore index after ALTER PARTITION is complete.` As a workaround to split a partition containing data, see [How to split a partition that contains data](#how-to-split-a-partition-that-contains-data).
133
131
@@ -156,11 +154,11 @@ WITH
156
154
(20000101
157
155
)
158
156
)
159
-
)
160
-
;
157
+
);
161
158
162
159
INSERT INTOdbo.FactInternetSales
163
160
VALUES (1,19990101,1,1,1,1,1,1);
161
+
164
162
INSERT INTOdbo.FactInternetSales
165
163
VALUES (1,20000101,1,1,1,1,1,1);
166
164
```
@@ -178,8 +176,7 @@ JOIN sys.tables t ON p.[object_id] = t.[object_id]
178
176
JOINsys.schemas s ON t.[schema_id] = s.[schema_id]
179
177
JOINsys.indexes i ON p.[object_id] = i.[object_Id]
180
178
AND p.[index_Id] = i.[index_Id]
181
-
WHERE t.[name] ='FactInternetSales'
182
-
;
179
+
WHERE t.[name] ='FactInternetSales';
183
180
```
184
181
185
182
The following split command receives an error message:
@@ -198,23 +195,22 @@ However, you can use `CTAS` to create a new table to hold the data.
198
195
```sql
199
196
CREATETABLEdbo.FactInternetSales_20000101
200
197
WITH ( DISTRIBUTION = HASH(ProductKey)
201
-
, CLUSTERED COLUMNSTORE INDEX
198
+
, CLUSTERED COLUMNSTORE INDEX
202
199
, PARTITION ( [OrderDateKey] RANGE RIGHT FOR VALUES
203
200
(20000101
204
201
)
205
202
)
206
-
)
203
+
)
207
204
AS
208
205
SELECT*
209
206
FROM FactInternetSales
210
-
WHERE1=2
211
-
;
207
+
WHERE1=2;
212
208
```
213
209
214
210
As the partition boundaries are aligned, a switch is permitted. This will leave the source table with an empty partition that you can subsequently split.
215
211
216
212
```sql
217
-
ALTERTABLE FactInternetSales SWITCH PARTITION 2 TO FactInternetSales_20000101 PARTITION 2;
213
+
ALTERTABLE FactInternetSales SWITCH PARTITION 2 TO FactInternetSales_20000101 PARTITION 2;
218
214
219
215
ALTERTABLE FactInternetSales SPLIT RANGE (20010101);
220
216
```
@@ -234,8 +230,7 @@ AS
234
230
SELECT*
235
231
FROM [dbo].[FactInternetSales_20000101]
236
232
WHERE [OrderDateKey] >=20000101
237
-
AND [OrderDateKey] <20010101
238
-
;
233
+
AND [OrderDateKey] <20010101;
239
234
240
235
ALTERTABLEdbo.FactInternetSales_20000101_20010101 SWITCH PARTITION 2 TO dbo.FactInternetSales PARTITION 2;
241
236
```
@@ -245,6 +240,7 @@ Once you have completed the movement of the data, it is a good idea to refresh t
245
240
```sql
246
241
UPDATE STATISTICS [dbo].[FactInternetSales];
247
242
```
243
+
Finally, in the case of a one-time partition switch to move data, you could drop the tables created for the partition switch, `FactInternetSales_20000101_20010101` and `FactInternetSales_20000101`. Alternatively, you may want to keep empty tables for regular, automated partition switches.
248
244
249
245
### Load new data into partitions that contain data in one step
250
246
@@ -303,8 +299,7 @@ To avoid your table definition from **rusting** in your source control system, y
303
299
( CLUSTERED COLUMNSTORE INDEX
304
300
, DISTRIBUTION = HASH([ProductKey])
305
301
, PARTITION ( [OrderDateKey] RANGE RIGHT FOR VALUES () )
306
-
)
307
-
;
302
+
);
308
303
```
309
304
310
305
1. `SPLIT` the table as part of the deployment process:
@@ -331,8 +326,7 @@ To avoid your table definition from **rusting** in your source control system, y
331
326
SELECT CAST(20030101 AS INT)
332
327
UNION ALL
333
328
SELECT CAST(20040101 AS INT)
334
-
) a
335
-
;
329
+
) a;
336
330
337
331
-- Iterate over the partition boundaries and split the table
338
332
@@ -341,8 +335,7 @@ To avoid your table definition from **rusting** in your source control system, y
0 commit comments