Solved

Modifying SQL 2008/2012 PARTITIONS

Posted on 2016-08-18
3
67 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
[X]
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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

756 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