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

Need Help with Automating Sliding Window Partition. Expand / Collapse
Author
Message
Posted Wednesday, August 1, 2012 1:48 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 3, 2013 2:11 PM
Points: 54, Visits: 349
I need to implement something similar to this:
http://www.sqlservercentral.com/articles/Partitioning/71655/

However, there are some differences between that article, and what I need to implement.
These are:
1.) I need this done for a single table.
2.) I need each partition to be for a year, rather than a month.
3.) I don't want any data removed, so I don't need what happens in part III at all.
4.) I don't want to use PowerShell, I just want pure T-SQL with agent jobs.

Can anyone help or point me in the right direction?
Post #1338786
Posted Wednesday, August 1, 2012 1:55 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:40 AM
Points: 2,692, Visits: 3,383
1.) I need this done for a single table.

A Partition function and scheme are not table specific, the table is built on the scheme. So if you have more than 1 table built on this scheme, you cannot do it for only 1 table.
2.) I need each partition to be for a year, rather than a month.

Then you create your function based on years and not on months.
3.) I don't want any data removed, so I don't need what happens in part III at all.

Don't do part III. Simply merge that partition in with the left partition.
4.) I don't want to use PowerShell, I just want pure T-SQL with agent jobs.

Write the job in SQL.

Try this:http://msdn.microsoft.com/en-us/library/aa964122%28v=sql.90%29.aspx

If this is a question on how to partition and how to write your functions and such... Best to give it a try first and post any specific issues with proper DDL.


Thanks,

Jared
SQL Know-It-All

How to post data/code on a forum to get the best help - Jeff Moden
Post #1338791
Posted Thursday, August 2, 2012 8:04 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 3, 2013 2:11 PM
Points: 54, Visits: 349
I like that article, it looks just like what I need.
I'll study it, and use it as a baseline to write similar code without getting rid of any data.
Then, I'll post that and let you see if you think it will work.
Of course I'll test it in my dev environment, but any help or advice is appreciated as this is my first forey into SQL partitioning.
Post #1339191
Posted Thursday, August 2, 2012 8:18 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:40 AM
Points: 2,692, Visits: 3,383
The key here is to keep your storage aligned. We'll be here to help on specifics Good luck!

Thanks,

Jared
SQL Know-It-All

How to post data/code on a forum to get the best help - Jeff Moden
Post #1339200
Posted Thursday, August 2, 2012 8:51 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, December 3, 2013 2:11 PM
Points: 54, Visits: 349
Ok, 1 quick question.
So, I want to modify the partition function to be based on years...but is it really as simple as turning this:
create partition function pfDaily (datetime)
as RANGE RIGHT for values(
'2005-05-07', '2005-05-08', '2005-05-09', '2005-05-10', '2005-05-11', '2005-05-12', '2005-05-13', '2005-05-14',
'2005-05-15', '2005-05-16', '2005-05-17', '2005-05-18', '2005-05-19', '2005-05-20', '2005-05-21', '2005-05-22',
'2005-05-23', '2005-05-24', '2005-05-25', '2005-05-26', '2005-05-27', '2005-05-28', '2005-05-29', '2005-05-30',
'2005-05-31', '2005-06-01', '2005-06-02', '2005-06-03', '2005-06-04', '2005-06-05', '2005-06-06', '2005-06-07',
'2005-06-08', '2005-06-09', '2005-06-10', '2005-06-11', '2005-06-12', '2005-06-13', '2005-06-14', '2005-06-15',
'2005-06-16', '2005-06-17', '2005-06-18', '2005-06-19', '2005-06-20', '2005-06-21', '2005-06-22', '2005-06-23',
'2005-06-24', '2005-06-25', '2005-06-26', '2005-06-27', '2005-06-28', '2005-06-29', '2005-06-30', '2005-07-01',
'2005-07-02', '2005-07-03', '2005-07-04')

and making it this:
create partition function pfDaily (datetime)
as RANGE RIGHT for values(
'2005-10-01', '2006-10-01', '2007-10-01', '2008-10-01', '2009-10-01', '2010-10-01', '2011-10-01', '2012-10-01')

What I'm trying to do here is to create a seperare partition for each year, and I'm defining a year as 10-01-XXXX through 9-31-XXXX.
Does that make sense?
Post #1339239
Posted Thursday, August 2, 2012 8:53 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:40 AM
Points: 2,692, Visits: 3,383
That's all there is to it!

Thanks,

Jared
SQL Know-It-All

How to post data/code on a forum to get the best help - Jeff Moden
Post #1339243
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse