Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Automate Sliding Window Partition Maintenance: Part II Expand / Collapse
Posted Monday, December 20, 2010 10:34 PM


Group: General Forum Members
Last Login: Thursday, April 3, 2014 7:35 PM
Points: 401, Visits: 166
Comments posted to this topic are about the item Automate Sliding Window Partition Maintenance: Part II

Post #1037499
Posted Tuesday, December 21, 2010 9:28 AM



Group: General Forum Members
Last Login: Yesterday @ 8:01 PM
Points: 21,642, Visits: 15,312
Thanks for continuing the series on this subject.

Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1037807
Posted Tuesday, December 21, 2010 9:36 AM


Group: General Forum Members
Last Login: Wednesday, July 9, 2014 11:04 AM
Points: 14, Visits: 264
I have encouraged our DBA team to get powershell installed (SQL 2005) - no luck yet. Meanwhile I use a procedure for each partitioning function. Here is an example where boundaries are YYYYMM. For monthly loads - we call this in ETL process before insert. You'll notice no use of filegroups - it would take a bit more code if we were strategically using filegroups.

Ommitted try/catch, error handling to keep is short.

create procedure [dbo].[CreateYearMonthPartition] @YearMonth int as
declare @PartitionId int
-- check if partition for this period already exists
select @PartitionId = rv.boundary_id + 1
from sys.partition_functions pf
join sys.partition_range_values rv on pf.function_id=rv.function_id
and rv.value=@YearMonth
if @PartitionId is null
-- partition does not exist; create it.
alter partition scheme [YearMonth_RangeR_scheme]
next used [PRIMARY]
alter partition function [YearMonth_RangeR]()
split range (@YearMonth)

Post #1037812
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse