Skip to content

Commit 6dbd73a

Browse files
authored
Merge pull request #92544 from lucaferrari77/patch-1
Update sql-data-warehouse-tables-partition.md
2 parents dca78d7 + d046f6e commit 6dbd73a

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-tables-partition.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ WITH
7676
,20030101,20040101,20050101
7777
)
7878
)
79-
)
80-
;
79+
);
8180
```
8281

8382
## Migrate partitions from SQL Server
@@ -87,7 +86,7 @@ To migrate SQL Server partition definitions to dedicated SQL pool simply:
8786
- 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).
8887
- 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.
8988

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.
9190

9291
```sql
9392
-- Partition information for a SQL Server Database
@@ -119,15 +118,14 @@ GROUP BY s.[name]
119118
, p.[partition_number]
120119
, p.[rows]
121120
, rv.[value]
122-
, p.[data_compression_desc]
123-
;
121+
, p.[data_compression_desc];
124122
```
125123

126124
## Partition switching
127125

128126
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.
129127

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.
131129

132130
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).
133131

@@ -156,11 +154,11 @@ WITH
156154
(20000101
157155
)
158156
)
159-
)
160-
;
157+
);
161158

162159
INSERT INTO dbo.FactInternetSales
163160
VALUES (1,19990101,1,1,1,1,1,1);
161+
164162
INSERT INTO dbo.FactInternetSales
165163
VALUES (1,20000101,1,1,1,1,1,1);
166164
```
@@ -178,8 +176,7 @@ JOIN sys.tables t ON p.[object_id] = t.[object_id]
178176
JOIN sys.schemas s ON t.[schema_id] = s.[schema_id]
179177
JOIN sys.indexes i ON p.[object_id] = i.[object_Id]
180178
AND p.[index_Id] = i.[index_Id]
181-
WHERE t.[name] = 'FactInternetSales'
182-
;
179+
WHERE t.[name] = 'FactInternetSales';
183180
```
184181

185182
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.
198195
```sql
199196
CREATE TABLE dbo.FactInternetSales_20000101
200197
WITH ( DISTRIBUTION = HASH(ProductKey)
201-
, CLUSTERED COLUMNSTORE INDEX
198+
, CLUSTERED COLUMNSTORE INDEX
202199
, PARTITION ( [OrderDateKey] RANGE RIGHT FOR VALUES
203200
(20000101
204201
)
205202
)
206-
)
203+
)
207204
AS
208205
SELECT *
209206
FROM FactInternetSales
210-
WHERE 1=2
211-
;
207+
WHERE 1=2;
212208
```
213209

214210
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.
215211

216212
```sql
217-
ALTER TABLE FactInternetSales SWITCH PARTITION 2 TO FactInternetSales_20000101 PARTITION 2;
213+
ALTER TABLE FactInternetSales SWITCH PARTITION 2 TO FactInternetSales_20000101 PARTITION 2;
218214

219215
ALTER TABLE FactInternetSales SPLIT RANGE (20010101);
220216
```
@@ -234,8 +230,7 @@ AS
234230
SELECT *
235231
FROM [dbo].[FactInternetSales_20000101]
236232
WHERE [OrderDateKey] >= 20000101
237-
AND [OrderDateKey] < 20010101
238-
;
233+
AND [OrderDateKey] < 20010101;
239234

240235
ALTER TABLE dbo.FactInternetSales_20000101_20010101 SWITCH PARTITION 2 TO dbo.FactInternetSales PARTITION 2;
241236
```
@@ -245,6 +240,7 @@ Once you have completed the movement of the data, it is a good idea to refresh t
245240
```sql
246241
UPDATE STATISTICS [dbo].[FactInternetSales];
247242
```
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.
248244

249245
### Load new data into partitions that contain data in one step
250246

@@ -303,8 +299,7 @@ To avoid your table definition from **rusting** in your source control system, y
303299
( CLUSTERED COLUMNSTORE INDEX
304300
, DISTRIBUTION = HASH([ProductKey])
305301
, PARTITION ( [OrderDateKey] RANGE RIGHT FOR VALUES () )
306-
)
307-
;
302+
);
308303
```
309304

310305
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
331326
SELECT CAST(20030101 AS INT)
332327
UNION ALL
333328
SELECT CAST(20040101 AS INT)
334-
) a
335-
;
329+
) a;
336330
337331
-- Iterate over the partition boundaries and split the table
338332
@@ -341,8 +335,7 @@ To avoid your table definition from **rusting** in your source control system, y
341335
, @q NVARCHAR(4000) --query
342336
, @p NVARCHAR(20) = N'' --partition_number
343337
, @s NVARCHAR(128) = N'dbo' --schema
344-
, @t NVARCHAR(128) = N'FactInternetSales' --table
345-
;
338+
, @t NVARCHAR(128) = N'FactInternetSales' --table;
346339
347340
WHILE @i <= @c
348341
BEGIN

0 commit comments

Comments
 (0)