SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need Help with Automating Sliding Window Partition.


Need Help with Automating Sliding Window Partition.

Author
Message
tim.cloud
tim.cloud
SSC Veteran
SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)

Group: General Forum Members
Points: 228 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?
Jared Karney
Jared Karney
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13246 Visits: 3697
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
PFE - Microsoft
SQL Know-It-All
How to post data/code on a forum to get the best help - Jeff Moden
tim.cloud
tim.cloud
SSC Veteran
SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)

Group: General Forum Members
Points: 228 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.
Jared Karney
Jared Karney
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13246 Visits: 3697
The key here is to keep your storage aligned. We'll be here to help on specifics :-) Good luck!

Thanks,
Jared
PFE - Microsoft
SQL Know-It-All
How to post data/code on a forum to get the best help - Jeff Moden
tim.cloud
tim.cloud
SSC Veteran
SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)SSC Veteran (228 reputation)

Group: General Forum Members
Points: 228 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?
Jared Karney
Jared Karney
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13246 Visits: 3697
That's all there is to it!

Thanks,
Jared
PFE - Microsoft
SQL Know-It-All
How to post data/code on a forum to get the best help - Jeff Moden
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search