Solved

Modifying SQL 2008/2012 PARTITIONS

Posted on 2016-08-18
3
46 Views
Last Modified: 2016-08-24
Dear Experts;

My client has asked me to extend a project past it's expected end date of 2016.  The database has PARTITIONS through 2017 and I need to extend or create new PARTITIONS through 2020.  The problem I'm having is with the ALTER SCHEMA and FUNCTION - I just don't know what to do.  I have the ALTER DATABASE to create the FILEGROUPs example below, but cannot figure out the syntax for the SCHEMA and FUNCTION.

Experts, I need your help.  The original script that created the PARTITIONS AND SCHEMA is attached.

Thank you!

IF NOT EXISTS(SELECT * FROM HARBOR.sys.filegroups WHERE name = 'HARBOR20181001')
BEGIN
  ALTER DATABASE HARBOR
    ADD FILEGROUP HARBOR20181001

  ALTER DATABASE HARBOR
    ADD FILE ( NAME       = N'HARBOR20181001',
               FILENAME   = N'C:\Data\HARBOR20181001.ndf',
               SIZE       = 2048KB,
               MAXSIZE    = UNLIMITED,
               FILEGROWTH = 1024KB )
     TO FILEGROUP HARBOR20181001
END
Harbor.sql
0
Comment
Question by:wdbates
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
dbaSQL earned 500 total points
ID: 41763985
You need to alter the partition function.  MSFT gives a decent example here.  Example A splits one of the existing partitions into two, thus creating a new partition:   https://technet.microsoft.com/en-us/library/ms186307.aspx

Or here's a quick example from Kalen Delaney.  The first statements The following statements will create 5 partitions with five different price boundary points:

CREATE PARTITION FUNCTION price_parts (money)
  AS RANGE LEFT FOR VALUES ( 1.00,10.00,100.00,1000.00) ;
GO

CREATE PARTITION SCHEME price_scheme
AS PARTITION price_parts
   ALL to ([PRIMARY]);
GO
SELECT * INTO NewProduct
FROM Production.Product;
GO  

CREATE CLUSTERED INDEX newproduct_pk
  ON NewProduct(ProductID)
  ON price_scheme (ListPrice);


Here we create a table for the partition:

SELECT * INTO NewProduct
FROM Production.Product;
GO  

CREATE CLUSTERED INDEX newproduct_pk
  ON NewProduct(ProductID)
  ON price_scheme (ListPrice);

Run this, you will see 5 partitions:
SELECT * FROM sys.partitions
WHERE object_id = object_id('dbo.NewProduct');

And here you split partition number 3, containing rows between 10 and 100:

ALTER PARTITION FUNCTION price_parts()
  SPLIT RANGE (50);
GO

Look again, you'll see six partitions:

SELECT * FROM sys.partitions
WHERE object_id = object_id('dbo.NewProduct');
0
 

Author Closing Comment

by:wdbates
ID: 41769222
Sorry for the delay in responding, but been on the road.  Life of the modern software developer.  Thank you for your help.
0
 
LVL 17

Expert Comment

by:dbaSQL
ID: 41769230
My pleasure.  Glad things worked out for you.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now