sql server – SQL Azure table partitioning ,need help to understand how to apply to an existing table
While trying to optimize access to a table on an Azure SQL Db I found this link.
Now the major issues I’ve got are on this table which has around and it’ defined as
CREATE TABLE dbo.ProductInstance
(
Id int IDENTITY
CONSTRAINT PK_ProductInstance
PRIMARY KEY,
ProductInstanceSeriesId int NOT NULL
CONSTRAINT FK_ProductInstance_ProductInstanceSeries_ProductInstanceSeriesId
REFERENCES dbo.ProductInstanceSeries,
Title nvarchar(256),
Description nvarchar(1024),
StartDateTime datetime2 NOT NULL,
EndDateTime datetime2 NOT NULL,
Availability int NOT NULL,
InitialAvailability int NOT NULL,
GuideUserId int
CONSTRAINT FK_ProductInstance_User_GuideUserId
REFERENCES dbo.[User],
SignupUserId int
CONSTRAINT FK_ProductInstance_User_SignupUserId
REFERENCES dbo.[User],
GroupNumber int NOT NULL,
IsActive bit NOT NULL,
IsDeleted bit NOT NULL,
IsPrivate bit NOT NULL,
GuideNote nvarchar(max),
OfficeNote nvarchar(max),
CreatedByUserId int NOT NULL,
CreatedOnUtc datetime2 NOT NULL,
LastModifiedOnUtc datetime2,
DeletedOnUtc datetime2,
ProductId int,
MappedId int,
ActivityId int,
ActivityInstanceId varchar(50),
LastTimeChangedDateTime date,
TimeChangeConfirmed bit,
StartedAt datetime2,
ProductInventoryId int
CONSTRAINT FK_ProductInstance_ProductInventory_ProductInventoryId
REFERENCES dbo.ProductInventory
ON DELETE CASCADE
)
go
Most of the searches are done on StartAt / EndAt fields so I need to understand how to partition on those fields.
In the example, it reason on a Timestamp column while in my current implementation I don’t have one…should I add one or can I reason on a Datetime2 field?
Look at the code from the link I pasted
CREATE TABLE DemoPartitionTable
(
ID int,
[Timestamp] datetime PRIMARY KEY,
[Sampletext] varchar(100)
)
ON PS_Date ([Timestamp]);
GO
INSERT INTO DemoPartitionTable (id, [TimeStamp],[SampleText])
SELECT '1', '20191231','Year 2019' UNION ALL
SELECT '2', '20211231','Year 2021' UNION ALL
SELECT '1', '20210111','Year 2021' UNION ALL
SELECT '1', '20210630','Year 2021'
Read more here: Source link
