A table contains xyz columns, with 3 years of data.
Index = clustered column index
Hash distribution column = product.
Partition column = date.
As the new year data arrive like 2010, 2011, 2012, 2013(new).
2010 year data must be deleted, using the partition switching.
But Hash will distribute according to similar products data, and when data will be partitioned according to date it will not in same location/container/distribution.
So how partition switch will be fast as DB engine needs to run query parallel in all distributions and it will look for 2010 data in each and then remove it?
Or is there something that I am missing?
I have tried to reproduce the solution.
attempted to switch partition 4 from Sales_New to Sales.
The below is the code:
Step 1: Create new table.
Step 2: Delete 2010 from Sales table
2010 records in sales_new table.
Switch Partrition:
Partition switch operation between two tables,
[dbo].[Sales_New]and[dbo].[Sales], specifically for partition number 4.The below is the partition logic I have tried.
[SaleDate] < '20090101''20090101' <= [SaleDate] < '20100101''20100101' <= [SaleDate] < '20110101''20110101' <= [SaleDate] < '20120101''20120101' <= [SaleDate] < '20130101'As you want to delete the 2010 values falling between ‘20110101’ and ‘20120101’ would belong to Partition 4.
As you mentioned how partition switch will be fast as DB engine This operation is used in scenarios where you want to efficiently move data from one table to another without physically copying it.
The partition switch operation between two tables, [dbo].[Sales_New] and [dbo].[Sales], specifically for partition number 4.