Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Updating SQL partition schemes & partition functions

Posted on 2010-11-16
Medium Priority
Last Modified: 2012-05-10
My client's IT dept had set up SQL Server 2005 filegroups on a particular database for each fiscal quarter: fg2006Q4, fg2007Q1, fg2007Q2, ... up to fg2010Q4. I noticed today that the fg2010Qx files had not been used, still at 1MB each.

Upon further digging, I found the Partition Schemes and Partition Functions folders in Mgmt Studio.

One Scheme: CREATE PARTITION SCHEME [psEvent] AS PARTITION [pfEvent] TO ([fg2006Q4], [fg2007Q1], [fg2007Q2], [fg2007Q3], [fg2007Q4], [fg2008Q1], [fg2008Q2], [fg2008Q3], [fg2008Q4], [fg2009Q1], [fg2009Q2], [fg2009Q3], [fg2009Q4])

Corresponding Function: CREATE PARTITION FUNCTION [pfEvent](int) AS RANGE RIGHT FOR VALUES (1000300, 5493523, 25712235, 45243827, 67741212, 88804361, 106935897, 121343754, 122508529, 122512053, 139523161, 154878083)

Q1: I'd like to create filegroups for fg2011Qx... then can I simply ALTER PARTITION SCHEME with fg2010Q1 through fg2011Q4 added to the list?

Q2: I believe I understand the function ranges, but wondering where/how these ID's would have been generated (likely)? And more fundamentally, how would SQL know when to move onto the next filegroup (assuming it had existed when needed)?

Q3: Is there a safe & easy way to "re-balance" the filegroups... so that fg2010Qx's are used, and the fg2009Q4's aren't so big. I suppose not a huge deal if not, but it'd look cleaner if so.

Question by:jdallen75
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Expert Comment

by:Sander Stad
ID: 34153577
You can add an additional filegroup to the scheme with the following command:

NEXT USED fg2011Qx;

Than you can use the following script to alter the partition function:

IF EXISTS (SELECT * FROM sys.partition_functions
    WHERE name = 'pfEevent')
AS RANGE RIGHT FOR VALUES  (1000300, 5493523, 25712235, 45243827, 67741212, 88804361, 106935897, 121343754, 122508529, 122512053, 139523161, 154878083, xxxxxxx);

Accepted Solution

Sander Stad earned 2000 total points
ID: 34153622
The numbers in the function are not ID's but are the boundaries of rows. This website shows you what you want to know:

Q3: What do you mean by rebalance the filegroups? Do you want to change the number of records that are saved in the different filegroups?

Author Comment

ID: 34154843

Q3: I mean that, for instance, the files in fg2009Q1, Q2, and Q3 each total 10GB. However, since fg2009Q4 was the last listed in the partition scheme, it has been used since that point in time, and is now 80GB. fg2010Qx files are basically empty because they have not been used this year.

Thanks on the other points - I will look into them.

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Author Comment

ID: 34155331
I think I understand now... it looks as though the boundary values in the partition function list are SSID's of the rows in the tables. That part isn't all that intuitive, and more importantly does not cleanly divided up the data by calendar quarters. What seems to be cleaner would be to choose a datetime column from the table, and define its boundaries accordingly. "20090101, 20090401, 20090701..." is a heck of a lot clearer!

Expert Comment

by:Sander Stad
ID: 34157157
That could work but make sure your column is in date or int format because I don't know how it works with text in this case.

Author Comment

ID: 34158841
I discovered the common problem in that the partition column has to be part of the primary key, which in this case it isn't. There are a couple of workaround solutions, be we've decided in this case (since it is an archive DB), to go with one partition over several filegroups.

Thanks for your guidance.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question