Reputation: 22556
I have been following some SQL Server table partitioning tutorials, but i can't seem to find a overview or explanation of how all the aspects fit together.
I have an existing table that I want to partition called 'Orders
' for example.
So I go and create my partition function on Orders table
.
I then create my partition scheme on top of the partition function.
Does that mean that if I insert into Table1 that it will now be partitioned automatically? Or which is the part I don't understand, in the tutorial there is the following:
--******************
--6. CREATE OBJECTS ON THE PARTITION SCHEME
--******************
--Create a partitioned heap... yep, you can do that!
CREATE TABLE OrdersDaily (
OrderDate DATETIME2(0) NOT NULL,
OrderId int IDENTITY NOT NULL,
OrderName nvarchar(256) NOT NULL
) on DailyPartitionSceheme(OrderDate)
GO
From what I understand about this, is they are essentially creating a duplicate table but putting it as an object on top of the partition scheme. Do I have to do this?
Upvotes: 0
Views: 72
Reputation: 621
Partitioning an already existing non-partitioned table is tricky and not-necessarily recommended. I'm not sure how big your existing table is, or how many tables may already have foreign keys referencing it, etc., so YMMV. Two possible approaches come to mind:
I. Go old-school with a partitioned view instead.
OR
II. 1. Create a partition function that, initially, has only a single partition, e.g.:
CREATE PARTITION FUNCTION OrdersFunction (datetime2) AS RANGE LEFT FOR VALUES ();
CREATE PARTITION SCHEME DailyPartitionScheme AS PARTITION OrdersFunction TO ([PRIMARY]);
ALTER TABLE Orders SWITCH TO OrdersDaily PARTITION 1
Upvotes: 1