我正在研究表分区,我还有一些不清楚的地方。
我创建了一个分区函数来组织过去三个月的数据。
CREATE PARTITION FUNCTION PartitioningBy3meses (datetime)
AS RANGE LEFT FOR VALUES (getdate()-90, getdate()-1);
GO
方案:
CREATE PARTITION SCHEME PartitionByVejes
AS PARTITION PartitioningBy3meses
TO (datosmuyviejos, datosviejos, [PRIMARY]);
GO
我使用向导对现有表进行分区,这是它为我生成的代码:
BEGIN TRANSACTION
ALTER TABLE [dbo].[factura] DROP CONSTRAINT [PK__factura__3213E83F22FEA7FF] WITH ( ONLINE = OFF )
ALTER TABLE [dbo].[factura] ADD PRIMARY KEY NONCLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
CREATE CLUSTERED INDEX [ClusteredIndex_on_PartitionByVejes_637678578300644842] ON [dbo].[factura]
(
[fecha]
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PartitionByVejes]([fecha])
DROP INDEX [ClusteredIndex_on_PartitionByVejes_637678578300644842] ON [dbo].[factura]
COMMIT TRANSACTION
GO
疑点:
- 为了在分区之间传播数据,主索引是否变为非聚集索引?
- 为什么会创建 ClusteredIndex_on_PartitionByVejes_637678578300644842 索引然后删除?
- 随着时间的流逝,数据是否会在分区之间自行移动,还是我必须做一些事情才能使其移动?