My Goal is to create a partitioned table with a rolling window of three months without having the data move file groups. The issue I am running into is that when you want to Merge the last two partitions together to "remove" the old data, the partition that I want to keep moves to the file group where the data I want to delete lives. I’m not sure if there is anyway aroudn this so maybe someone has a mthod for doing rolling windows that doesn’t require the data to move around to different file groups?According to BOL: "The merged partition resides in the filegroup that originally did not hold boundary_value", which sounds like there is nothing I can do. If that is the case, then all I can say is “wow.” Hopefully I’m missing something here. Below is a rough sample of what I am trying to do, I did not script the creation of the file groups:-- Create Partition Function, Scheme and TableCREATE PARTITION FUNCTION PF_3MonthRolling(INT)AS RANGE RIGHT FOR VALUES ( 20070201, 20070301)GOCREATE PARTITION SCHEME PS_3MonthRollingAS PARTITION PF_3MonthRollingTO (FG1, FG2, FG3)GOCREATE TABLE MyFact( ID INT, DateNumber INT, ItemCount INT) ON PS_3MonthRolling(DateNumber)GOCREATE CLUSTERED INDEX IX_MyFact_DateNumber ON MyFact( DateNumber ASC) WITH FILLFACTOR = 100 ON PS_3MonthRolling(DateNumber)GO-- Load Sample DataINSERT MyFactSELECT 1, 20070114, 12UNION ALL SELECT 2, 20070118, 32UNION ALL SELECT 3, 20070205, 18UNION ALL SELECT 4, 20070211, 98UNION ALL SELECT 5, 20070227, 13UNION ALL SELECT 6, 20070303, 76UNION ALL SELECT 7, 20070309, 11UNION ALL SELECT 8, 20070314, 1UNION ALL SELECT 9, 20070323, 3-- Verify that data was split into the appropriate partitionsSELECT $PARTITION.PF_3MonthRolling(DateNumber) AS [Partition#], COUNT(*) AS RowCnt, MIN(DateNumber) AS MinDate, MAX(DateNumber) AS MaxDateFROM MyFact GROUP BY $PARTITION.PF_3MonthRolling(DateNumber)ORDER BY [Partition#]-- DROP TABLE MyFact20070201-- Create New Table to move OLD data intoCREATE TABLE MyFact20070201( ID INT, DateNumber INT, ItemCount INT) ON FG1GOCREATE CLUSTERED INDEX IX_MyFact20070201_DateNumber ON MyFact20070201( DateNumber ASC) WITH FILLFACTOR = 100 ON FG1ALTER PARTITION SCHEME PS_3MonthRolling NEXT USED [FG2]GO-- Move old data to "OLD" tableALTER TABLE dbo.MyFactSWITCH PARTITION 1 TO dbo.MyFact20070201GO-- Merge the Range -- This is the problem (at least the way I've done it)ALTER PARTITION FUNCTION PF_3MonthRolling() MERGE RANGE (20070201)GO-- Check partitions (this should be as expected) 2 partitions with dataSELECT $PARTITION.PF_3MonthRolling(DateNumber) AS [Partition#], COUNT(*) AS RowCnt, MIN(DateNumber) AS MinDate, MAX(DateNumber) AS MaxDateFROM MyFact GROUP BY $PARTITION.PF_3MonthRolling(DateNumber)ORDER BY [Partition#]-------------------------------------------------------------------------------- HERE IS THE PROBLEM-------------------------------------------------------------------------------- When we check the partions and their file groups we see-- that the data on our original partition 2 (FG2) has moved over to FG1.SELECT ps.name AS PSName, dds.destination_id AS PartitionNumber, fg.name AS FileGroupNameFROM sys.tables AS t INNER JOIN sys.indexes AS i ON t.object_id = i.object_idINNER JOIN sys.partition_schemes AS ps ON i.data_space_id = ps.data_space_idINNER JOIN sys.destination_data_spaces AS dds ON ps.data_space_id = dds.partition_scheme_idINNER JOIN sys.filegroups AS fg ON dds.data_space_id = fg.data_space_idWHERE t.name = 'MyFact' AND i.index_id IN (0,1) -- Create New table to merge inCREATE TABLE MyFact20070401( ID INT, DateNumber INT, ItemCount INT) ON FG1GOCREATE CLUSTERED INDEX IX_MyFact20070401_DateNumber ON MyFact20070401( DateNumber ASC) WITH FILLFACTOR = 100 ON FG1-- Split the Range for new dataALTER PARTITION FUNCTION PS_3MonthRolling() SPLIT RANGE (20070401)GO--DROP TABLE MyFact--DROP PARTITION SCHEME PS_3MonthRolling--DROP PARTITION FUNCTION PF_3MonthRolling
Any help would be apreciated!