SQL Server Table Partitioning Strategy for Date-Based Data

I’m working with a SQL Server 2008 database that contains thousands of tables from 2005. Around 20-30% of these tables grow by approximately 200,000 rows each year.

I need to create statistics visualizations based on a dateLastModified column. My plan is to organize data into time-based partition categories: 10 years, 5 years, 3 years, 1 year, 6 months, 3 months, 1 month, 2 weeks, and current date. These would be labeled as partition1, partition2, through partition9.

The challenge is that I run a weekly job that shifts these partitions based on the current date. For example, after one week partition9 moves to partition8, after two weeks partition8 shifts to partition7, and so on.

My questions are:

  1. Can I implement a partitioning strategy that dynamically adjusts based on the current date?
  2. Given that my database uses about 31,556 MB of space, would horizontal partitioning provide better query performance compared to scanning entire tables?
-- Example of what I'm trying to achieve
CREATE PARTITION FUNCTION TimeBasedPartition (datetime)
AS RANGE RIGHT FOR VALUES 
(
    DATEADD(year, -10, GETDATE()),
    DATEADD(year, -5, GETDATE()),
    DATEADD(year, -3, GETDATE())
);

Any advice on whether this approach makes sense for my scenario?

The approach you’re describing has a fundamental issue - SQL Server partition functions don’t support dynamic expressions like GETDATE() in the boundary values. The partition boundaries are fixed at creation time and cannot automatically shift based on the current date. What you’ll actually need is a sliding window partitioning strategy where you manually manage the partition boundaries through your weekly job. This involves dropping the oldest partition, merging ranges, and adding new partitions with specific datetime values rather than relative functions. Regarding performance benefits, with 200k rows added annually across your tables, partitioning will likely help query performance significantly when filtering by dateLastModified. However, the maintenance overhead of weekly partition management might outweigh the benefits unless your queries consistently filter on date ranges that align with your partition scheme. A simpler alternative might be creating filtered indexes on dateLastModified for your specific time ranges rather than implementing full table partitioning. This would give you similar query performance improvements without the complexity of managing sliding partitions.

Your partitioning concept faces practical challenges beyond the GETDATE() limitation already mentioned. I’ve dealt with similar scenarios and found that weekly partition boundary adjustments create significant maintenance complexity, especially with thousands of tables. The ALTER PARTITION SCHEME operations required for your sliding window approach will generate substantial I/O overhead and potential blocking issues during your weekly jobs.

For your data volume and growth pattern, consider implementing a hybrid approach instead. Create static yearly partitions for historical data (which rarely changes) and use a separate hot partition for recent data. This reduces maintenance while still providing performance benefits for your statistics queries. Your 31GB database size suggests that proper indexing on dateLastModified might deliver comparable performance without partitioning complexity.

Before committing to partitioning, test your typical statistics queries against a representative dataset. Many date-range queries perform well with clustered indexes on dateLastModified, particularly when combined with page compression for older data. The administrative burden of managing partition functions across thousands of tables often exceeds the performance gains unless you have very specific query patterns that consistently benefit from partition elimination.

honestly this sounds like overengineering for your scenario. with only 200k rows added yearly, you’re probaly better off just creating good indexes on dateLastModified rather than dealing with weekly partition maintainence headaches. partitioning works best when you have predictable query patterns that consistently eliminate partitions - not sure thats the case here