Main objective: Add partitioning to table to make deletion of old orders non-blocking/quicker (and also understand partitioning)
I have an existing table Order, like this:
CREATE TABLE Order ( OrderId INT, OrderDate Datetime, Quantity INT, CONSTRAINT [PK_OrderId] PRIMARY KEY CLUSTERED ( [OrderId] ASC) ON [PRIMARY];
This table contains 50 million rows from the last 10 years.I only need the last 5 years data.
I have a partition function like this:
CREATE PARTITION FUNCTION OrderPF (datetime)AS RANGE RIGHT FOR VALUES ('2014-01-01')
I have a partition scheme like this:
CREATE PARTITION SCHEME OrderPS AS PARTITION OrderPF ALL TO ([PRIMARY])
My question is how to proceed?I still want a primary key on the table.
Does the [OrderDate] column have to be a part of the clustered index? (Main question)
CREATE UNIQUE CLUSTERED INDEX IX_Order ON Order(OrderDate,OrderId) ON OrderPS(OrderDate) ;
If so, do I then have to create an extra non-clustered Primary Key purely on [OrderId]?
ALTER TABLE Order ADD CONSTRAINT PK_OrderId PRIMARY KEY NONCLUSTERED (Id) ON [PRIMARY];
Is this the correct approach?