Solved

Modifying SQL 2008/2012 PARTITIONS

Posted on 2016-08-18
3
74 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

628 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